flickerstreak@1
|
1 --[[
|
flickerstreak@1
|
2 Name: AceDB-2.0
|
flickerstreak@1
|
3 Revision: $Rev: 18708 $
|
flickerstreak@1
|
4 Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
|
flickerstreak@1
|
5 Inspired By: Ace 1.x by Turan (turan@gryphon.com)
|
flickerstreak@1
|
6 Website: http://www.wowace.com/
|
flickerstreak@1
|
7 Documentation: http://www.wowace.com/index.php/AceDB-2.0
|
flickerstreak@1
|
8 SVN: http://svn.wowace.com/root/trunk/Ace2/AceDB-2.0
|
flickerstreak@1
|
9 Description: Mixin to allow for fast, clean, and featureful saved variable
|
flickerstreak@1
|
10 access.
|
flickerstreak@1
|
11 Dependencies: AceLibrary, AceOO-2.0, AceEvent-2.0
|
flickerstreak@1
|
12 ]]
|
flickerstreak@1
|
13
|
flickerstreak@1
|
14 local MAJOR_VERSION = "AceDB-2.0"
|
flickerstreak@1
|
15 local MINOR_VERSION = "$Revision: 18708 $"
|
flickerstreak@1
|
16
|
flickerstreak@1
|
17 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
|
flickerstreak@1
|
18 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
|
flickerstreak@1
|
19
|
flickerstreak@1
|
20 if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end
|
flickerstreak@1
|
21
|
flickerstreak@1
|
22 local function safecall(func,...)
|
flickerstreak@1
|
23 local success, err = pcall(func,...)
|
flickerstreak@1
|
24 if not success then geterrorhandler()(err) end
|
flickerstreak@1
|
25 end
|
flickerstreak@1
|
26
|
flickerstreak@1
|
27 local ACTIVE, ENABLED, STATE, TOGGLE_ACTIVE, MAP_ACTIVESUSPENDED, SET_PROFILE, SET_PROFILE_USAGE, PROFILE, PLAYER_OF_REALM, CHOOSE_PROFILE_DESC, CHOOSE_PROFILE_GUI, COPY_PROFILE_DESC, COPY_PROFILE_GUI, OTHER_PROFILE_DESC, OTHER_PROFILE_GUI, OTHER_PROFILE_USAGE, CHARACTER_COLON, REALM_COLON, CLASS_COLON, DEFAULT, ALTERNATIVE
|
flickerstreak@1
|
28
|
flickerstreak@1
|
29 if GetLocale() == "deDE" then
|
flickerstreak@1
|
30 ACTIVE = "Aktiv"
|
flickerstreak@1
|
31 ENABLED = "Aktiviert"
|
flickerstreak@1
|
32 STATE = "Status"
|
flickerstreak@1
|
33 TOGGLE_ACTIVE = "Stoppt/Aktiviert dieses Addon."
|
flickerstreak@1
|
34 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Aktiv|r", [false] = "|cffff0000Gestoppt|r" }
|
flickerstreak@1
|
35 SET_PROFILE = "Setzt das Profil f\195\188r dieses Addon."
|
flickerstreak@1
|
36 SET_PROFILE_USAGE = "{Charakter || Klasse || Realm || <Profilname>}"
|
flickerstreak@1
|
37 PROFILE = "Profil"
|
flickerstreak@1
|
38 PLAYER_OF_REALM = "%s von %s"
|
flickerstreak@1
|
39 CHOOSE_PROFILE_DESC = "W\195\164hle ein Profil."
|
flickerstreak@1
|
40 CHOOSE_PROFILE_GUI = "W\195\164hle"
|
flickerstreak@1
|
41 COPY_PROFILE_DESC = "Kopiert Einstellungen von einem anderem Profil."
|
flickerstreak@1
|
42 COPY_PROFILE_GUI = "Kopiere von"
|
flickerstreak@1
|
43 OTHER_PROFILE_DESC = "W\195\164hle ein anderes Profil."
|
flickerstreak@1
|
44 OTHER_PROFILE_GUI = "Anderes"
|
flickerstreak@1
|
45 OTHER_PROFILE_USAGE = "<Profilname>"
|
flickerstreak@1
|
46
|
flickerstreak@1
|
47 CHARACTER_COLON = "Charakter: "
|
flickerstreak@1
|
48 REALM_COLON = "Realm: "
|
flickerstreak@1
|
49 CLASS_COLON = "Klasse: "
|
flickerstreak@1
|
50
|
flickerstreak@1
|
51 DEFAULT = "Default" -- fix
|
flickerstreak@1
|
52 ALTERNATIVE = "Alternative" -- fix
|
flickerstreak@1
|
53 elseif GetLocale() == "frFR" then
|
flickerstreak@1
|
54 ACTIVE = "Actif"
|
flickerstreak@1
|
55 ENABLED = "Activ\195\169"
|
flickerstreak@1
|
56 STATE = "Etat"
|
flickerstreak@1
|
57 TOGGLE_ACTIVE = "Suspend/active cet addon."
|
flickerstreak@1
|
58 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Actif|r", [false] = "|cffff0000Suspendu|r" }
|
flickerstreak@1
|
59 SET_PROFILE = "S\195\169lectionne le profil pour cet addon."
|
flickerstreak@1
|
60 SET_PROFILE_USAGE = "{perso || classe || royaume || <nom de profil>}"
|
flickerstreak@1
|
61 PROFILE = "Profil"
|
flickerstreak@1
|
62 PLAYER_OF_REALM = "%s de %s"
|
flickerstreak@1
|
63 CHOOSE_PROFILE_DESC = "Choisissez un profil."
|
flickerstreak@1
|
64 CHOOSE_PROFILE_GUI = "Choix"
|
flickerstreak@1
|
65 COPY_PROFILE_DESC = "Copier les param\195\168tres d'un autre profil."
|
flickerstreak@1
|
66 COPY_PROFILE_GUI = "Copier \195\160 partir de"
|
flickerstreak@1
|
67 OTHER_PROFILE_DESC = "Choisissez un autre profil."
|
flickerstreak@1
|
68 OTHER_PROFILE_GUI = "Autre"
|
flickerstreak@1
|
69 OTHER_PROFILE_USAGE = "<nom de profil>"
|
flickerstreak@1
|
70
|
flickerstreak@1
|
71 CHARACTER_COLON = "Personnage: "
|
flickerstreak@1
|
72 REALM_COLON = "Royaume: "
|
flickerstreak@1
|
73 CLASS_COLON = "Classe: "
|
flickerstreak@1
|
74
|
flickerstreak@1
|
75 DEFAULT = "Default" -- fix
|
flickerstreak@1
|
76 ALTERNATIVE = "Alternative" -- fix
|
flickerstreak@1
|
77 elseif GetLocale() == "koKR" then
|
flickerstreak@1
|
78 ACTIVE = "활성화"
|
flickerstreak@1
|
79 ENABLED = "활성화"
|
flickerstreak@1
|
80 STATE = "상태"
|
flickerstreak@1
|
81 TOGGLE_ACTIVE = "이 애드온 중지/계속 실행"
|
flickerstreak@1
|
82 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00활성화|r", [false] = "|cffff0000중지됨|r" }
|
flickerstreak@1
|
83 SET_PROFILE = "이 애드온에 프로필 설정"
|
flickerstreak@1
|
84 SET_PROFILE_USAGE = "{캐릭터명 || 직업 || 서버명 || <프로필명>}"
|
flickerstreak@1
|
85 PROFILE = "프로필"
|
flickerstreak@1
|
86 PLAYER_OF_REALM = "%s (%s 서버)"
|
flickerstreak@1
|
87 CHOOSE_PROFILE_DESC = "프로파일을 선택합니다."
|
flickerstreak@1
|
88 CHOOSE_PROFILE_GUI = "선택"
|
flickerstreak@1
|
89 COPY_PROFILE_DESC = "다른 프로파일에서 설정을 복사합니다."
|
flickerstreak@1
|
90 COPY_PROFILE_GUI = "복사"
|
flickerstreak@1
|
91 OTHER_PROFILE_DESC = "다른 프로파일을 선택합니다."
|
flickerstreak@1
|
92 OTHER_PROFILE_GUI = "기타"
|
flickerstreak@1
|
93 OTHER_PROFILE_USAGE = "<프로파일명>"
|
flickerstreak@1
|
94
|
flickerstreak@1
|
95 CHARACTER_COLON = "캐릭터: "
|
flickerstreak@1
|
96 REALM_COLON = "서버: "
|
flickerstreak@1
|
97 CLASS_COLON = "직업: "
|
flickerstreak@1
|
98
|
flickerstreak@1
|
99 DEFAULT = "Default" -- fix
|
flickerstreak@1
|
100 ALTERNATIVE = "Alternative" -- fix
|
flickerstreak@1
|
101 elseif GetLocale() == "zhTW" then
|
flickerstreak@1
|
102 ACTIVE = "啟動"
|
flickerstreak@1
|
103 ENABLED = "啟用"
|
flickerstreak@1
|
104 STATE = "狀態"
|
flickerstreak@1
|
105 TOGGLE_ACTIVE = "暫停/重啟這個插件。"
|
flickerstreak@1
|
106 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00啟動|r", [false] = "|cffff0000已暫停|r" }
|
flickerstreak@1
|
107 SET_PROFILE = "設定這插件的記錄檔。"
|
flickerstreak@1
|
108 SET_PROFILE_USAGE = "{角色 || 聯業 || 伺服器 || <記錄檔名稱>}"
|
flickerstreak@1
|
109 PROFILE = "記錄檔"
|
flickerstreak@1
|
110 PLAYER_OF_REALM = "%s 於 %s"
|
flickerstreak@1
|
111 CHOOSE_PROFILE_DESC = "選擇一個記錄檔"
|
flickerstreak@1
|
112 CHOOSE_PROFILE_GUI = "選擇"
|
flickerstreak@1
|
113 COPY_PROFILE_DESC = "由其他記錄檔複製設定。"
|
flickerstreak@1
|
114 COPY_PROFILE_GUI = "複製由"
|
flickerstreak@1
|
115 OTHER_PROFILE_DESC = "選擇其他記錄檔。"
|
flickerstreak@1
|
116 OTHER_PROFILE_GUI = "其他"
|
flickerstreak@1
|
117 OTHER_PROFILE_USAGE = "<記錄檔名稱>"
|
flickerstreak@1
|
118
|
flickerstreak@1
|
119 CHARACTER_COLON = "角色:"
|
flickerstreak@1
|
120 REALM_COLON = "伺服器:"
|
flickerstreak@1
|
121 CLASS_COLON = "聯業:"
|
flickerstreak@1
|
122
|
flickerstreak@1
|
123 DEFAULT = "Default" -- fix
|
flickerstreak@1
|
124 ALTERNATIVE = "Alternative" -- fix
|
flickerstreak@1
|
125 elseif GetLocale() == "zhCN" then
|
flickerstreak@1
|
126 ACTIVE = "\230\156\137\230\149\136"
|
flickerstreak@1
|
127 ENABLED = "\229\144\175\231\148\168"
|
flickerstreak@1
|
128 STATE = "\231\138\182\230\128\129"
|
flickerstreak@1
|
129 TOGGLE_ACTIVE = "\230\154\130\229\129\156/\230\129\162\229\164\141 \230\173\164\230\143\146\228\187\182."
|
flickerstreak@1
|
130 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00\230\156\137\230\149\136|r", [false] = "|cffff0000\230\154\130\229\129\156|r" }
|
flickerstreak@1
|
131 SET_PROFILE = "\232\174\190\231\189\174\233\133\141\231\189\174\230\150\135\228\187\182\228\184\186\232\191\153\230\143\146\228\187\182."
|
flickerstreak@1
|
132 SET_PROFILE_USAGE = "{\229\173\151\231\172\166 || \233\128\137\228\187\182\231\177\187 || \229\159\159 || <\233\133\141\231\189\174\230\150\135\228\187\182\229\144\141\229\173\151>}"
|
flickerstreak@1
|
133 PROFILE = "\233\133\141\231\189\174\230\150\135\228\187\182"
|
flickerstreak@1
|
134 PLAYER_OF_REALM = "%s \231\154\132 %s"
|
flickerstreak@1
|
135 CHOOSE_PROFILE_DESC = "\233\128\137\230\139\169\233\133\141\231\189\174\230\150\135\228\187\182."
|
flickerstreak@1
|
136 CHOOSE_PROFILE_GUI = "\233\128\137\230\139\169"
|
flickerstreak@1
|
137 COPY_PROFILE_DESC = "\229\164\141\229\136\182\232\174\190\231\189\174\228\187\142\229\143\166\228\184\128\228\184\170\233\133\141\231\189\174\230\150\135\228\187\182."
|
flickerstreak@1
|
138 COPY_PROFILE_GUI = "\229\164\141\229\136\182\228\187\142"
|
flickerstreak@1
|
139 OTHER_PROFILE_DESC = "\233\128\137\230\139\169\229\143\166\228\184\128\228\184\170\233\133\141\231\189\174\230\150\135\228\187\182."
|
flickerstreak@1
|
140 OTHER_PROFILE_GUI = "\229\133\182\228\187\150"
|
flickerstreak@1
|
141 OTHER_PROFILE_USAGE = "<\233\133\141\231\189\174\230\150\135\228\187\182\229\144\141\229\173\151>"
|
flickerstreak@1
|
142
|
flickerstreak@1
|
143 CHARACTER_COLON = "\229\173\151\231\172\166: "
|
flickerstreak@1
|
144 REALM_COLON = "\229\159\159: "
|
flickerstreak@1
|
145 CLASS_COLON = "\233\128\137\228\187\182\231\177\187: "
|
flickerstreak@1
|
146
|
flickerstreak@1
|
147 DEFAULT = "Default" -- fix
|
flickerstreak@1
|
148 ALTERNATIVE = "Alternative" -- fix
|
flickerstreak@1
|
149 else -- enUS
|
flickerstreak@1
|
150 ACTIVE = "Active"
|
flickerstreak@1
|
151 ENABLED = "Enabled"
|
flickerstreak@1
|
152 STATE = "State"
|
flickerstreak@1
|
153 TOGGLE_ACTIVE = "Suspend/resume this addon."
|
flickerstreak@1
|
154 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Active|r", [false] = "|cffff0000Suspended|r" }
|
flickerstreak@1
|
155 SET_PROFILE = "Set profile for this addon."
|
flickerstreak@1
|
156 SET_PROFILE_USAGE = "{char || class || realm || <profile name>}"
|
flickerstreak@1
|
157 PROFILE = "Profile"
|
flickerstreak@1
|
158 PLAYER_OF_REALM = "%s of %s"
|
flickerstreak@1
|
159 CHOOSE_PROFILE_DESC = "Choose a profile."
|
flickerstreak@1
|
160 CHOOSE_PROFILE_GUI = "Choose"
|
flickerstreak@1
|
161 COPY_PROFILE_DESC = "Copy settings from another profile."
|
flickerstreak@1
|
162 COPY_PROFILE_GUI = "Copy from"
|
flickerstreak@1
|
163 OTHER_PROFILE_DESC = "Choose another profile."
|
flickerstreak@1
|
164 OTHER_PROFILE_GUI = "Other"
|
flickerstreak@1
|
165 OTHER_PROFILE_USAGE = "<profile name>"
|
flickerstreak@1
|
166
|
flickerstreak@1
|
167 CHARACTER_COLON = "Character: "
|
flickerstreak@1
|
168 REALM_COLON = "Realm: "
|
flickerstreak@1
|
169 CLASS_COLON = "Class: "
|
flickerstreak@1
|
170
|
flickerstreak@1
|
171 DEFAULT = "Default"
|
flickerstreak@1
|
172 ALTERNATIVE = "Alternative"
|
flickerstreak@1
|
173 end
|
flickerstreak@1
|
174
|
flickerstreak@1
|
175 local AceOO = AceLibrary("AceOO-2.0")
|
flickerstreak@1
|
176 local AceEvent
|
flickerstreak@1
|
177 local Mixin = AceOO.Mixin
|
flickerstreak@1
|
178 local AceDB = Mixin {
|
flickerstreak@1
|
179 "RegisterDB",
|
flickerstreak@1
|
180 "RegisterDefaults",
|
flickerstreak@1
|
181 "ResetDB",
|
flickerstreak@1
|
182 "SetProfile",
|
flickerstreak@1
|
183 "GetProfile",
|
flickerstreak@1
|
184 "CopyProfileFrom",
|
flickerstreak@1
|
185 "ToggleActive",
|
flickerstreak@1
|
186 "IsActive",
|
flickerstreak@1
|
187 "AcquireDBNamespace",
|
flickerstreak@1
|
188 }
|
flickerstreak@1
|
189 local Dewdrop = AceLibrary:HasInstance("Dewdrop-2.0") and AceLibrary("Dewdrop-2.0")
|
flickerstreak@1
|
190
|
flickerstreak@1
|
191 local _G = getfenv(0)
|
flickerstreak@1
|
192
|
flickerstreak@1
|
193 local function inheritDefaults(t, defaults)
|
flickerstreak@1
|
194 if not defaults then
|
flickerstreak@1
|
195 return t
|
flickerstreak@1
|
196 end
|
flickerstreak@1
|
197 for k,v in pairs(defaults) do
|
flickerstreak@1
|
198 if k == "*" then
|
flickerstreak@1
|
199 local v = v
|
flickerstreak@1
|
200 if type(v) == "table" then
|
flickerstreak@1
|
201 setmetatable(t, {
|
flickerstreak@1
|
202 __index = function(self, key)
|
flickerstreak@1
|
203 if key == nil then
|
flickerstreak@1
|
204 return nil
|
flickerstreak@1
|
205 end
|
flickerstreak@1
|
206 self[key] = {}
|
flickerstreak@1
|
207 inheritDefaults(self[key], v)
|
flickerstreak@1
|
208 return self[key]
|
flickerstreak@1
|
209 end
|
flickerstreak@1
|
210 } )
|
flickerstreak@1
|
211 else
|
flickerstreak@1
|
212 setmetatable(t, {
|
flickerstreak@1
|
213 __index = function(self, key)
|
flickerstreak@1
|
214 if key == nil then
|
flickerstreak@1
|
215 return nil
|
flickerstreak@1
|
216 end
|
flickerstreak@1
|
217 self[key] = v
|
flickerstreak@1
|
218 return self[key]
|
flickerstreak@1
|
219 end
|
flickerstreak@1
|
220 } )
|
flickerstreak@1
|
221 end
|
flickerstreak@1
|
222 for key in pairs(t) do
|
flickerstreak@1
|
223 if (defaults[key] == nil or key == "*") and type(t[key]) == "table" then
|
flickerstreak@1
|
224 inheritDefaults(t[key], v)
|
flickerstreak@1
|
225 end
|
flickerstreak@1
|
226 end
|
flickerstreak@1
|
227 else
|
flickerstreak@1
|
228 if type(v) == "table" then
|
flickerstreak@1
|
229 if type(t[k]) ~= "table" then
|
flickerstreak@1
|
230 t[k] = {}
|
flickerstreak@1
|
231 end
|
flickerstreak@1
|
232 inheritDefaults(t[k], v)
|
flickerstreak@1
|
233 elseif t[k] == nil then
|
flickerstreak@1
|
234 t[k] = v
|
flickerstreak@1
|
235 end
|
flickerstreak@1
|
236 end
|
flickerstreak@1
|
237 end
|
flickerstreak@1
|
238 return t
|
flickerstreak@1
|
239 end
|
flickerstreak@1
|
240
|
flickerstreak@1
|
241 local _,race = UnitRace("player")
|
flickerstreak@1
|
242 local faction
|
flickerstreak@1
|
243 if race == "Orc" or race == "Scourge" or race == "Troll" or race == "Tauren" or race == "BloodElf" then
|
flickerstreak@1
|
244 faction = FACTION_HORDE
|
flickerstreak@1
|
245 else
|
flickerstreak@1
|
246 faction = FACTION_ALLIANCE
|
flickerstreak@1
|
247 end
|
flickerstreak@1
|
248 local charID = string.format(PLAYER_OF_REALM, UnitName("player"), (string.gsub(GetRealmName(), "^%s*(.-)%s*$", "%1")))
|
flickerstreak@1
|
249 local realm = string.gsub(GetRealmName(), "^%s*(.-)%s*$", "%1")
|
flickerstreak@1
|
250 local realmID = realm .. " - " .. faction
|
flickerstreak@1
|
251 local classID = UnitClass("player")
|
flickerstreak@1
|
252
|
flickerstreak@1
|
253 AceDB.CHAR_ID = charID
|
flickerstreak@1
|
254 AceDB.REALM_ID = realmID
|
flickerstreak@1
|
255 AceDB.CLASS_ID = classID
|
flickerstreak@1
|
256
|
flickerstreak@1
|
257 AceDB.FACTION = faction
|
flickerstreak@1
|
258 AceDB.REALM = realm
|
flickerstreak@1
|
259 AceDB.NAME = UnitName("player")
|
flickerstreak@1
|
260
|
flickerstreak@1
|
261 local new, del
|
flickerstreak@1
|
262 do
|
flickerstreak@1
|
263 local list = setmetatable({}, {__mode="k"})
|
flickerstreak@1
|
264 function new()
|
flickerstreak@1
|
265 local t = next(list)
|
flickerstreak@1
|
266 if t then
|
flickerstreak@1
|
267 list[t] = nil
|
flickerstreak@1
|
268 return t
|
flickerstreak@1
|
269 else
|
flickerstreak@1
|
270 return {}
|
flickerstreak@1
|
271 end
|
flickerstreak@1
|
272 end
|
flickerstreak@1
|
273
|
flickerstreak@1
|
274 function del(t)
|
flickerstreak@1
|
275 setmetatable(t, nil)
|
flickerstreak@1
|
276 for k in pairs(t) do
|
flickerstreak@1
|
277 t[k] = nil
|
flickerstreak@1
|
278 end
|
flickerstreak@1
|
279 list[t] = true
|
flickerstreak@1
|
280 end
|
flickerstreak@1
|
281 end
|
flickerstreak@1
|
282
|
flickerstreak@1
|
283 local caseInsensitive_mt = {
|
flickerstreak@1
|
284 __index = function(self, key)
|
flickerstreak@1
|
285 if type(key) ~= "string" then
|
flickerstreak@1
|
286 return nil
|
flickerstreak@1
|
287 end
|
flickerstreak@1
|
288 local lowerKey = string.lower(key)
|
flickerstreak@1
|
289 for k,v in pairs(self) do
|
flickerstreak@1
|
290 if string.lower(k) == lowerKey then
|
flickerstreak@1
|
291 return self[k]
|
flickerstreak@1
|
292 end
|
flickerstreak@1
|
293 end
|
flickerstreak@1
|
294 end,
|
flickerstreak@1
|
295 __newindex = function(self, key, value)
|
flickerstreak@1
|
296 if type(key) ~= "string" then
|
flickerstreak@1
|
297 return error("table index is nil", 2)
|
flickerstreak@1
|
298 end
|
flickerstreak@1
|
299 local lowerKey = string.lower(key)
|
flickerstreak@1
|
300 for k in pairs(self) do
|
flickerstreak@1
|
301 if string.lower(k) == lowerKey then
|
flickerstreak@1
|
302 rawset(self, k, nil)
|
flickerstreak@1
|
303 rawset(self, key, value)
|
flickerstreak@1
|
304 return
|
flickerstreak@1
|
305 end
|
flickerstreak@1
|
306 end
|
flickerstreak@1
|
307 rawset(self, key, value)
|
flickerstreak@1
|
308 end
|
flickerstreak@1
|
309 }
|
flickerstreak@1
|
310
|
flickerstreak@1
|
311 local db_mt = { __index = function(db, key)
|
flickerstreak@1
|
312 if key == "char" then
|
flickerstreak@1
|
313 if db.charName then
|
flickerstreak@1
|
314 if type(_G[db.charName]) ~= "table" then
|
flickerstreak@1
|
315 _G[db.charName] = {}
|
flickerstreak@1
|
316 end
|
flickerstreak@1
|
317 if type(_G[db.charName].global) ~= "table" then
|
flickerstreak@1
|
318 _G[db.charName].global = {}
|
flickerstreak@1
|
319 end
|
flickerstreak@1
|
320 rawset(db, 'char', _G[db.charName].global)
|
flickerstreak@1
|
321 else
|
flickerstreak@1
|
322 if type(db.raw.chars) ~= "table" then
|
flickerstreak@1
|
323 db.raw.chars = {}
|
flickerstreak@1
|
324 end
|
flickerstreak@1
|
325 local id = charID
|
flickerstreak@1
|
326 if type(db.raw.chars[id]) ~= "table" then
|
flickerstreak@1
|
327 db.raw.chars[id] = {}
|
flickerstreak@1
|
328 end
|
flickerstreak@1
|
329 rawset(db, 'char', db.raw.chars[id])
|
flickerstreak@1
|
330 end
|
flickerstreak@1
|
331 if db.defaults and db.defaults.char then
|
flickerstreak@1
|
332 inheritDefaults(db.char, db.defaults.char)
|
flickerstreak@1
|
333 end
|
flickerstreak@1
|
334 return db.char
|
flickerstreak@1
|
335 elseif key == "realm" then
|
flickerstreak@1
|
336 if type(db.raw.realms) ~= "table" then
|
flickerstreak@1
|
337 db.raw.realms = {}
|
flickerstreak@1
|
338 end
|
flickerstreak@1
|
339 local id = realmID
|
flickerstreak@1
|
340 if type(db.raw.realms[id]) ~= "table" then
|
flickerstreak@1
|
341 db.raw.realms[id] = {}
|
flickerstreak@1
|
342 end
|
flickerstreak@1
|
343 rawset(db, 'realm', db.raw.realms[id])
|
flickerstreak@1
|
344 if db.defaults and db.defaults.realm then
|
flickerstreak@1
|
345 inheritDefaults(db.realm, db.defaults.realm)
|
flickerstreak@1
|
346 end
|
flickerstreak@1
|
347 return db.realm
|
flickerstreak@1
|
348 elseif key == "account" then
|
flickerstreak@1
|
349 if type(db.raw.account) ~= "table" then
|
flickerstreak@1
|
350 db.raw.account = {}
|
flickerstreak@1
|
351 end
|
flickerstreak@1
|
352 rawset(db, 'account', db.raw.account)
|
flickerstreak@1
|
353 if db.defaults and db.defaults.account then
|
flickerstreak@1
|
354 inheritDefaults(db.account, db.defaults.account)
|
flickerstreak@1
|
355 end
|
flickerstreak@1
|
356 return db.account
|
flickerstreak@1
|
357 elseif key == "faction" then
|
flickerstreak@1
|
358 if type(db.raw.factions) ~= "table" then
|
flickerstreak@1
|
359 db.raw.factions = {}
|
flickerstreak@1
|
360 end
|
flickerstreak@1
|
361 local id = faction
|
flickerstreak@1
|
362 if type(db.raw.factions[id]) ~= "table" then
|
flickerstreak@1
|
363 db.raw.factions[id] = {}
|
flickerstreak@1
|
364 end
|
flickerstreak@1
|
365 rawset(db, 'faction', db.raw.factions[id])
|
flickerstreak@1
|
366 if db.defaults and db.defaults.faction then
|
flickerstreak@1
|
367 inheritDefaults(db.faction, db.defaults.faction)
|
flickerstreak@1
|
368 end
|
flickerstreak@1
|
369 return db.faction
|
flickerstreak@1
|
370 elseif key == "class" then
|
flickerstreak@1
|
371 if type(db.raw.classes) ~= "table" then
|
flickerstreak@1
|
372 db.raw.classes = {}
|
flickerstreak@1
|
373 end
|
flickerstreak@1
|
374 local id = classID
|
flickerstreak@1
|
375 if type(db.raw.classes[id]) ~= "table" then
|
flickerstreak@1
|
376 db.raw.classes[id] = {}
|
flickerstreak@1
|
377 end
|
flickerstreak@1
|
378 rawset(db, 'class', db.raw.classes[id])
|
flickerstreak@1
|
379 if db.defaults and db.defaults.class then
|
flickerstreak@1
|
380 inheritDefaults(db.class, db.defaults.class)
|
flickerstreak@1
|
381 end
|
flickerstreak@1
|
382 return db.class
|
flickerstreak@1
|
383 elseif key == "profile" then
|
flickerstreak@1
|
384 if type(db.raw.profiles) ~= "table" then
|
flickerstreak@1
|
385 db.raw.profiles = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
386 else
|
flickerstreak@1
|
387 setmetatable(db.raw.profiles, caseInsensitive_mt)
|
flickerstreak@1
|
388 end
|
flickerstreak@1
|
389 local id = db.raw.currentProfile[charID]
|
flickerstreak@1
|
390 if id == "char" then
|
flickerstreak@1
|
391 id = "char/" .. charID
|
flickerstreak@1
|
392 elseif id == "class" then
|
flickerstreak@1
|
393 id = "class/" .. classID
|
flickerstreak@1
|
394 elseif id == "realm" then
|
flickerstreak@1
|
395 id = "realm/" .. realmID
|
flickerstreak@1
|
396 end
|
flickerstreak@1
|
397 if type(db.raw.profiles[id]) ~= "table" then
|
flickerstreak@1
|
398 db.raw.profiles[id] = {}
|
flickerstreak@1
|
399 end
|
flickerstreak@1
|
400 rawset(db, 'profile', db.raw.profiles[id])
|
flickerstreak@1
|
401 if db.defaults and db.defaults.profile then
|
flickerstreak@1
|
402 inheritDefaults(db.profile, db.defaults.profile)
|
flickerstreak@1
|
403 end
|
flickerstreak@1
|
404 return db.profile
|
flickerstreak@1
|
405 elseif key == "raw" or key == "defaults" or key == "name" or key == "charName" or key == "namespaces" then
|
flickerstreak@1
|
406 return nil
|
flickerstreak@1
|
407 end
|
flickerstreak@1
|
408 error(string.format('Cannot access key %q in db table. You may want to use db.profile[%q]', tostring(key), tostring(key)), 2)
|
flickerstreak@1
|
409 end, __newindex = function(db, key, value)
|
flickerstreak@1
|
410 error(string.format('Cannot access key %q in db table. You may want to use db.profile[%q]', tostring(key), tostring(key)), 2)
|
flickerstreak@1
|
411 end }
|
flickerstreak@1
|
412
|
flickerstreak@1
|
413 local function RecalculateAceDBCopyFromList(target)
|
flickerstreak@1
|
414 local db = target.db
|
flickerstreak@1
|
415 local t = target['acedb-profile-copylist']
|
flickerstreak@1
|
416 for k,v in pairs(t) do
|
flickerstreak@1
|
417 t[k] = nil
|
flickerstreak@1
|
418 end
|
flickerstreak@1
|
419 local _,currentProfile = AceDB.GetProfile(target)
|
flickerstreak@1
|
420 if db and db.raw then
|
flickerstreak@1
|
421 if db.raw.profiles then
|
flickerstreak@1
|
422 for k in pairs(db.raw.profiles) do
|
flickerstreak@1
|
423 if currentProfile ~= k then
|
flickerstreak@1
|
424 if string.find(k, '^char/') then
|
flickerstreak@1
|
425 local name = string.sub(k, 6)
|
flickerstreak@1
|
426 t[k] = CHARACTER_COLON .. name
|
flickerstreak@1
|
427 elseif string.find(k, '^realm/') then
|
flickerstreak@1
|
428 local name = string.sub(k, 7)
|
flickerstreak@1
|
429 t[k] = REALM_COLON .. name
|
flickerstreak@1
|
430 elseif string.find(k, '^class/') then
|
flickerstreak@1
|
431 local name = string.sub(k, 7)
|
flickerstreak@1
|
432 t[k] = CLASS_COLON .. name
|
flickerstreak@1
|
433 else
|
flickerstreak@1
|
434 t[k] = k
|
flickerstreak@1
|
435 end
|
flickerstreak@1
|
436 end
|
flickerstreak@1
|
437 end
|
flickerstreak@1
|
438 end
|
flickerstreak@1
|
439 if db.raw.namespaces then
|
flickerstreak@1
|
440 for _,n in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
441 if n.profiles then
|
flickerstreak@1
|
442 for k in pairs(n.profiles) do
|
flickerstreak@1
|
443 if currentProfile ~= k then
|
flickerstreak@1
|
444 if string.find(k, '^char/') then
|
flickerstreak@1
|
445 local name = string.sub(k, 6)
|
flickerstreak@1
|
446 t[k] = CHARACTER_COLON .. name
|
flickerstreak@1
|
447 elseif string.find(k, '^realm/') then
|
flickerstreak@1
|
448 local name = string.sub(k, 7)
|
flickerstreak@1
|
449 t[k] = REALM_COLON .. name
|
flickerstreak@1
|
450 elseif string.find(k, '^class/') then
|
flickerstreak@1
|
451 local name = string.sub(k, 7)
|
flickerstreak@1
|
452 t[k] = CLASS_COLON .. name
|
flickerstreak@1
|
453 else
|
flickerstreak@1
|
454 t[k] = k
|
flickerstreak@1
|
455 end
|
flickerstreak@1
|
456 end
|
flickerstreak@1
|
457 end
|
flickerstreak@1
|
458 end
|
flickerstreak@1
|
459 end
|
flickerstreak@1
|
460 end
|
flickerstreak@1
|
461 end
|
flickerstreak@1
|
462 if t.Default then
|
flickerstreak@1
|
463 t.Default = DEFAULT
|
flickerstreak@1
|
464 end
|
flickerstreak@1
|
465 if t.Alternative then
|
flickerstreak@1
|
466 t.Alternative = ALTERNATIVE
|
flickerstreak@1
|
467 end
|
flickerstreak@1
|
468 end
|
flickerstreak@1
|
469
|
flickerstreak@1
|
470 local function RecalculateAceDBProfileList(target)
|
flickerstreak@1
|
471 local t = target['acedb-profile-list']
|
flickerstreak@1
|
472 for k,v in pairs(t) do
|
flickerstreak@1
|
473 t[k] = nil
|
flickerstreak@1
|
474 end
|
flickerstreak@1
|
475 t.char = CHARACTER_COLON .. charID
|
flickerstreak@1
|
476 t.realm = REALM_COLON .. realmID
|
flickerstreak@1
|
477 t.class = CLASS_COLON .. classID
|
flickerstreak@1
|
478 t.Default = DEFAULT
|
flickerstreak@1
|
479 local db = target.db
|
flickerstreak@1
|
480 if db and db.raw then
|
flickerstreak@1
|
481 if db.raw.profiles then
|
flickerstreak@1
|
482 for k in pairs(db.raw.profiles) do
|
flickerstreak@1
|
483 if not string.find(k, '^char/') and not string.find(k, '^realm/') and not string.find(k, '^class/') then
|
flickerstreak@1
|
484 t[k] = k
|
flickerstreak@1
|
485 end
|
flickerstreak@1
|
486 end
|
flickerstreak@1
|
487 end
|
flickerstreak@1
|
488 if db.raw.namespaces then
|
flickerstreak@1
|
489 for _,n in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
490 if n.profiles then
|
flickerstreak@1
|
491 for k in pairs(n.profiles) do
|
flickerstreak@1
|
492 if not string.find(k, '^char/') and not string.find(k, '^realm/') and not string.find(k, '^class/') then
|
flickerstreak@1
|
493 t[k] = k
|
flickerstreak@1
|
494 end
|
flickerstreak@1
|
495 end
|
flickerstreak@1
|
496 end
|
flickerstreak@1
|
497 end
|
flickerstreak@1
|
498 end
|
flickerstreak@1
|
499 local curr = db.raw.currentProfile and db.raw.currentProfile[charID]
|
flickerstreak@1
|
500 if curr then
|
flickerstreak@1
|
501 t[curr] = curr
|
flickerstreak@1
|
502 end
|
flickerstreak@1
|
503 end
|
flickerstreak@1
|
504 if t.Alternative then
|
flickerstreak@1
|
505 t.Alternative = ALTERNATIVE
|
flickerstreak@1
|
506 end
|
flickerstreak@1
|
507 end
|
flickerstreak@1
|
508
|
flickerstreak@1
|
509 local CrawlForSerialization
|
flickerstreak@1
|
510 local CrawlForDeserialization
|
flickerstreak@1
|
511
|
flickerstreak@1
|
512 local function SerializeObject(o)
|
flickerstreak@1
|
513 local t = { o:Serialize() }
|
flickerstreak@1
|
514 CrawlForSerialization(t)
|
flickerstreak@1
|
515 t[0] = o.class:GetLibraryVersion()
|
flickerstreak@1
|
516 return t
|
flickerstreak@1
|
517 end
|
flickerstreak@1
|
518
|
flickerstreak@1
|
519 local function DeserializeObject(t)
|
flickerstreak@1
|
520 CrawlForDeserialization(t)
|
flickerstreak@1
|
521 local className = t[0]
|
flickerstreak@1
|
522 t[0] = nil
|
flickerstreak@1
|
523 return AceLibrary(className):Deserialize(unpack(t))
|
flickerstreak@1
|
524 end
|
flickerstreak@1
|
525
|
flickerstreak@1
|
526 local function IsSerializable(t)
|
flickerstreak@1
|
527 return AceOO.inherits(t, AceOO.Class) and t.class and type(t.class.Deserialize) == "function" and type(t.Serialize) == "function" and type(t.class.GetLibraryVersion) == "function"
|
flickerstreak@1
|
528 end
|
flickerstreak@1
|
529
|
flickerstreak@1
|
530 function CrawlForSerialization(t)
|
flickerstreak@1
|
531 local tmp = new()
|
flickerstreak@1
|
532 for k,v in pairs(t) do
|
flickerstreak@1
|
533 tmp[k] = v
|
flickerstreak@1
|
534 end
|
flickerstreak@1
|
535 for k,v in pairs(tmp) do
|
flickerstreak@1
|
536 if type(v) == "table" and type(v[0]) ~= "userdata" then
|
flickerstreak@1
|
537 if IsSerializable(v) then
|
flickerstreak@1
|
538 v = SerializeObject(v)
|
flickerstreak@1
|
539 t[k] = v
|
flickerstreak@1
|
540 else
|
flickerstreak@1
|
541 CrawlForSerialization(v)
|
flickerstreak@1
|
542 end
|
flickerstreak@1
|
543 end
|
flickerstreak@1
|
544 if type(k) == "table" and type(k[0]) ~= "userdata" then
|
flickerstreak@1
|
545 if IsSerializable(k) then
|
flickerstreak@1
|
546 t[k] = nil
|
flickerstreak@1
|
547 t[SerializeObject(k)] = v
|
flickerstreak@1
|
548 else
|
flickerstreak@1
|
549 CrawlForSerialization(k)
|
flickerstreak@1
|
550 end
|
flickerstreak@1
|
551 end
|
flickerstreak@1
|
552 tmp[k] = nil
|
flickerstreak@1
|
553 k = nil
|
flickerstreak@1
|
554 end
|
flickerstreak@1
|
555 tmp = del(tmp)
|
flickerstreak@1
|
556 end
|
flickerstreak@1
|
557
|
flickerstreak@1
|
558 local function IsDeserializable(t)
|
flickerstreak@1
|
559 return type(t[0]) == "string" and AceLibrary:HasInstance(t[0])
|
flickerstreak@1
|
560 end
|
flickerstreak@1
|
561
|
flickerstreak@1
|
562 function CrawlForDeserialization(t)
|
flickerstreak@1
|
563 local tmp = new()
|
flickerstreak@1
|
564 for k,v in pairs(t) do
|
flickerstreak@1
|
565 tmp[k] = v
|
flickerstreak@1
|
566 end
|
flickerstreak@1
|
567 for k,v in pairs(tmp) do
|
flickerstreak@1
|
568 if type(v) == "table" then
|
flickerstreak@1
|
569 if IsDeserializable(v) then
|
flickerstreak@1
|
570 t[k] = DeserializeObject(v)
|
flickerstreak@1
|
571 del(v)
|
flickerstreak@1
|
572 v = t[k]
|
flickerstreak@1
|
573 elseif type(v[0]) ~= "userdata" then
|
flickerstreak@1
|
574 CrawlForDeserialization(v)
|
flickerstreak@1
|
575 end
|
flickerstreak@1
|
576 end
|
flickerstreak@1
|
577 if type(k) == "table" then
|
flickerstreak@1
|
578 if IsDeserializable(k) then
|
flickerstreak@1
|
579 t[k] = nil
|
flickerstreak@1
|
580 t[DeserializeObject(k)] = v
|
flickerstreak@1
|
581 del(k)
|
flickerstreak@1
|
582 elseif type(k[0]) ~= "userdata" then
|
flickerstreak@1
|
583 CrawlForDeserialization(k)
|
flickerstreak@1
|
584 end
|
flickerstreak@1
|
585 end
|
flickerstreak@1
|
586 tmp[k] = nil
|
flickerstreak@1
|
587 k = nil
|
flickerstreak@1
|
588 end
|
flickerstreak@1
|
589 tmp = del(tmp)
|
flickerstreak@1
|
590 end
|
flickerstreak@1
|
591
|
flickerstreak@1
|
592 local namespace_mt = { __index = function(namespace, key)
|
flickerstreak@1
|
593 local db = namespace.db
|
flickerstreak@1
|
594 local name = namespace.name
|
flickerstreak@1
|
595 if key == "char" then
|
flickerstreak@1
|
596 if db.charName then
|
flickerstreak@1
|
597 if type(_G[db.charName]) ~= "table" then
|
flickerstreak@1
|
598 _G[db.charName] = {}
|
flickerstreak@1
|
599 end
|
flickerstreak@1
|
600 if type(_G[db.charName].namespaces) ~= "table" then
|
flickerstreak@1
|
601 _G[db.charName].namespaces = {}
|
flickerstreak@1
|
602 end
|
flickerstreak@1
|
603 if type(_G[db.charName].namespaces[name]) ~= "table" then
|
flickerstreak@1
|
604 _G[db.charName].namespaces[name] = {}
|
flickerstreak@1
|
605 end
|
flickerstreak@1
|
606 rawset(namespace, 'char', _G[db.charName].namespaces[name])
|
flickerstreak@1
|
607 else
|
flickerstreak@1
|
608 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
609 db.raw.namespaces = {}
|
flickerstreak@1
|
610 end
|
flickerstreak@1
|
611 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
612 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
613 end
|
flickerstreak@1
|
614 if type(db.raw.namespaces[name].chars) ~= "table" then
|
flickerstreak@1
|
615 db.raw.namespaces[name].chars = {}
|
flickerstreak@1
|
616 end
|
flickerstreak@1
|
617 local id = charID
|
flickerstreak@1
|
618 if type(db.raw.namespaces[name].chars[id]) ~= "table" then
|
flickerstreak@1
|
619 db.raw.namespaces[name].chars[id] = {}
|
flickerstreak@1
|
620 end
|
flickerstreak@1
|
621 rawset(namespace, 'char', db.raw.namespaces[name].chars[id])
|
flickerstreak@1
|
622 end
|
flickerstreak@1
|
623 if namespace.defaults and namespace.defaults.char then
|
flickerstreak@1
|
624 inheritDefaults(namespace.char, namespace.defaults.char)
|
flickerstreak@1
|
625 end
|
flickerstreak@1
|
626 return namespace.char
|
flickerstreak@1
|
627 elseif key == "realm" then
|
flickerstreak@1
|
628 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
629 db.raw.namespaces = {}
|
flickerstreak@1
|
630 end
|
flickerstreak@1
|
631 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
632 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
633 end
|
flickerstreak@1
|
634 if type(db.raw.namespaces[name].realms) ~= "table" then
|
flickerstreak@1
|
635 db.raw.namespaces[name].realms = {}
|
flickerstreak@1
|
636 end
|
flickerstreak@1
|
637 local id = realmID
|
flickerstreak@1
|
638 if type(db.raw.namespaces[name].realms[id]) ~= "table" then
|
flickerstreak@1
|
639 db.raw.namespaces[name].realms[id] = {}
|
flickerstreak@1
|
640 end
|
flickerstreak@1
|
641 rawset(namespace, 'realm', db.raw.namespaces[name].realms[id])
|
flickerstreak@1
|
642 if namespace.defaults and namespace.defaults.realm then
|
flickerstreak@1
|
643 inheritDefaults(namespace.realm, namespace.defaults.realm)
|
flickerstreak@1
|
644 end
|
flickerstreak@1
|
645 return namespace.realm
|
flickerstreak@1
|
646 elseif key == "account" then
|
flickerstreak@1
|
647 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
648 db.raw.namespaces = {}
|
flickerstreak@1
|
649 end
|
flickerstreak@1
|
650 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
651 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
652 end
|
flickerstreak@1
|
653 if type(db.raw.namespaces[name].account) ~= "table" then
|
flickerstreak@1
|
654 db.raw.namespaces[name].account = {}
|
flickerstreak@1
|
655 end
|
flickerstreak@1
|
656 rawset(namespace, 'account', db.raw.namespaces[name].account)
|
flickerstreak@1
|
657 if namespace.defaults and namespace.defaults.account then
|
flickerstreak@1
|
658 inheritDefaults(namespace.account, namespace.defaults.account)
|
flickerstreak@1
|
659 end
|
flickerstreak@1
|
660 return namespace.account
|
flickerstreak@1
|
661 elseif key == "faction" then
|
flickerstreak@1
|
662 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
663 db.raw.namespaces = {}
|
flickerstreak@1
|
664 end
|
flickerstreak@1
|
665 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
666 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
667 end
|
flickerstreak@1
|
668 if type(db.raw.namespaces[name].factions) ~= "table" then
|
flickerstreak@1
|
669 db.raw.namespaces[name].factions = {}
|
flickerstreak@1
|
670 end
|
flickerstreak@1
|
671 local id = faction
|
flickerstreak@1
|
672 if type(db.raw.namespaces[name].factions[id]) ~= "table" then
|
flickerstreak@1
|
673 db.raw.namespaces[name].factions[id] = {}
|
flickerstreak@1
|
674 end
|
flickerstreak@1
|
675 rawset(namespace, 'faction', db.raw.namespaces[name].factions[id])
|
flickerstreak@1
|
676 if namespace.defaults and namespace.defaults.faction then
|
flickerstreak@1
|
677 inheritDefaults(namespace.faction, namespace.defaults.faction)
|
flickerstreak@1
|
678 end
|
flickerstreak@1
|
679 return namespace.faction
|
flickerstreak@1
|
680 elseif key == "class" then
|
flickerstreak@1
|
681 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
682 db.raw.namespaces = {}
|
flickerstreak@1
|
683 end
|
flickerstreak@1
|
684 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
685 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
686 end
|
flickerstreak@1
|
687 if type(db.raw.namespaces[name].classes) ~= "table" then
|
flickerstreak@1
|
688 db.raw.namespaces[name].classes = {}
|
flickerstreak@1
|
689 end
|
flickerstreak@1
|
690 local id = classID
|
flickerstreak@1
|
691 if type(db.raw.namespaces[name].classes[id]) ~= "table" then
|
flickerstreak@1
|
692 db.raw.namespaces[name].classes[id] = {}
|
flickerstreak@1
|
693 end
|
flickerstreak@1
|
694 rawset(namespace, 'class', db.raw.namespaces[name].classes[id])
|
flickerstreak@1
|
695 if namespace.defaults and namespace.defaults.class then
|
flickerstreak@1
|
696 inheritDefaults(namespace.class, namespace.defaults.class)
|
flickerstreak@1
|
697 end
|
flickerstreak@1
|
698 return namespace.class
|
flickerstreak@1
|
699 elseif key == "profile" then
|
flickerstreak@1
|
700 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
701 db.raw.namespaces = {}
|
flickerstreak@1
|
702 end
|
flickerstreak@1
|
703 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
704 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
705 end
|
flickerstreak@1
|
706 if type(db.raw.namespaces[name].profiles) ~= "table" then
|
flickerstreak@1
|
707 db.raw.namespaces[name].profiles = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
708 else
|
flickerstreak@1
|
709 setmetatable(db.raw.namespaces[name].profiles, caseInsensitive_mt)
|
flickerstreak@1
|
710 end
|
flickerstreak@1
|
711 local id = db.raw.currentProfile[charID]
|
flickerstreak@1
|
712 if id == "char" then
|
flickerstreak@1
|
713 id = "char/" .. charID
|
flickerstreak@1
|
714 elseif id == "class" then
|
flickerstreak@1
|
715 id = "class/" .. classID
|
flickerstreak@1
|
716 elseif id == "realm" then
|
flickerstreak@1
|
717 id = "realm/" .. realmID
|
flickerstreak@1
|
718 end
|
flickerstreak@1
|
719 if type(db.raw.namespaces[name].profiles[id]) ~= "table" then
|
flickerstreak@1
|
720 db.raw.namespaces[name].profiles[id] = {}
|
flickerstreak@1
|
721 end
|
flickerstreak@1
|
722 rawset(namespace, 'profile', db.raw.namespaces[name].profiles[id])
|
flickerstreak@1
|
723 if namespace.defaults and namespace.defaults.profile then
|
flickerstreak@1
|
724 inheritDefaults(namespace.profile, namespace.defaults.profile)
|
flickerstreak@1
|
725 end
|
flickerstreak@1
|
726 return namespace.profile
|
flickerstreak@1
|
727 elseif key == "defaults" or key == "name" or key == "db" then
|
flickerstreak@1
|
728 return nil
|
flickerstreak@1
|
729 end
|
flickerstreak@1
|
730 error(string.format('Cannot access key %q in db table. You may want to use db.profile[%q]', tostring(key), tostring(key)), 2)
|
flickerstreak@1
|
731 end, __newindex = function(db, key, value)
|
flickerstreak@1
|
732 error(string.format('Cannot access key %q in db table. You may want to use db.profile[%q]', tostring(key), tostring(key)), 2)
|
flickerstreak@1
|
733 end }
|
flickerstreak@1
|
734
|
flickerstreak@1
|
735 function AceDB:InitializeDB(addonName)
|
flickerstreak@1
|
736 local db = self.db
|
flickerstreak@1
|
737
|
flickerstreak@1
|
738 if not db then
|
flickerstreak@1
|
739 if addonName then
|
flickerstreak@1
|
740 AceDB.addonsLoaded[addonName] = true
|
flickerstreak@1
|
741 end
|
flickerstreak@1
|
742 return
|
flickerstreak@1
|
743 end
|
flickerstreak@1
|
744
|
flickerstreak@1
|
745 if db.raw then
|
flickerstreak@1
|
746 -- someone manually initialized
|
flickerstreak@1
|
747 return
|
flickerstreak@1
|
748 end
|
flickerstreak@1
|
749
|
flickerstreak@1
|
750 if type(_G[db.name]) ~= "table" then
|
flickerstreak@1
|
751 _G[db.name] = {}
|
flickerstreak@1
|
752 else
|
flickerstreak@1
|
753 CrawlForDeserialization(_G[db.name])
|
flickerstreak@1
|
754 end
|
flickerstreak@1
|
755 if type(_G[db.charName]) == "table" then
|
flickerstreak@1
|
756 CrawlForDeserialization(_G[db.charName])
|
flickerstreak@1
|
757 end
|
flickerstreak@1
|
758 rawset(db, 'raw', _G[db.name])
|
flickerstreak@1
|
759 if not db.raw.currentProfile then
|
flickerstreak@1
|
760 db.raw.currentProfile = {}
|
flickerstreak@1
|
761 end
|
flickerstreak@1
|
762 if not db.raw.currentProfile[charID] then
|
flickerstreak@1
|
763 db.raw.currentProfile[charID] = "Default"
|
flickerstreak@1
|
764 end
|
flickerstreak@1
|
765 if db.raw.disabled then
|
flickerstreak@1
|
766 setmetatable(db.raw.disabled, caseInsensitive_mt)
|
flickerstreak@1
|
767 end
|
flickerstreak@1
|
768 if self['acedb-profile-copylist'] then
|
flickerstreak@1
|
769 RecalculateAceDBCopyFromList(self)
|
flickerstreak@1
|
770 end
|
flickerstreak@1
|
771 if self['acedb-profile-list'] then
|
flickerstreak@1
|
772 RecalculateAceDBProfileList(self)
|
flickerstreak@1
|
773 end
|
flickerstreak@1
|
774 setmetatable(db, db_mt)
|
flickerstreak@1
|
775 end
|
flickerstreak@1
|
776
|
flickerstreak@1
|
777 function AceDB:OnEmbedInitialize(target, name)
|
flickerstreak@1
|
778 if name then
|
flickerstreak@1
|
779 self:ADDON_LOADED(name)
|
flickerstreak@1
|
780 end
|
flickerstreak@1
|
781 self.InitializeDB(target, name)
|
flickerstreak@1
|
782 end
|
flickerstreak@1
|
783
|
flickerstreak@1
|
784 function AceDB:RegisterDB(name, charName)
|
flickerstreak@1
|
785 AceDB:argCheck(name, 2, "string")
|
flickerstreak@1
|
786 AceDB:argCheck(charName, 3, "string", "nil")
|
flickerstreak@1
|
787 if self.db then
|
flickerstreak@1
|
788 AceDB:error("Cannot call \"RegisterDB\" if self.db is set.")
|
flickerstreak@1
|
789 end
|
flickerstreak@1
|
790 local stack = debugstack()
|
flickerstreak@1
|
791 local addonName = string.gsub(stack, ".-\n.-\\AddOns\\(.-)\\.*", "%1")
|
flickerstreak@1
|
792 self.db = {
|
flickerstreak@1
|
793 name = name,
|
flickerstreak@1
|
794 charName = charName
|
flickerstreak@1
|
795 }
|
flickerstreak@1
|
796 if AceDB.addonsLoaded[addonName] then
|
flickerstreak@1
|
797 AceDB.InitializeDB(self, addonName)
|
flickerstreak@1
|
798 else
|
flickerstreak@1
|
799 AceDB.addonsToBeInitialized[self] = addonName
|
flickerstreak@1
|
800 end
|
flickerstreak@1
|
801 AceDB.registry[self] = true
|
flickerstreak@1
|
802 end
|
flickerstreak@1
|
803
|
flickerstreak@1
|
804 function AceDB:RegisterDefaults(kind, defaults, a3)
|
flickerstreak@1
|
805 local name
|
flickerstreak@1
|
806 if a3 then
|
flickerstreak@1
|
807 name, kind, defaults = kind, defaults, a3
|
flickerstreak@1
|
808 AceDB:argCheck(name, 2, "string")
|
flickerstreak@1
|
809 AceDB:argCheck(kind, 3, "string")
|
flickerstreak@1
|
810 AceDB:argCheck(defaults, 4, "table")
|
flickerstreak@1
|
811 else
|
flickerstreak@1
|
812 AceDB:argCheck(kind, 2, "string")
|
flickerstreak@1
|
813 AceDB:argCheck(defaults, 3, "table")
|
flickerstreak@1
|
814 end
|
flickerstreak@1
|
815 if kind ~= "char" and kind ~= "class" and kind ~= "profile" and kind ~= "account" and kind ~= "realm" and kind ~= "faction" then
|
flickerstreak@1
|
816 AceDB:error("Bad argument #%d to `RegisterDefaults' (\"char\", \"class\", \"profile\", \"account\", \"realm\", or \"faction\" expected, got %q)", a3 and 3 or 2, kind)
|
flickerstreak@1
|
817 end
|
flickerstreak@1
|
818 if type(self.db) ~= "table" or type(self.db.name) ~= "string" then
|
flickerstreak@1
|
819 AceDB:error("Cannot call \"RegisterDefaults\" unless \"RegisterDB\" has been previously called.")
|
flickerstreak@1
|
820 end
|
flickerstreak@1
|
821 local db
|
flickerstreak@1
|
822 if name then
|
flickerstreak@1
|
823 local namespace = self:AcquireDBNamespace(name)
|
flickerstreak@1
|
824 if namespace.defaults and namespace.defaults[kind] then
|
flickerstreak@1
|
825 AceDB:error("\"RegisterDefaults\" has already been called for %q::%q.", name, kind)
|
flickerstreak@1
|
826 end
|
flickerstreak@1
|
827 db = namespace
|
flickerstreak@1
|
828 else
|
flickerstreak@1
|
829 if self.db.defaults and self.db.defaults[kind] then
|
flickerstreak@1
|
830 AceDB:error("\"RegisterDefaults\" has already been called for %q.", kind)
|
flickerstreak@1
|
831 end
|
flickerstreak@1
|
832 db = self.db
|
flickerstreak@1
|
833 end
|
flickerstreak@1
|
834 if not db.defaults then
|
flickerstreak@1
|
835 rawset(db, 'defaults', {})
|
flickerstreak@1
|
836 end
|
flickerstreak@1
|
837 db.defaults[kind] = defaults
|
flickerstreak@1
|
838 if rawget(db, kind) then
|
flickerstreak@1
|
839 inheritDefaults(db[kind], defaults)
|
flickerstreak@1
|
840 end
|
flickerstreak@1
|
841 end
|
flickerstreak@1
|
842
|
flickerstreak@1
|
843 function AceDB:ResetDB(kind)
|
flickerstreak@1
|
844 AceDB:argCheck(kind, 2, "nil", "string")
|
flickerstreak@1
|
845 if not self.db or not self.db.raw then
|
flickerstreak@1
|
846 AceDB:error("Cannot call \"ResetDB\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.")
|
flickerstreak@1
|
847 end
|
flickerstreak@1
|
848 local db = self.db
|
flickerstreak@1
|
849 if kind == nil then
|
flickerstreak@1
|
850 if db.charName then
|
flickerstreak@1
|
851 _G[db.charName] = nil
|
flickerstreak@1
|
852 end
|
flickerstreak@1
|
853 _G[db.name] = nil
|
flickerstreak@1
|
854 rawset(db, 'raw', nil)
|
flickerstreak@1
|
855 AceDB.InitializeDB(self)
|
flickerstreak@1
|
856 if db.namespaces then
|
flickerstreak@1
|
857 for name,v in pairs(db.namespaces) do
|
flickerstreak@1
|
858 rawset(v, 'account', nil)
|
flickerstreak@1
|
859 rawset(v, 'char', nil)
|
flickerstreak@1
|
860 rawset(v, 'class', nil)
|
flickerstreak@1
|
861 rawset(v, 'profile', nil)
|
flickerstreak@1
|
862 rawset(v, 'realm', nil)
|
flickerstreak@1
|
863 rawset(v, 'faction', nil)
|
flickerstreak@1
|
864 end
|
flickerstreak@1
|
865 end
|
flickerstreak@1
|
866 elseif kind == "account" then
|
flickerstreak@1
|
867 db.raw.account = nil
|
flickerstreak@1
|
868 rawset(db, 'account', nil)
|
flickerstreak@1
|
869 if db.namespaces then
|
flickerstreak@1
|
870 for name,v in pairs(db.namespaces) do
|
flickerstreak@1
|
871 rawset(v, 'account', nil)
|
flickerstreak@1
|
872 end
|
flickerstreak@1
|
873 end
|
flickerstreak@1
|
874 elseif kind == "char" then
|
flickerstreak@1
|
875 if db.charName then
|
flickerstreak@1
|
876 _G[db.charName] = nil
|
flickerstreak@1
|
877 else
|
flickerstreak@1
|
878 if db.raw.chars then
|
flickerstreak@1
|
879 db.raw.chars[charID] = nil
|
flickerstreak@1
|
880 end
|
flickerstreak@1
|
881 if db.raw.namespaces then
|
flickerstreak@1
|
882 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
883 if v.chars then
|
flickerstreak@1
|
884 v.chars[charID] = nil
|
flickerstreak@1
|
885 end
|
flickerstreak@1
|
886 end
|
flickerstreak@1
|
887 end
|
flickerstreak@1
|
888 end
|
flickerstreak@1
|
889 rawset(db, 'char', nil)
|
flickerstreak@1
|
890 if db.namespaces then
|
flickerstreak@1
|
891 for name,v in pairs(db.namespaces) do
|
flickerstreak@1
|
892 rawset(v, 'char', nil)
|
flickerstreak@1
|
893 end
|
flickerstreak@1
|
894 end
|
flickerstreak@1
|
895 elseif kind == "realm" then
|
flickerstreak@1
|
896 if db.raw.realms then
|
flickerstreak@1
|
897 db.raw.realms[realmID] = nil
|
flickerstreak@1
|
898 end
|
flickerstreak@1
|
899 rawset(db, 'realm', nil)
|
flickerstreak@1
|
900 if db.raw.namespaces then
|
flickerstreak@1
|
901 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
902 if v.realms then
|
flickerstreak@1
|
903 v.realms[realmID] = nil
|
flickerstreak@1
|
904 end
|
flickerstreak@1
|
905 end
|
flickerstreak@1
|
906 end
|
flickerstreak@1
|
907 if db.namespaces then
|
flickerstreak@1
|
908 for name,v in pairs(db.namespaces) do
|
flickerstreak@1
|
909 rawset(v, 'realm', nil)
|
flickerstreak@1
|
910 end
|
flickerstreak@1
|
911 end
|
flickerstreak@1
|
912 elseif kind == "faction" then
|
flickerstreak@1
|
913 if db.raw.factions then
|
flickerstreak@1
|
914 db.raw.factions[faction] = nil
|
flickerstreak@1
|
915 end
|
flickerstreak@1
|
916 rawset(db, 'faction', nil)
|
flickerstreak@1
|
917 if db.raw.namespaces then
|
flickerstreak@1
|
918 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
919 if v.factions then
|
flickerstreak@1
|
920 v.factions[faction] = nil
|
flickerstreak@1
|
921 end
|
flickerstreak@1
|
922 end
|
flickerstreak@1
|
923 end
|
flickerstreak@1
|
924 if db.namespaces then
|
flickerstreak@1
|
925 for name,v in pairs(db.namespaces) do
|
flickerstreak@1
|
926 rawset(v, 'faction', nil)
|
flickerstreak@1
|
927 end
|
flickerstreak@1
|
928 end
|
flickerstreak@1
|
929 elseif kind == "class" then
|
flickerstreak@1
|
930 if db.raw.realms then
|
flickerstreak@1
|
931 db.raw.realms[classID] = nil
|
flickerstreak@1
|
932 end
|
flickerstreak@1
|
933 rawset(db, 'class', nil)
|
flickerstreak@1
|
934 if db.raw.namespaces then
|
flickerstreak@1
|
935 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
936 if v.classes then
|
flickerstreak@1
|
937 v.classes[classID] = nil
|
flickerstreak@1
|
938 end
|
flickerstreak@1
|
939 end
|
flickerstreak@1
|
940 end
|
flickerstreak@1
|
941 if db.namespaces then
|
flickerstreak@1
|
942 for name,v in pairs(db.namespaces) do
|
flickerstreak@1
|
943 rawset(v, 'class', nil)
|
flickerstreak@1
|
944 end
|
flickerstreak@1
|
945 end
|
flickerstreak@1
|
946 elseif kind == "profile" then
|
flickerstreak@1
|
947 local id = db.raw.currentProfile and db.raw.currentProfile[charID] or "Default"
|
flickerstreak@1
|
948 if id == "char" then
|
flickerstreak@1
|
949 id = "char/" .. charID
|
flickerstreak@1
|
950 elseif id == "class" then
|
flickerstreak@1
|
951 id = "class/" .. classID
|
flickerstreak@1
|
952 elseif id == "realm" then
|
flickerstreak@1
|
953 id = "realm/" .. realmID
|
flickerstreak@1
|
954 end
|
flickerstreak@1
|
955 if db.raw.profiles then
|
flickerstreak@1
|
956 db.raw.profiles[id] = nil
|
flickerstreak@1
|
957 end
|
flickerstreak@1
|
958 rawset(db, 'profile', nil)
|
flickerstreak@1
|
959 if db.raw.namespaces then
|
flickerstreak@1
|
960 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
961 if v.profiles then
|
flickerstreak@1
|
962 v.profiles[id] = nil
|
flickerstreak@1
|
963 end
|
flickerstreak@1
|
964 end
|
flickerstreak@1
|
965 end
|
flickerstreak@1
|
966 if db.namespaces then
|
flickerstreak@1
|
967 for name,v in pairs(db.namespaces) do
|
flickerstreak@1
|
968 rawset(v, 'profile', nil)
|
flickerstreak@1
|
969 end
|
flickerstreak@1
|
970 end
|
flickerstreak@1
|
971 end
|
flickerstreak@1
|
972 end
|
flickerstreak@1
|
973
|
flickerstreak@1
|
974 local function cleanDefaults(t, defaults)
|
flickerstreak@1
|
975 if defaults then
|
flickerstreak@1
|
976 for k,v in pairs(defaults) do
|
flickerstreak@1
|
977 if k == "*" then
|
flickerstreak@1
|
978 if type(v) == "table" then
|
flickerstreak@1
|
979 for k in pairs(t) do
|
flickerstreak@1
|
980 if (defaults[k] == nil or k == "*") and type(t[k]) == "table" then
|
flickerstreak@1
|
981 if cleanDefaults(t[k], v) then
|
flickerstreak@1
|
982 t[k] = nil
|
flickerstreak@1
|
983 end
|
flickerstreak@1
|
984 end
|
flickerstreak@1
|
985 end
|
flickerstreak@1
|
986 else
|
flickerstreak@1
|
987 for k in pairs(t) do
|
flickerstreak@1
|
988 if (defaults[k] == nil or k == "*") and t[k] == v then
|
flickerstreak@1
|
989 t[k] = nil
|
flickerstreak@1
|
990 end
|
flickerstreak@1
|
991 end
|
flickerstreak@1
|
992 end
|
flickerstreak@1
|
993 else
|
flickerstreak@1
|
994 if type(v) == "table" then
|
flickerstreak@1
|
995 if type(t[k]) == "table" then
|
flickerstreak@1
|
996 if cleanDefaults(t[k], v) then
|
flickerstreak@1
|
997 t[k] = nil
|
flickerstreak@1
|
998 end
|
flickerstreak@1
|
999 end
|
flickerstreak@1
|
1000 elseif t[k] == v then
|
flickerstreak@1
|
1001 t[k] = nil
|
flickerstreak@1
|
1002 end
|
flickerstreak@1
|
1003 end
|
flickerstreak@1
|
1004 end
|
flickerstreak@1
|
1005 end
|
flickerstreak@1
|
1006 return t and not next(t)
|
flickerstreak@1
|
1007 end
|
flickerstreak@1
|
1008
|
flickerstreak@1
|
1009 function AceDB:GetProfile()
|
flickerstreak@1
|
1010 if not self.db or not self.db.raw then
|
flickerstreak@1
|
1011 return nil
|
flickerstreak@1
|
1012 end
|
flickerstreak@1
|
1013 if not self.db.raw.currentProfile then
|
flickerstreak@1
|
1014 self.db.raw.currentProfile = {}
|
flickerstreak@1
|
1015 end
|
flickerstreak@1
|
1016 if not self.db.raw.currentProfile[charID] then
|
flickerstreak@1
|
1017 self.db.raw.currentProfile[charID] = "Default"
|
flickerstreak@1
|
1018 end
|
flickerstreak@1
|
1019 local profile = self.db.raw.currentProfile[charID]
|
flickerstreak@1
|
1020 if profile == "char" then
|
flickerstreak@1
|
1021 return "char", "char/" .. charID
|
flickerstreak@1
|
1022 elseif profile == "class" then
|
flickerstreak@1
|
1023 return "class", "class/" .. classID
|
flickerstreak@1
|
1024 elseif profile == "realm" then
|
flickerstreak@1
|
1025 return "realm", "realm/" .. realmID
|
flickerstreak@1
|
1026 end
|
flickerstreak@1
|
1027 return profile, profile
|
flickerstreak@1
|
1028 end
|
flickerstreak@1
|
1029
|
flickerstreak@1
|
1030 local function copyTable(to, from)
|
flickerstreak@1
|
1031 setmetatable(to, nil)
|
flickerstreak@1
|
1032 for k,v in pairs(from) do
|
flickerstreak@1
|
1033 if type(k) == "table" then
|
flickerstreak@1
|
1034 k = copyTable({}, k)
|
flickerstreak@1
|
1035 end
|
flickerstreak@1
|
1036 if type(v) == "table" then
|
flickerstreak@1
|
1037 v = copyTable({}, v)
|
flickerstreak@1
|
1038 end
|
flickerstreak@1
|
1039 to[k] = v
|
flickerstreak@1
|
1040 end
|
flickerstreak@1
|
1041 setmetatable(to, from)
|
flickerstreak@1
|
1042 return to
|
flickerstreak@1
|
1043 end
|
flickerstreak@1
|
1044
|
flickerstreak@1
|
1045 function AceDB:SetProfile(name)
|
flickerstreak@1
|
1046 AceDB:argCheck(name, 2, "string")
|
flickerstreak@1
|
1047 if not self.db or not self.db.raw then
|
flickerstreak@1
|
1048 AceDB:error("Cannot call \"SetProfile\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.")
|
flickerstreak@1
|
1049 end
|
flickerstreak@1
|
1050 local db = self.db
|
flickerstreak@1
|
1051 local lowerName = string.lower(name)
|
flickerstreak@1
|
1052 if string.sub(lowerName, 1, 5) == "char/" or string.sub(lowerName, 1, 6) == "realm/" or string.sub(lowerName, 1, 6) == "class/" then
|
flickerstreak@1
|
1053 if string.sub(lowerName, 1, 5) == "char/" then
|
flickerstreak@1
|
1054 name = "char"
|
flickerstreak@1
|
1055 else
|
flickerstreak@1
|
1056 name = string.sub(lowerName, 1, 5)
|
flickerstreak@1
|
1057 end
|
flickerstreak@1
|
1058 lowerName = string.lower(name)
|
flickerstreak@1
|
1059 end
|
flickerstreak@1
|
1060 local oldName = db.raw.currentProfile[charID]
|
flickerstreak@1
|
1061 if string.lower(oldName) == string.lower(name) then
|
flickerstreak@1
|
1062 return
|
flickerstreak@1
|
1063 end
|
flickerstreak@1
|
1064 local oldProfileData = db.profile
|
flickerstreak@1
|
1065 local realName = name
|
flickerstreak@1
|
1066 if lowerName == "char" then
|
flickerstreak@1
|
1067 realName = name .. "/" .. charID
|
flickerstreak@1
|
1068 elseif lowerName == "realm" then
|
flickerstreak@1
|
1069 realName = name .. "/" .. realmID
|
flickerstreak@1
|
1070 elseif lowerName == "class" then
|
flickerstreak@1
|
1071 realName = name .. "/" .. classID
|
flickerstreak@1
|
1072 end
|
flickerstreak@1
|
1073 local current = self.class
|
flickerstreak@1
|
1074 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1075 if current.mixins then
|
flickerstreak@1
|
1076 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1077 if type(mixin.OnEmbedProfileDisable) == "function" then
|
flickerstreak@1
|
1078 safecall(mixin.OnEmbedProfileDisable, mixin, self, realName)
|
flickerstreak@1
|
1079 end
|
flickerstreak@1
|
1080 end
|
flickerstreak@1
|
1081 end
|
flickerstreak@1
|
1082 current = current.super
|
flickerstreak@1
|
1083 end
|
flickerstreak@1
|
1084 if type(self.OnProfileDisable) == "function" then
|
flickerstreak@1
|
1085 safecall(self.OnProfileDisable, self, realName)
|
flickerstreak@1
|
1086 end
|
flickerstreak@1
|
1087 local active = self:IsActive()
|
flickerstreak@1
|
1088 db.raw.currentProfile[charID] = name
|
flickerstreak@1
|
1089 rawset(db, 'profile', nil)
|
flickerstreak@1
|
1090 if db.namespaces then
|
flickerstreak@1
|
1091 for k,v in pairs(db.namespaces) do
|
flickerstreak@1
|
1092 rawset(v, 'profile', nil)
|
flickerstreak@1
|
1093 end
|
flickerstreak@1
|
1094 end
|
flickerstreak@1
|
1095 local current = self.class
|
flickerstreak@1
|
1096 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1097 if current.mixins then
|
flickerstreak@1
|
1098 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1099 if type(mixin.OnEmbedProfileEnable) == "function" then
|
flickerstreak@1
|
1100 safecall(mixin.OnEmbedProfileEnable, mixin, self, oldName, oldProfileData)
|
flickerstreak@1
|
1101 end
|
flickerstreak@1
|
1102 end
|
flickerstreak@1
|
1103 end
|
flickerstreak@1
|
1104 current = current.super
|
flickerstreak@1
|
1105 end
|
flickerstreak@1
|
1106 if type(self.OnProfileEnable) == "function" then
|
flickerstreak@1
|
1107 safecall(self.OnProfileEnable, self, oldName, oldProfileData)
|
flickerstreak@1
|
1108 end
|
flickerstreak@1
|
1109 if cleanDefaults(oldProfileData, db.defaults and db.defaults.profile) then
|
flickerstreak@1
|
1110 db.raw.profiles[oldName] = nil
|
flickerstreak@1
|
1111 if not next(db.raw.profiles) then
|
flickerstreak@1
|
1112 db.raw.profiles = nil
|
flickerstreak@1
|
1113 end
|
flickerstreak@1
|
1114 end
|
flickerstreak@1
|
1115 local newactive = self:IsActive()
|
flickerstreak@1
|
1116 if active ~= newactive then
|
flickerstreak@1
|
1117 if AceOO.inherits(self, "AceAddon-2.0") then
|
flickerstreak@1
|
1118 local AceAddon = AceLibrary("AceAddon-2.0")
|
flickerstreak@1
|
1119 if not AceAddon.addonsStarted[self] then
|
flickerstreak@1
|
1120 return
|
flickerstreak@1
|
1121 end
|
flickerstreak@1
|
1122 end
|
flickerstreak@1
|
1123 if newactive then
|
flickerstreak@1
|
1124 local current = self.class
|
flickerstreak@1
|
1125 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1126 if current.mixins then
|
flickerstreak@1
|
1127 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1128 if type(mixin.OnEmbedEnable) == "function" then
|
flickerstreak@1
|
1129 safecall(mixin.OnEmbedEnable, mixin, self)
|
flickerstreak@1
|
1130 end
|
flickerstreak@1
|
1131 end
|
flickerstreak@1
|
1132 end
|
flickerstreak@1
|
1133 current = current.super
|
flickerstreak@1
|
1134 end
|
flickerstreak@1
|
1135 if type(self.OnEnable) == "function" then
|
flickerstreak@1
|
1136 safecall(self.OnEnable, self)
|
flickerstreak@1
|
1137 end
|
flickerstreak@1
|
1138 if AceEvent then
|
flickerstreak@1
|
1139 AceEvent:TriggerEvent("Ace2_AddonEnabled", self)
|
flickerstreak@1
|
1140 end
|
flickerstreak@1
|
1141 else
|
flickerstreak@1
|
1142 local current = self.class
|
flickerstreak@1
|
1143 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1144 if current.mixins then
|
flickerstreak@1
|
1145 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1146 if type(mixin.OnEmbedDisable) == "function" then
|
flickerstreak@1
|
1147 safecall(mixin.OnEmbedDisable, mixin, self)
|
flickerstreak@1
|
1148 end
|
flickerstreak@1
|
1149 end
|
flickerstreak@1
|
1150 end
|
flickerstreak@1
|
1151 current = current.super
|
flickerstreak@1
|
1152 end
|
flickerstreak@1
|
1153 if type(self.OnDisable) == "function" then
|
flickerstreak@1
|
1154 safecall(self.OnDisable, self)
|
flickerstreak@1
|
1155 end
|
flickerstreak@1
|
1156 if AceEvent then
|
flickerstreak@1
|
1157 AceEvent:TriggerEvent("Ace2_AddonDisabled", self)
|
flickerstreak@1
|
1158 end
|
flickerstreak@1
|
1159 end
|
flickerstreak@1
|
1160 end
|
flickerstreak@1
|
1161 if self['acedb-profile-list'] then
|
flickerstreak@1
|
1162 RecalculateAceDBProfileList(self)
|
flickerstreak@1
|
1163 end
|
flickerstreak@1
|
1164 if self['acedb-profile-copylist'] then
|
flickerstreak@1
|
1165 RecalculateAceDBCopyFromList(self)
|
flickerstreak@1
|
1166 end
|
flickerstreak@1
|
1167 if Dewdrop then
|
flickerstreak@1
|
1168 Dewdrop:Refresh(1)
|
flickerstreak@1
|
1169 Dewdrop:Refresh(2)
|
flickerstreak@1
|
1170 Dewdrop:Refresh(3)
|
flickerstreak@1
|
1171 Dewdrop:Refresh(4)
|
flickerstreak@1
|
1172 Dewdrop:Refresh(5)
|
flickerstreak@1
|
1173 end
|
flickerstreak@1
|
1174 end
|
flickerstreak@1
|
1175
|
flickerstreak@1
|
1176 function AceDB:CopyProfileFrom(copyFrom)
|
flickerstreak@1
|
1177 AceDB:argCheck(copyFrom, 2, "string")
|
flickerstreak@1
|
1178 if not self.db or not self.db.raw then
|
flickerstreak@1
|
1179 AceDB:error("Cannot call \"CopyProfileFrom\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.")
|
flickerstreak@1
|
1180 end
|
flickerstreak@1
|
1181 local db = self.db
|
flickerstreak@1
|
1182 local lowerCopyFrom = string.lower(copyFrom)
|
flickerstreak@1
|
1183 if not db.raw.profiles or not db.raw.profiles[copyFrom] then
|
flickerstreak@1
|
1184 local good = false
|
flickerstreak@1
|
1185 if db.raw.namespaces then
|
flickerstreak@1
|
1186 for _,n in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
1187 if n.profiles and n.profiles[copyFrom] then
|
flickerstreak@1
|
1188 good = true
|
flickerstreak@1
|
1189 break
|
flickerstreak@1
|
1190 end
|
flickerstreak@1
|
1191 end
|
flickerstreak@1
|
1192 end
|
flickerstreak@1
|
1193 if not good then
|
flickerstreak@1
|
1194 AceDB:error("Cannot copy from profile %q, it does not exist.", copyFrom)
|
flickerstreak@1
|
1195 end
|
flickerstreak@1
|
1196 end
|
flickerstreak@1
|
1197 local currentProfile = db.raw.currentProfile[charID]
|
flickerstreak@1
|
1198 if string.lower(currentProfile) == lowerCopyFrom then
|
flickerstreak@1
|
1199 AceDB:error("Cannot copy from profile %q, it is currently in use.", copyFrom)
|
flickerstreak@1
|
1200 end
|
flickerstreak@1
|
1201 local oldProfileData = db.profile
|
flickerstreak@1
|
1202 local current = self.class
|
flickerstreak@1
|
1203 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1204 if current.mixins then
|
flickerstreak@1
|
1205 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1206 if type(mixin.OnEmbedProfileDisable) == "function" then
|
flickerstreak@1
|
1207 safecall(mixin.OnEmbedProfileDisable, mixin, self, currentProfile)
|
flickerstreak@1
|
1208 end
|
flickerstreak@1
|
1209 end
|
flickerstreak@1
|
1210 end
|
flickerstreak@1
|
1211 current = current.super
|
flickerstreak@1
|
1212 end
|
flickerstreak@1
|
1213 if type(self.OnProfileDisable) == "function" then
|
flickerstreak@1
|
1214 safecall(self.OnProfileDisable, self, realName)
|
flickerstreak@1
|
1215 end
|
flickerstreak@1
|
1216 local active = self:IsActive()
|
flickerstreak@1
|
1217 for k,v in pairs(db.profile) do
|
flickerstreak@1
|
1218 db.profile[k] = nil
|
flickerstreak@1
|
1219 end
|
flickerstreak@1
|
1220 if db.raw.profiles[copyFrom] then
|
flickerstreak@1
|
1221 copyTable(db.profile, db.raw.profiles[copyFrom])
|
flickerstreak@1
|
1222 end
|
flickerstreak@1
|
1223 inheritDefaults(db.profile, db.defaults and db.defaults.profile)
|
flickerstreak@1
|
1224 if db.namespaces then
|
flickerstreak@1
|
1225 for l,u in pairs(db.namespaces) do
|
flickerstreak@1
|
1226 for k,v in pairs(u.profile) do
|
flickerstreak@1
|
1227 u.profile[k] = nil
|
flickerstreak@1
|
1228 end
|
flickerstreak@1
|
1229 if db.raw.namespaces[l].profiles[copyFrom] then
|
flickerstreak@1
|
1230 copyTable(u.profile, db.raw.namespaces[l].profiles[copyFrom])
|
flickerstreak@1
|
1231 end
|
flickerstreak@1
|
1232 inheritDefaults(u.profile, u.defaults and u.defaults.profile)
|
flickerstreak@1
|
1233 end
|
flickerstreak@1
|
1234 end
|
flickerstreak@1
|
1235 local current = self.class
|
flickerstreak@1
|
1236 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1237 if current.mixins then
|
flickerstreak@1
|
1238 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1239 if type(mixin.OnEmbedProfileEnable) == "function" then
|
flickerstreak@1
|
1240 safecall(mixin.OnEmbedProfileEnable, mixin, self, copyFrom, oldProfileData, copyFrom)
|
flickerstreak@1
|
1241 end
|
flickerstreak@1
|
1242 end
|
flickerstreak@1
|
1243 end
|
flickerstreak@1
|
1244 current = current.super
|
flickerstreak@1
|
1245 end
|
flickerstreak@1
|
1246 if type(self.OnProfileEnable) == "function" then
|
flickerstreak@1
|
1247 safecall(self.OnProfileEnable, self, copyFrom, oldProfileData, copyFrom)
|
flickerstreak@1
|
1248 end
|
flickerstreak@1
|
1249 local newactive = self:IsActive()
|
flickerstreak@1
|
1250 if active ~= newactive then
|
flickerstreak@1
|
1251 if AceOO.inherits(self, "AceAddon-2.0") then
|
flickerstreak@1
|
1252 local AceAddon = AceLibrary("AceAddon-2.0")
|
flickerstreak@1
|
1253 if not AceAddon.addonsStarted[self] then
|
flickerstreak@1
|
1254 return
|
flickerstreak@1
|
1255 end
|
flickerstreak@1
|
1256 end
|
flickerstreak@1
|
1257 if newactive then
|
flickerstreak@1
|
1258 local current = self.class
|
flickerstreak@1
|
1259 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1260 if current.mixins then
|
flickerstreak@1
|
1261 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1262 if type(mixin.OnEmbedEnable) == "function" then
|
flickerstreak@1
|
1263 safecall(mixin.OnEmbedEnable, mixin, self)
|
flickerstreak@1
|
1264 end
|
flickerstreak@1
|
1265 end
|
flickerstreak@1
|
1266 end
|
flickerstreak@1
|
1267 current = current.super
|
flickerstreak@1
|
1268 end
|
flickerstreak@1
|
1269 if type(self.OnEnable) == "function" then
|
flickerstreak@1
|
1270 safecall(self.OnEnable, self)
|
flickerstreak@1
|
1271 end
|
flickerstreak@1
|
1272 if AceEvent then
|
flickerstreak@1
|
1273 AceEvent:TriggerEvent("Ace2_AddonEnabled", self)
|
flickerstreak@1
|
1274 end
|
flickerstreak@1
|
1275 else
|
flickerstreak@1
|
1276 local current = self.class
|
flickerstreak@1
|
1277 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1278 if current.mixins then
|
flickerstreak@1
|
1279 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1280 if type(mixin.OnEmbedDisable) == "function" then
|
flickerstreak@1
|
1281 safecall(mixin.OnEmbedDisable, mixin, self)
|
flickerstreak@1
|
1282 end
|
flickerstreak@1
|
1283 end
|
flickerstreak@1
|
1284 end
|
flickerstreak@1
|
1285 current = current.super
|
flickerstreak@1
|
1286 end
|
flickerstreak@1
|
1287 if type(self.OnDisable) == "function" then
|
flickerstreak@1
|
1288 safecall(self.OnDisable, self)
|
flickerstreak@1
|
1289 end
|
flickerstreak@1
|
1290 if AceEvent then
|
flickerstreak@1
|
1291 AceEvent:TriggerEvent("Ace2_AddonDisabled", self)
|
flickerstreak@1
|
1292 end
|
flickerstreak@1
|
1293 end
|
flickerstreak@1
|
1294 end
|
flickerstreak@1
|
1295 if self['acedb-profile-list'] then
|
flickerstreak@1
|
1296 RecalculateAceDBProfileList(self)
|
flickerstreak@1
|
1297 end
|
flickerstreak@1
|
1298 if self['acedb-profile-copylist'] then
|
flickerstreak@1
|
1299 RecalculateAceDBCopyFromList(self)
|
flickerstreak@1
|
1300 end
|
flickerstreak@1
|
1301 if Dewdrop then
|
flickerstreak@1
|
1302 Dewdrop:Refresh(1)
|
flickerstreak@1
|
1303 Dewdrop:Refresh(2)
|
flickerstreak@1
|
1304 Dewdrop:Refresh(3)
|
flickerstreak@1
|
1305 Dewdrop:Refresh(4)
|
flickerstreak@1
|
1306 Dewdrop:Refresh(5)
|
flickerstreak@1
|
1307 end
|
flickerstreak@1
|
1308 end
|
flickerstreak@1
|
1309
|
flickerstreak@1
|
1310 function AceDB:IsActive()
|
flickerstreak@1
|
1311 return not self.db or not self.db.raw or not self.db.raw.disabled or not self.db.raw.disabled[self.db.raw.currentProfile[charID]]
|
flickerstreak@1
|
1312 end
|
flickerstreak@1
|
1313
|
flickerstreak@1
|
1314 function AceDB:ToggleActive(state)
|
flickerstreak@1
|
1315 AceDB:argCheck(state, 2, "boolean", "nil")
|
flickerstreak@1
|
1316 if not self.db or not self.db.raw then
|
flickerstreak@1
|
1317 AceDB:error("Cannot call \"ToggleActive\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.")
|
flickerstreak@1
|
1318 end
|
flickerstreak@1
|
1319 local db = self.db
|
flickerstreak@1
|
1320 if not db.raw.disabled then
|
flickerstreak@1
|
1321 db.raw.disabled = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
1322 end
|
flickerstreak@1
|
1323 local profile = db.raw.currentProfile[charID]
|
flickerstreak@1
|
1324 local disable
|
flickerstreak@1
|
1325 if state == nil then
|
flickerstreak@1
|
1326 disable = not db.raw.disabled[profile]
|
flickerstreak@1
|
1327 else
|
flickerstreak@1
|
1328 disable = not state
|
flickerstreak@1
|
1329 if disable == db.raw.disabled[profile] then
|
flickerstreak@1
|
1330 return
|
flickerstreak@1
|
1331 end
|
flickerstreak@1
|
1332 end
|
flickerstreak@1
|
1333 db.raw.disabled[profile] = disable or nil
|
flickerstreak@1
|
1334 if AceOO.inherits(self, "AceAddon-2.0") then
|
flickerstreak@1
|
1335 local AceAddon = AceLibrary("AceAddon-2.0")
|
flickerstreak@1
|
1336 if not AceAddon.addonsStarted[self] then
|
flickerstreak@1
|
1337 return
|
flickerstreak@1
|
1338 end
|
flickerstreak@1
|
1339 end
|
flickerstreak@1
|
1340 if not disable then
|
flickerstreak@1
|
1341 local current = self.class
|
flickerstreak@1
|
1342 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1343 if current.mixins then
|
flickerstreak@1
|
1344 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1345 if type(mixin.OnEmbedEnable) == "function" then
|
flickerstreak@1
|
1346 safecall(mixin.OnEmbedEnable, mixin, self)
|
flickerstreak@1
|
1347 end
|
flickerstreak@1
|
1348 end
|
flickerstreak@1
|
1349 end
|
flickerstreak@1
|
1350 current = current.super
|
flickerstreak@1
|
1351 end
|
flickerstreak@1
|
1352 if type(self.OnEnable) == "function" then
|
flickerstreak@1
|
1353 safecall(self.OnEnable, self)
|
flickerstreak@1
|
1354 end
|
flickerstreak@1
|
1355 if AceEvent then
|
flickerstreak@1
|
1356 AceEvent:TriggerEvent("Ace2_AddonEnabled", self)
|
flickerstreak@1
|
1357 end
|
flickerstreak@1
|
1358 else
|
flickerstreak@1
|
1359 local current = self.class
|
flickerstreak@1
|
1360 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1361 if current.mixins then
|
flickerstreak@1
|
1362 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1363 if type(mixin.OnEmbedDisable) == "function" then
|
flickerstreak@1
|
1364 safecall(mixin.OnEmbedDisable, mixin, self)
|
flickerstreak@1
|
1365 end
|
flickerstreak@1
|
1366 end
|
flickerstreak@1
|
1367 end
|
flickerstreak@1
|
1368 current = current.super
|
flickerstreak@1
|
1369 end
|
flickerstreak@1
|
1370 if type(self.OnDisable) == "function" then
|
flickerstreak@1
|
1371 safecall(self.OnDisable, self)
|
flickerstreak@1
|
1372 end
|
flickerstreak@1
|
1373 if AceEvent then
|
flickerstreak@1
|
1374 AceEvent:TriggerEvent("Ace2_AddonDisabled", self)
|
flickerstreak@1
|
1375 end
|
flickerstreak@1
|
1376 end
|
flickerstreak@1
|
1377 return not disable
|
flickerstreak@1
|
1378 end
|
flickerstreak@1
|
1379
|
flickerstreak@1
|
1380 function AceDB:embed(target)
|
flickerstreak@1
|
1381 self.super.embed(self, target)
|
flickerstreak@1
|
1382 if not AceEvent then
|
flickerstreak@1
|
1383 AceDB:error(MAJOR_VERSION .. " requires AceEvent-2.0")
|
flickerstreak@1
|
1384 end
|
flickerstreak@1
|
1385 end
|
flickerstreak@1
|
1386
|
flickerstreak@1
|
1387 function AceDB:ADDON_LOADED(name)
|
flickerstreak@1
|
1388 AceDB.addonsLoaded[name] = true
|
flickerstreak@1
|
1389 for addon, addonName in pairs(AceDB.addonsToBeInitialized) do
|
flickerstreak@1
|
1390 if name == addonName then
|
flickerstreak@1
|
1391 AceDB.InitializeDB(addon, name)
|
flickerstreak@1
|
1392 AceDB.addonsToBeInitialized[addon] = nil
|
flickerstreak@1
|
1393 end
|
flickerstreak@1
|
1394 end
|
flickerstreak@1
|
1395 end
|
flickerstreak@1
|
1396
|
flickerstreak@1
|
1397 function AceDB:PLAYER_LOGOUT()
|
flickerstreak@1
|
1398 for addon in pairs(AceDB.registry) do
|
flickerstreak@1
|
1399 local db = addon.db
|
flickerstreak@1
|
1400 if db then
|
flickerstreak@1
|
1401 setmetatable(db, nil)
|
flickerstreak@1
|
1402 CrawlForSerialization(db.raw)
|
flickerstreak@1
|
1403 if type(_G[db.charName]) == "table" then
|
flickerstreak@1
|
1404 CrawlForSerialization(_G[db.charName])
|
flickerstreak@1
|
1405 end
|
flickerstreak@1
|
1406 if db.char and cleanDefaults(db.char, db.defaults and db.defaults.char) then
|
flickerstreak@1
|
1407 if db.charName and _G[db.charName] and _G[db.charName].global == db.char then
|
flickerstreak@1
|
1408 _G[db.charName].global = nil
|
flickerstreak@1
|
1409 if not next(_G[db.charName]) then
|
flickerstreak@1
|
1410 _G[db.charName] = nil
|
flickerstreak@1
|
1411 end
|
flickerstreak@1
|
1412 else
|
flickerstreak@1
|
1413 if db.raw.chars then
|
flickerstreak@1
|
1414 db.raw.chars[charID] = nil
|
flickerstreak@1
|
1415 if not next(db.raw.chars) then
|
flickerstreak@1
|
1416 db.raw.chars = nil
|
flickerstreak@1
|
1417 end
|
flickerstreak@1
|
1418 end
|
flickerstreak@1
|
1419 end
|
flickerstreak@1
|
1420 end
|
flickerstreak@1
|
1421 if db.realm and cleanDefaults(db.realm, db.defaults and db.defaults.realm) then
|
flickerstreak@1
|
1422 if db.raw.realms then
|
flickerstreak@1
|
1423 db.raw.realms[realmID] = nil
|
flickerstreak@1
|
1424 if not next(db.raw.realms) then
|
flickerstreak@1
|
1425 db.raw.realms = nil
|
flickerstreak@1
|
1426 end
|
flickerstreak@1
|
1427 end
|
flickerstreak@1
|
1428 end
|
flickerstreak@1
|
1429 if db.faction and cleanDefaults(db.faction, db.defaults and db.defaults.faction) then
|
flickerstreak@1
|
1430 if db.raw.factions then
|
flickerstreak@1
|
1431 db.raw.factions[faction] = nil
|
flickerstreak@1
|
1432 if not next(db.raw.factions) then
|
flickerstreak@1
|
1433 db.raw.factions = nil
|
flickerstreak@1
|
1434 end
|
flickerstreak@1
|
1435 end
|
flickerstreak@1
|
1436 end
|
flickerstreak@1
|
1437 if db.class and cleanDefaults(db.class, db.defaults and db.defaults.class) then
|
flickerstreak@1
|
1438 if db.raw.classes then
|
flickerstreak@1
|
1439 db.raw.classes[classID] = nil
|
flickerstreak@1
|
1440 if not next(db.raw.classes) then
|
flickerstreak@1
|
1441 db.raw.classes = nil
|
flickerstreak@1
|
1442 end
|
flickerstreak@1
|
1443 end
|
flickerstreak@1
|
1444 end
|
flickerstreak@1
|
1445 if db.account and cleanDefaults(db.account, db.defaults and db.defaults.account) then
|
flickerstreak@1
|
1446 db.raw.account = nil
|
flickerstreak@1
|
1447 end
|
flickerstreak@1
|
1448 if db.profile and cleanDefaults(db.profile, db.defaults and db.defaults.profile) then
|
flickerstreak@1
|
1449 if db.raw.profiles then
|
flickerstreak@1
|
1450 db.raw.profiles[db.raw.currentProfile and db.raw.currentProfile[charID] or "Default"] = nil
|
flickerstreak@1
|
1451 if not next(db.raw.profiles) then
|
flickerstreak@1
|
1452 db.raw.profiles = nil
|
flickerstreak@1
|
1453 end
|
flickerstreak@1
|
1454 end
|
flickerstreak@1
|
1455 end
|
flickerstreak@1
|
1456 if db.namespaces and db.raw.namespaces then
|
flickerstreak@1
|
1457 for name,v in pairs(db.namespaces) do
|
flickerstreak@1
|
1458 if db.raw.namespaces[name] then
|
flickerstreak@1
|
1459 setmetatable(v, nil)
|
flickerstreak@1
|
1460 if v.char and cleanDefaults(v.char, v.defaults and v.defaults.char) then
|
flickerstreak@1
|
1461 if db.charName and _G[db.charName] and _G[db.charName].namespaces and _G[db.charName].namespaces[name] == v then
|
flickerstreak@1
|
1462 _G[db.charName].namespaces[name] = nil
|
flickerstreak@1
|
1463 if not next(_G[db.charName].namespaces) then
|
flickerstreak@1
|
1464 _G[db.charName].namespaces = nil
|
flickerstreak@1
|
1465 if not next(_G[db.charName]) then
|
flickerstreak@1
|
1466 _G[db.charName] = nil
|
flickerstreak@1
|
1467 end
|
flickerstreak@1
|
1468 end
|
flickerstreak@1
|
1469 else
|
flickerstreak@1
|
1470 if db.raw.namespaces[name].chars then
|
flickerstreak@1
|
1471 db.raw.namespaces[name].chars[charID] = nil
|
flickerstreak@1
|
1472 if not next(db.raw.namespaces[name].chars) then
|
flickerstreak@1
|
1473 db.raw.namespaces[name].chars = nil
|
flickerstreak@1
|
1474 end
|
flickerstreak@1
|
1475 end
|
flickerstreak@1
|
1476 end
|
flickerstreak@1
|
1477 end
|
flickerstreak@1
|
1478 if v.realm and cleanDefaults(v.realm, v.defaults and v.defaults.realm) then
|
flickerstreak@1
|
1479 if db.raw.namespaces[name].realms then
|
flickerstreak@1
|
1480 db.raw.namespaces[name].realms[realmID] = nil
|
flickerstreak@1
|
1481 if not next(db.raw.namespaces[name].realms) then
|
flickerstreak@1
|
1482 db.raw.namespaces[name].realms = nil
|
flickerstreak@1
|
1483 end
|
flickerstreak@1
|
1484 end
|
flickerstreak@1
|
1485 end
|
flickerstreak@1
|
1486 if v.faction and cleanDefaults(v.faction, v.defaults and v.defaults.faction) then
|
flickerstreak@1
|
1487 if db.raw.namespaces[name].factions then
|
flickerstreak@1
|
1488 db.raw.namespaces[name].factions[faction] = nil
|
flickerstreak@1
|
1489 if not next(db.raw.namespaces[name].factions) then
|
flickerstreak@1
|
1490 db.raw.namespaces[name].factions = nil
|
flickerstreak@1
|
1491 end
|
flickerstreak@1
|
1492 end
|
flickerstreak@1
|
1493 end
|
flickerstreak@1
|
1494 if v.class and cleanDefaults(v.class, v.defaults and v.defaults.class) then
|
flickerstreak@1
|
1495 if db.raw.namespaces[name].classes then
|
flickerstreak@1
|
1496 db.raw.namespaces[name].classes[classID] = nil
|
flickerstreak@1
|
1497 if not next(db.raw.namespaces[name].classes) then
|
flickerstreak@1
|
1498 db.raw.namespaces[name].classes = nil
|
flickerstreak@1
|
1499 end
|
flickerstreak@1
|
1500 end
|
flickerstreak@1
|
1501 end
|
flickerstreak@1
|
1502 if v.account and cleanDefaults(v.account, v.defaults and v.defaults.account) then
|
flickerstreak@1
|
1503 db.raw.namespaces[name].account = nil
|
flickerstreak@1
|
1504 end
|
flickerstreak@1
|
1505 if v.profile and cleanDefaults(v.profile, v.defaults and v.defaults.profile) then
|
flickerstreak@1
|
1506 if db.raw.namespaces[name].profiles then
|
flickerstreak@1
|
1507 db.raw.namespaces[name].profiles[db.raw.currentProfile and db.raw.currentProfile[charID] or "Default"] = nil
|
flickerstreak@1
|
1508 if not next(db.raw.namespaces[name].profiles) then
|
flickerstreak@1
|
1509 db.raw.namespaces[name].profiles = nil
|
flickerstreak@1
|
1510 end
|
flickerstreak@1
|
1511 end
|
flickerstreak@1
|
1512 end
|
flickerstreak@1
|
1513 if not next(db.raw.namespaces[name]) then
|
flickerstreak@1
|
1514 db.raw.namespaces[name] = nil
|
flickerstreak@1
|
1515 end
|
flickerstreak@1
|
1516 end
|
flickerstreak@1
|
1517 end
|
flickerstreak@1
|
1518 if not next(db.raw.namespaces) then
|
flickerstreak@1
|
1519 db.raw.namespaces = nil
|
flickerstreak@1
|
1520 end
|
flickerstreak@1
|
1521 end
|
flickerstreak@1
|
1522 if db.raw.disabled and not next(db.raw.disabled) then
|
flickerstreak@1
|
1523 db.raw.disabled = nil
|
flickerstreak@1
|
1524 end
|
flickerstreak@1
|
1525 if db.raw.currentProfile then
|
flickerstreak@1
|
1526 for k,v in pairs(db.raw.currentProfile) do
|
flickerstreak@1
|
1527 if string.lower(v) == "default" then
|
flickerstreak@1
|
1528 db.raw.currentProfile[k] = nil
|
flickerstreak@1
|
1529 end
|
flickerstreak@1
|
1530 end
|
flickerstreak@1
|
1531 if not next(db.raw.currentProfile) then
|
flickerstreak@1
|
1532 db.raw.currentProfile = nil
|
flickerstreak@1
|
1533 end
|
flickerstreak@1
|
1534 end
|
flickerstreak@1
|
1535 if _G[db.name] and not next(_G[db.name]) then
|
flickerstreak@1
|
1536 _G[db.name] = nil
|
flickerstreak@1
|
1537 end
|
flickerstreak@1
|
1538 end
|
flickerstreak@1
|
1539 end
|
flickerstreak@1
|
1540 end
|
flickerstreak@1
|
1541
|
flickerstreak@1
|
1542 function AceDB:AcquireDBNamespace(name)
|
flickerstreak@1
|
1543 AceDB:argCheck(name, 2, "string")
|
flickerstreak@1
|
1544 local db = self.db
|
flickerstreak@1
|
1545 if not db then
|
flickerstreak@1
|
1546 AceDB:error("Cannot call `AcquireDBNamespace' before `RegisterDB' has been called.", 2)
|
flickerstreak@1
|
1547 end
|
flickerstreak@1
|
1548 if not db.namespaces then
|
flickerstreak@1
|
1549 rawset(db, 'namespaces', {})
|
flickerstreak@1
|
1550 end
|
flickerstreak@1
|
1551 if not db.namespaces[name] then
|
flickerstreak@1
|
1552 local namespace = {}
|
flickerstreak@1
|
1553 db.namespaces[name] = namespace
|
flickerstreak@1
|
1554 namespace.db = db
|
flickerstreak@1
|
1555 namespace.name = name
|
flickerstreak@1
|
1556 setmetatable(namespace, namespace_mt)
|
flickerstreak@1
|
1557 end
|
flickerstreak@1
|
1558 return db.namespaces[name]
|
flickerstreak@1
|
1559 end
|
flickerstreak@1
|
1560
|
flickerstreak@1
|
1561 function AceDB:GetAceOptionsDataTable(target)
|
flickerstreak@1
|
1562 if not target['acedb-profile-list'] then
|
flickerstreak@1
|
1563 target['acedb-profile-list'] = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
1564 RecalculateAceDBProfileList(target)
|
flickerstreak@1
|
1565 end
|
flickerstreak@1
|
1566 if not target['acedb-profile-copylist'] then
|
flickerstreak@1
|
1567 target['acedb-profile-copylist'] = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
1568 RecalculateAceDBCopyFromList(target)
|
flickerstreak@1
|
1569 end
|
flickerstreak@1
|
1570 return {
|
flickerstreak@1
|
1571 standby = {
|
flickerstreak@1
|
1572 cmdName = STATE,
|
flickerstreak@1
|
1573 guiName = ENABLED,
|
flickerstreak@1
|
1574 name = ACTIVE,
|
flickerstreak@1
|
1575 desc = TOGGLE_ACTIVE,
|
flickerstreak@1
|
1576 type = "toggle",
|
flickerstreak@1
|
1577 get = "IsActive",
|
flickerstreak@1
|
1578 set = "ToggleActive",
|
flickerstreak@1
|
1579 map = MAP_ACTIVESUSPENDED,
|
flickerstreak@1
|
1580 order = -3,
|
flickerstreak@1
|
1581 },
|
flickerstreak@1
|
1582 profile = {
|
flickerstreak@1
|
1583 type = 'group',
|
flickerstreak@1
|
1584 name = PROFILE,
|
flickerstreak@1
|
1585 desc = SET_PROFILE,
|
flickerstreak@1
|
1586 order = -3.5,
|
flickerstreak@1
|
1587 get = "GetProfile",
|
flickerstreak@1
|
1588 args = {
|
flickerstreak@1
|
1589 choose = {
|
flickerstreak@1
|
1590 guiName = CHOOSE_PROFILE_GUI,
|
flickerstreak@1
|
1591 cmdName = PROFILE,
|
flickerstreak@1
|
1592 desc = CHOOSE_PROFILE_DESC,
|
flickerstreak@1
|
1593 type = 'text',
|
flickerstreak@1
|
1594 get = "GetProfile",
|
flickerstreak@1
|
1595 set = "SetProfile",
|
flickerstreak@1
|
1596 validate = target['acedb-profile-list']
|
flickerstreak@1
|
1597 },
|
flickerstreak@1
|
1598 copy = {
|
flickerstreak@1
|
1599 guiName = COPY_PROFILE_GUI,
|
flickerstreak@1
|
1600 cmdName = PROFILE,
|
flickerstreak@1
|
1601 desc = COPY_PROFILE_DESC,
|
flickerstreak@1
|
1602 type = 'text',
|
flickerstreak@1
|
1603 get = false,
|
flickerstreak@1
|
1604 set = "CopyProfileFrom",
|
flickerstreak@1
|
1605 validate = target['acedb-profile-copylist'],
|
flickerstreak@1
|
1606 disabled = function()
|
flickerstreak@1
|
1607 return not next(target['acedb-profile-copylist'])
|
flickerstreak@1
|
1608 end,
|
flickerstreak@1
|
1609 },
|
flickerstreak@1
|
1610 other = {
|
flickerstreak@1
|
1611 guiName = OTHER_PROFILE_GUI,
|
flickerstreak@1
|
1612 cmdName = PROFILE,
|
flickerstreak@1
|
1613 desc = OTHER_PROFILE_DESC,
|
flickerstreak@1
|
1614 usage = OTHER_PROFILE_USAGE,
|
flickerstreak@1
|
1615 type = 'text',
|
flickerstreak@1
|
1616 get = "GetProfile",
|
flickerstreak@1
|
1617 set = "SetProfile",
|
flickerstreak@1
|
1618 }
|
flickerstreak@1
|
1619 }
|
flickerstreak@1
|
1620 },
|
flickerstreak@1
|
1621 }
|
flickerstreak@1
|
1622 end
|
flickerstreak@1
|
1623
|
flickerstreak@1
|
1624 local function activate(self, oldLib, oldDeactivate)
|
flickerstreak@1
|
1625 AceDB = self
|
flickerstreak@1
|
1626 AceEvent = AceLibrary:HasInstance("AceEvent-2.0") and AceLibrary("AceEvent-2.0")
|
flickerstreak@1
|
1627
|
flickerstreak@1
|
1628 self.addonsToBeInitialized = oldLib and oldLib.addonsToBeInitialized or {}
|
flickerstreak@1
|
1629 self.addonsLoaded = oldLib and oldLib.addonsLoaded or {}
|
flickerstreak@1
|
1630 self.registry = oldLib and oldLib.registry or {}
|
flickerstreak@1
|
1631
|
flickerstreak@1
|
1632 self:activate(oldLib, oldDeactivate)
|
flickerstreak@1
|
1633
|
flickerstreak@1
|
1634 for t in pairs(self.embedList) do
|
flickerstreak@1
|
1635 if t.db then
|
flickerstreak@1
|
1636 rawset(t.db, 'char', nil)
|
flickerstreak@1
|
1637 rawset(t.db, 'realm', nil)
|
flickerstreak@1
|
1638 rawset(t.db, 'class', nil)
|
flickerstreak@1
|
1639 rawset(t.db, 'account', nil)
|
flickerstreak@1
|
1640 rawset(t.db, 'faction', nil)
|
flickerstreak@1
|
1641 rawset(t.db, 'profile', nil)
|
flickerstreak@1
|
1642 setmetatable(t.db, db_mt)
|
flickerstreak@1
|
1643 end
|
flickerstreak@1
|
1644 end
|
flickerstreak@1
|
1645
|
flickerstreak@1
|
1646 if oldLib then
|
flickerstreak@1
|
1647 oldDeactivate(oldLib)
|
flickerstreak@1
|
1648 end
|
flickerstreak@1
|
1649 end
|
flickerstreak@1
|
1650
|
flickerstreak@1
|
1651 local function external(self, major, instance)
|
flickerstreak@1
|
1652 if major == "AceEvent-2.0" then
|
flickerstreak@1
|
1653 AceEvent = instance
|
flickerstreak@1
|
1654
|
flickerstreak@1
|
1655 AceEvent:embed(self)
|
flickerstreak@1
|
1656
|
flickerstreak@1
|
1657 self:RegisterEvent("ADDON_LOADED")
|
flickerstreak@1
|
1658 self:RegisterEvent("PLAYER_LOGOUT")
|
flickerstreak@1
|
1659 elseif major == "Dewdrop-2.0" then
|
flickerstreak@1
|
1660 Dewdrop = instance
|
flickerstreak@1
|
1661 end
|
flickerstreak@1
|
1662 end
|
flickerstreak@1
|
1663
|
flickerstreak@1
|
1664 AceLibrary:Register(AceDB, MAJOR_VERSION, MINOR_VERSION, activate, nil, external)
|
flickerstreak@1
|
1665 AceDB = AceLibrary(MAJOR_VERSION)
|