-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathInitialize.lua
More file actions
207 lines (168 loc) · 5.4 KB
/
Initialize.lua
File metadata and controls
207 lines (168 loc) · 5.4 KB
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
207
local E, _, V, P, G = unpack(ElvUI) ---@type 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 tContains = tContains
local C_AddOns_GetAddOnMetadata = C_AddOns.GetAddOnMetadata
---@class WindTools : AceAddon, AceConsole-3.0, AceEvent-3.0, AceTimer-3.0, AceHook-3.0
local W = AceAddon:NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0", "AceHook-3.0")
V.WT = {} ---@class ProfileDB
P.WT = {} ---@class PrivateDB
G.WT = {} ---@class GlobalDB
addon[1] = W
addon[2] = {} ---@class Functions
addon[3] = E
addon[4] = L ---@alias LocaleTable table<string, string>
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 = {
---@class Misc : AceModule, AceHook-3.0, AceEvent-3.0
Misc = W:NewModule("Misc", "AceHook-3.0", "AceEvent-3.0"),
---@class Skins : AceModule, AceHook-3.0, AceEvent-3.0, AceTimer-3.0
Skins = W:NewModule("Skins", "AceHook-3.0", "AceEvent-3.0", "AceTimer-3.0"),
---@class Tooltips : AceModule, AceHook-3.0, AceEvent-3.0
Tooltips = W:NewModule("Tooltips", "AceHook-3.0", "AceEvent-3.0"),
---@class MoveFrames : AceModule, AceHook-3.0, AceEvent-3.0
MoveFrames = W:NewModule("MoveFrames", "AceEvent-3.0", "AceHook-3.0"),
}
W:NewModule("QuestProgress", "AceEvent-3.0")
-- Utilities namespace
W.Utilities = {}
-- Pre-register libs into ElvUI
E:AddLib("OpenRaid", "LibOpenRaid-1.0")
E:AddLib("ObjectiveProgressWT", "LibObjectiveProgress-WT")
E:AddLib("RangeCheck", "LibRangeCheck-3.0")
E:AddLib("Keystone", "LibKeystone")
E:AddLib("WTItemEnchant", "LibItemEnchant-WT")
_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 versions are used
EP:RegisterPlugin(addonName, W.OptionsCallback, false, xVersionString)
-- Fix the bug that locale files loaded after option table is created
local pluginTitle = L["Plugins"]
W:SecureHook(EP, "GetPluginOptions", function()
E.Options.args.plugins.name = pluginTitle
end)
self:SecureHook(E, "UpdateAll", "UpdateModules")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
end
function W:AutoCopyPrivateProfile()
if
not E.global.WT.core.autoCopyPrivateProfile.enable
or E.global.WT.core.autoCopyPrivateProfile.initializedCharacters[E.mynameRealm]
then
return
end
local copyFrom = E.global.WT.core.autoCopyPrivateProfile.copyFrom
if not copyFrom or E.charSettings:GetCurrentProfile() == copyFrom then
return
end
local profiles = E.charSettings:GetProfiles()
if tContains(profiles, copyFrom) then
E.charSettings:CopyProfile(copyFrom)
E.global.WT.core.autoCopyPrivateProfile.initializedCharacters[E.mynameRealm] = true
end
end
do
local checked = false
function W:PLAYER_ENTERING_WORLD(_, isInitialLogin, isReloadingUi)
if isInitialLogin then
self:AutoCopyPrivateProfile()
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:HookUIError()
self:GameFixing()
E:Delay(1, collectgarbage, "collect")
end
end
EP:HookInitialize(W, W.Initialize)