-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPreload.lua
More file actions
177 lines (137 loc) · 5.06 KB
/
Preload.lua
File metadata and controls
177 lines (137 loc) · 5.06 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
local env = select(2, ...)
local Sound = env.modules:Import("packages\\sound")
local CallbackRegistry = env.modules:Import("packages\\callback-registry")
local UIFont = env.modules:Import("packages\\ui-font")
local SavedVariables = env.modules:Import("packages\\saved-variables")
local SlashCommand = env.modules:Import("packages\\slash-command")
local Path = env.modules:Import("packages\\path")
env.NAME = "Manifold"
env.ICON = Path.Root .. "\\Art\\Icons\\Logo"
env.ICON_ALT = Path.Root .. "\\Art\\Icons\\Logo-White"
env.VERSION_STRING = "0.1.1"
env.VERSION_NUMBER = 000101
env.DEBUG_MODE = false
local L = {}; env.L = L
local Enum = {}; env.Enum = Enum
do
end
local Config = {}; env.Config = Config
do
Config.DBGlobal = nil
Config.DBGlobalPersistent = nil
Config.DBLocal = nil
Config.DBLocalPersistent = nil
local NAME_GLOBAL = "ManifoldDB_Global"
local NAME_GLOBAL_PERSISTENT = "ManifoldDB_Global_Persistent"
local NAME_LOCAL = "ManifoldDB_Local"
local NAME_LOCAL_PERSISTENT = "ManifoldDB_Local_Persistent"
---@format disable
local DB_GLOBAL_DEFAULTS = {
lastLoadedVersion = nil,
fontPath = nil,
-- Housing
DecorMerchant = true,
HouseChest = true,
PlacedDecorList = true,
DecorTooltip = false,
-- Tooltip
QuestDetailTooltip = true,
ExperienceBarTooltip = true,
-- Loot
LootAlertPopup = true,
-- Achievements
AchievementLink = true,
-- Transmog
DressingRoom = true,
}
local DB_GLOBAL_PERSISTENT_DEFAULTS = {}
local DB_LOCAL_DEFAULTS = {
--ExperienceBarTooltip
ExperienceBar_Level_StartTime = nil,
ExperienceBar_Session_StartTime = nil,
ExperienceBar_Session_GainedXP = nil,
ExperienceBar_Session_LastXP = nil,
}
local DB_LOCAL_PERSISTENT_DEFAULTS = {}
---@format enable
local DB_GLOBAL_MIGRATION = {}
function Config.LoadDB()
if ManifoldDB_Global and ManifoldDB_Global.lastLoadedVersion == env.VERSION_NUMBER then
-- Same version, skip migration
SavedVariables.RegisterDatabase(NAME_GLOBAL).defaults(DB_GLOBAL_DEFAULTS)
SavedVariables.RegisterDatabase(NAME_GLOBAL_PERSISTENT).defaults(DB_GLOBAL_PERSISTENT_DEFAULTS)
else
-- Migrate if new version
SavedVariables.RegisterDatabase(NAME_GLOBAL).defaults(DB_GLOBAL_DEFAULTS).migrationPlan(DB_GLOBAL_MIGRATION)
SavedVariables.RegisterDatabase(NAME_GLOBAL_PERSISTENT).defaults(DB_GLOBAL_PERSISTENT_DEFAULTS)
end
SavedVariables.RegisterDatabase(NAME_LOCAL).defaults(DB_LOCAL_DEFAULTS)
SavedVariables.RegisterDatabase(NAME_LOCAL_PERSISTENT).defaults(DB_LOCAL_PERSISTENT_DEFAULTS)
Config.DBGlobal = SavedVariables.GetDatabase(NAME_GLOBAL)
Config.DBGlobalPersistent = SavedVariables.GetDatabase(NAME_GLOBAL_PERSISTENT)
Config.DBLocal = SavedVariables.GetDatabase(NAME_LOCAL)
Config.DBLocalPersistent = SavedVariables.GetDatabase(NAME_LOCAL_PERSISTENT)
CallbackRegistry.Trigger("Preload.DatabaseReady")
end
end
local SlashCmdRegister = {}
do
local Handlers = {}
do -- /manifold
function Handlers.HandleSlashCmd_Manifold(_, tokens)
ManifoldAPI_ToggleSettingsUI()
end
end
local Schema = {
-- /manifold
{
name = "MANIFOLD",
hook = nil,
command = { "manifold" },
callback = Handlers.HandleSlashCmd_Manifold
}
}
function SlashCmdRegister.LoadSchema()
SlashCommand.AddFromSchema(Schema)
end
end
local SoundHandler = {}
do
local function UpdateMainSoundLayer()
local Settings_AudioGlobal = Config.DBGlobal:GetVariable("AudioGlobal")
if Settings_AudioGlobal == true then
Sound.SetEnabled("Main", true)
elseif Settings_AudioGlobal == false then
Sound.SetEnabled("Main", false)
end
end
SavedVariables.OnChange("ManifoldDB_Global", "AudioGlobal", UpdateMainSoundLayer)
function SoundHandler.Load()
UpdateMainSoundLayer()
end
end
local FontHandler = {}
do
local function UpdateFonts()
UIFont.CustomFont:RefreshFontList()
local fontPath = Config.DBGlobal:GetVariable("fontPath")
if fontPath == nil or not UIFont.CustomFont.FontExists(fontPath) then
fontPath = UIFont.CustomFont.GetFontPathForIndex(1)
end
UIFont.SetNormalFont(fontPath)
Config.DBGlobal:SetVariable("fontPath", fontPath)
end
SavedVariables.OnChange("ManifoldDB_Global", "fontPath", UpdateFonts)
function FontHandler.Load()
UpdateFonts()
end
end
local function LoadAddon()
Config.LoadDB()
SlashCmdRegister.LoadSchema()
SoundHandler.Load()
Config.DBGlobal:SetVariable("lastLoadedVersion", env.VERSION_NUMBER)
CallbackRegistry.Trigger("Preload.AddonReady")
end
CallbackRegistry.Add("WoWClient.OnAddonLoaded", LoadAddon)
CallbackRegistry.Add("WoWClient.OnPlayerLogin", FontHandler.Load)