forked from fafaraway/andromeda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
206 lines (171 loc) · 5.24 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
--[[
____________ _____ _____ _ _ _____
| ___| ___ \ ___| ___| | | |_ _|
| |_ | |_/ / |__ | |__ | | | | | |
| _| | /| __|| __|| | | | | |
| | | |\ \| |___| |___| |_| |_| |_
\_| \_| \_\____/\____/ \___/ \___/
]]
do
_G.BINDING_HEADER_FREEUI = GetAddOnMetadata(..., 'Title')
_G.BINDING_NAME_FREEUI_TOGGLE_GUI = 'GUI'
end
local addOnName, engine = ...
local aceAddon, aceAddonMinor = _G.LibStub('AceAddon-3.0')
engine[1] = aceAddon:NewAddon(addOnName, 'AceConsole-3.0', 'AceEvent-3.0', 'AceTimer-3.0', 'AceHook-3.0')
engine[2] = {}
engine[3] = {}
_G.FREE_ADB = {} -- Account variables
_G.FREE_PDB = {}
_G.FREE_DB = {} -- Character variables
_G.FreeUI = engine -- Allow other addon access
local F, C = engine[1], engine[2]
local addonVersion = '@project-version@'
if (addonVersion:find('project%-version')) then
addonVersion = 'Development'
end
C.AddonVersion = addonVersion
C.IsDeveloper = C.AddonVersion == 'Development'
-- Libraries
do
F.Libs = {}
F.LibsMinor = {}
function F:AddLib(name, major, minor)
if not name then
return
end
-- in this case: `major` is the lib table and `minor` is the minor version
if type(major) == 'table' and type(minor) == 'number' then
F.Libs[name], F.LibsMinor[name] = major, minor
else -- in this case: `major` is the lib name and `minor` is the silent switch
F.Libs[name], F.LibsMinor[name] = _G.LibStub(major, minor)
end
end
F:AddLib('AceAddon', aceAddon, aceAddonMinor)
F:AddLib('ACL', 'AceLocale-3.0')
F:AddLib('LBG', 'LibButtonGlow-1.0')
F:AddLib('LRC', 'LibRangeCheck-2.0')
F:AddLib('LRI', 'LibRealmInfo')
F:AddLib('LSM', 'LibSharedMedia-3.0')
F:AddLib('LDD', 'LibDropDown')
F:AddLib('Base64', 'LibBase64-1.0')
F.Libs.oUF = engine.oUF
F.Libs.cargBags = engine.cargBags
end
--[[ function F:OnEnable()
F:Initialize()
end
function F:CallLoadedModule(obj, silent, object, index)
local name, func
if type(obj) == 'table' then name, func = unpack(obj) else name = obj end
local module = name and F:GetModule(name, silent)
if not module then return end
if func and type(func) == 'string' then
F:CallLoadFunc(module[func], module)
elseif func and type(func) == 'function' then
F:CallLoadFunc(func, module)
elseif module.Initialize then
F:CallLoadFunc(module.Initialize, module)
end
if object and index then object[index] = nil end
end
function F:RegisterInitialModule(name, func)
F.RegisteredInitialModules[#F.RegisteredInitialModules + 1] = (func and {name, func}) or name
end
function F:RegisterModule(name, func)
if F.initialized then
F:CallLoadedModule((func and {name, func}) or name)
else
F.RegisteredModules[#F.RegisteredModules + 1] = (func and {name, func}) or name
end
end
function F:InitializeInitialModules()
for index, object in ipairs(F.RegisteredInitialModules) do
F:CallLoadedModule(object, true, F.RegisteredInitialModules, index)
end
end
function F:InitializeModules()
for index, object in ipairs(F.RegisteredModules) do
F:CallLoadedModule(object, true, F.RegisteredModules, index)
end
end
function F:Initialize()
F:InitializeModules()
end ]]
-- Events
local events = {}
local host = CreateFrame('Frame')
host:SetScript(
'OnEvent',
function(_, event, ...)
for func in pairs(events[event]) do
if event == 'COMBAT_LOG_EVENT_UNFILTERED' then
func(event, CombatLogGetCurrentEventInfo())
else
func(event, ...)
end
end
end
)
function F:RegisterEvent(event, func, unit1, unit2)
if not events[event] then
events[event] = {}
if unit1 then
host:RegisterUnitEvent(event, unit1, unit2)
else
host:RegisterEvent(event)
end
end
events[event][func] = true
end
function F:UnregisterEvent(event, func)
local funcs = events[event]
if funcs and funcs[func] then
funcs[func] = nil
if not next(funcs) then
events[event] = nil
host:UnregisterEvent(event)
end
end
end
-- Modules
local modules, initQueue = {}, {}
function F:RegisterModule(name)
if modules[name] then
F:Print('Module <' .. name .. '> has been registered.')
return
end
local module = {}
module.name = name
modules[name] = module
table.insert(initQueue, module)
return module
end
function F:GetModule(name)
if not modules[name] then
F:Print('Module <' .. name .. '> does not exist.')
return
end
return modules[name]
end
F:RegisterEvent(
'PLAYER_LOGIN',
function()
if C.DB.InstallationComplete then
F:SetupUIScale()
F:RegisterEvent('UI_SCALE_CHANGED', F.UpdatePixelScale)
_G.Display_UseUIScale:Kill()
_G.Display_UIScaleSlider:Kill()
else
F:SetupUIScale(true)
end
for _, module in next, initQueue do
if module.OnLogin then
module:OnLogin()
else
F:Print('Module <' .. module.name .. '> does not loaded.')
end
end
F:Print(C.AddonVersion)
end
)