-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Initialize.lua
166 lines (133 loc) · 4.04 KB
/
Initialize.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
local E, _, V, P, G = unpack(ElvUI)
local addonName, addon = ...
local EP = E.Libs.EP
local AceAddon = E.Libs.AceAddon
local L = E.Libs.ACL:GetLocale("ElvUI", E.global.general.locale)
local _G = _G
local collectgarbage = collectgarbage
local format = format
local hooksecurefunc = hooksecurefunc
local next = next
local print = print
local strfind = strfind
local strmatch = strmatch
local C_AddOns_GetAddOnMetadata = C_AddOns.GetAddOnMetadata
local W = AceAddon:NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0", "AceHook-3.0")
V.WT = {} -- profile database defaults
P.WT = {} -- private database defaults
G.WT = {} -- global database defaults
addon[1] = W
addon[2] = {} -- Functions
addon[3] = E
addon[4] = L
addon[5] = V.WT
addon[6] = P.WT
addon[7] = G.WT
_G["WindTools"] = addon
local versionString = C_AddOns_GetAddOnMetadata(addonName, "Version")
local xVersionString = C_AddOns_GetAddOnMetadata(addonName, "X-Version")
local function getVersion()
local version, variant, subversion
-- Git
if strfind(versionString, "project%-version") then
return xVersionString, "git", nil
end
version, variant = strmatch(versionString, "^(%d+%.%d+)(.*)$")
if not version then
return xVersionString, nil, nil
end
if not variant or variant == "" then
return version, nil, nil
end
local variantName, subversionNum = strmatch(variant, "^%-([%w]+)%-?(%d*)$")
if variantName and subversionNum then
variant = variantName
subversion = subversionNum ~= "" and subversionNum or nil
end
return version, variant, subversion
end
W.Version, W.Variant, W.SubVersion = getVersion()
W.DisplayVersion = W.Version
if W.Variant then
W.DisplayVersion = format("%s-%s", W.DisplayVersion, W.Variant)
if W.SubVersion then
W.DisplayVersion = format("%s-%s", W.DisplayVersion, W.SubVersion)
end
end
-- Pre-register some WindTools modules
W.Modules = {}
W.Modules.Misc = W:NewModule("Misc", "AceHook-3.0", "AceEvent-3.0")
W.Modules.Skins = W:NewModule("Skins", "AceHook-3.0", "AceEvent-3.0", "AceTimer-3.0")
W.Modules.Tooltips = W:NewModule("Tooltips", "AceHook-3.0", "AceEvent-3.0")
W.Modules.MoveFrames = W:NewModule("MoveFrames", "AceEvent-3.0", "AceHook-3.0")
-- Utilities namespace
W.Utilities = {}
-- Pre-register libs into ElvUI
E:AddLib("OpenRaid", "LibOpenRaid-1.0")
E:AddLib("LOP", "LibObjectiveProgress-1.0")
_G.WindTools_OnAddonCompartmentClick = function()
E:ToggleOptions("WindTools")
end
function W:Initialize()
-- ElvUI -> WindTools -> WindTools Modules
if not self:CheckElvUIVersion() then
return
end
for _, module in self:IterateModules() do
addon[2].Developer.InjectLogger(module)
end
hooksecurefunc(W, "NewModule", function(_, name)
addon[2].Developer.InjectLogger(name)
end)
self.initialized = true
self:AddCustomLinkSupport()
self:UpdateScripts()
self:InitializeModules()
-- To avoid the update tips from ElvUI when alpha/beta version is used
EP:RegisterPlugin(addonName, W.OptionsCallback, false, xVersionString)
self:SecureHook(E, "UpdateAll", "UpdateModules")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
end
do
local checked = false
function W:PLAYER_ENTERING_WORLD(_, isInitialLogin, isReloadingUi)
if isInitialLogin then
E:Delay(6, self.ChangelogReadAlert, self)
if E.global.WT.core.loginMessage then
local icon = addon[2].GetIconString(self.Media.Textures.smallLogo, 14)
print(
format(
icon
.. " "
.. L["%s %s Loaded."]
.. " "
.. L["You can send your suggestions or bugs via %s, %s, %s and the thread in %s."],
self.Title,
self.Version,
L["QQ Group"],
L["Discord"],
L["GitHub"],
L["NGA.cn"]
)
)
end
end
if not (checked or _G.ElvUIInstallFrame) then
self:CheckCompatibility()
checked = true
end
if _G.ElvDB then
if isInitialLogin or not _G.ElvDB.WT then
_G.ElvDB.WT = {
DisabledAddOns = {},
}
end
if next(_G.ElvDB.WT.DisabledAddOns) then
E:Delay(4, self.PrintDebugEnviromentTip)
end
end
self:GameFixing()
E:Delay(1, collectgarbage, "collect")
end
end
EP:HookInitialize(W, W.Initialize)