Glass 1.4.0 init.lua Core:OnInitialize()
0 removals
89 lines
1 addition
90 lines
local _G = _G
local _G = _G
local AceAddon = _G.LibStub("AceAddon-3.0")
local AceAddon = _G.LibStub("AceAddon-3.0")
local AddonName, AddonVars = ...
local AddonName, AddonVars = ...
local Core = AceAddon:NewAddon(AddonName)
local Core = AceAddon:NewAddon(AddonName)
local Constants = {}
local Constants = {}
local Utils = {}
local Utils = {}
AddonVars[1] = Core
AddonVars[1] = Core
AddonVars[2] = Constants
AddonVars[2] = Constants
AddonVars[3] = Utils
AddonVars[3] = Utils
_G[AddonName] = Core
_G[AddonName] = Core
-- Core
-- Core
Core.Libs = {
Core.Libs = {
AceConfig = _G.LibStub("AceConfig-3.0"),
AceConfig = _G.LibStub("AceConfig-3.0"),
AceConfigDialog = _G.LibStub("AceConfigDialog-3.0"),
AceConfigDialog = _G.LibStub("AceConfigDialog-3.0"),
AceDBOptions = _G.LibStub("AceDBOptions-3.0"),
AceDBOptions = _G.LibStub("AceDBOptions-3.0"),
AceDB = _G.LibStub("AceDB-3.0"),
AceDB = _G.LibStub("AceDB-3.0"),
AceHook = _G.LibStub("AceHook-3.0"),
AceHook = _G.LibStub("AceHook-3.0"),
LibEasing = _G.LibStub("LibEasing-1.0"),
LibEasing = _G.LibStub("LibEasing-1.0"),
LSM = _G.LibStub("LibSharedMedia-3.0"),
LSM = _G.LibStub("LibSharedMedia-3.0"),
lodash = _G.LibStub("lodash.wow")
lodash = _G.LibStub("lodash.wow")
}
}
Core.Components = {}
Core.Components = {}
-- Modules
-- Modules
Core:NewModule("Config", "AceConsole-3.0")
Core:NewModule("Config", "AceConsole-3.0")
Core:NewModule("Fonts")
Core:NewModule("Fonts")
Core:NewModule("Hyperlinks")
Core:NewModule("Hyperlinks")
Core:NewModule("TextProcessing")
Core:NewModule("TextProcessing")
Core:NewModule("UIManager", "AceHook-3.0")
Core:NewModule("UIManager", "AceHook-3.0")
function Core:OnInitialize()
function Core:OnInitialize()
local defaults = {
local defaults = {
profile = {
profile = {
frameWidth = 450,
frameWidth = 450,
frameHeight = 230,
frameHeight = 230,
positionAnchor = Constants.DEFAULT_ANCHOR_POINT,
positionAnchor = Constants.DEFAULT_ANCHOR_POINT,
font = "Friz Quadrata TT",
font = "Friz Quadrata TT",
messageFontSize = 12,
messageFontSize = 12,
editBoxFontSize = 12,
editBoxFontSize = 12,
iconTextureYOffset = 4,
iconTextureYOffset = 4,
mouseOverTooltips = true,
mouseOverTooltips = true,
chatHoldTime = 10,
chatHoldTime = 10,
chatBackgroundOpacity = 0.4,
chatBackgroundOpacity = 0.4,
chatShowOnMouseOver = true
chatShowOnMouseOver = true
}
}
}
}
self.listeners = {}
self.listeners = {}
self.db = self.Libs.AceDB:New("GlassDB", defaults, true)
self.db = self.Libs.AceDB:New("GlassDB", defaults, true)
self.printBuffer = {}
self.printBuffer = {}
return self.db.profile
end
end
function Core:OnEnable()
function Core:OnEnable()
-- Buffer print messages until ViragDevTool loads
-- Buffer print messages until ViragDevTool loads
for _, item in ipairs(self.printBuffer) do
for _, item in ipairs(self.printBuffer) do
Utils.print(unpack(item))
Utils.print(unpack(item))
end
end
self.printBuffer = {}
self.printBuffer = {}
end
end
function Core:Subscribe(messageType, listener)
function Core:Subscribe(messageType, listener)
if self.listeners[messageType] == nil then
if self.listeners[messageType] == nil then
self.listeners[messageType] = {}
self.listeners[messageType] = {}
end
end
local listeners = self.listeners[messageType]
local listeners = self.listeners[messageType]
local index = #listeners + 1
local index = #listeners + 1
listeners[index] = listener
listeners[index] = listener
return function ()
return function ()
self.Libs.lodash.remove(listeners, function (val) return val == listener end)
self.Libs.lodash.remove(listeners, function (val) return val == listener end)
end
end
end
end
function Core:Dispatch(messageType, payload)
function Core:Dispatch(messageType, payload)
--[===[@debug@--
--[===[@debug@--
Utils.print('E: '..messageType, payload)
Utils.print('E: '..messageType, payload)
--@end-debug@]===]--
--@end-debug@]===]--
local listeners = self.listeners[messageType] or {}
local listeners = self.listeners[messageType] or {}
for _, listener in ipairs(listeners) do
for _, listener in ipairs(listeners) do
listener(payload)
listener(payload)
end
end
end
end