flickerstreak@22
|
1 --[[
|
flickerstreak@1
|
2 Name: AceDB-2.0
|
flickerstreak@22
|
3 Revision: $Rev: 46764 $
|
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@22
|
12 License: LGPL v2.1
|
flickerstreak@1
|
13 ]]
|
flickerstreak@1
|
14
|
flickerstreak@1
|
15 local MAJOR_VERSION = "AceDB-2.0"
|
flickerstreak@22
|
16 local MINOR_VERSION = "$Revision: 46764 $"
|
flickerstreak@1
|
17
|
flickerstreak@1
|
18 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
|
flickerstreak@1
|
19 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
|
flickerstreak@1
|
20
|
flickerstreak@1
|
21 if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end
|
flickerstreak@1
|
22
|
flickerstreak@1
|
23 local function safecall(func,...)
|
flickerstreak@1
|
24 local success, err = pcall(func,...)
|
flickerstreak@1
|
25 if not success then geterrorhandler()(err) end
|
flickerstreak@1
|
26 end
|
flickerstreak@1
|
27
|
flickerstreak@22
|
28 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, RESET_PROFILE, RESET_PROFILE_DESC, CHARACTER_COLON, REALM_COLON, CLASS_COLON, DEFAULT, ALTERNATIVE
|
flickerstreak@22
|
29
|
flickerstreak@22
|
30 -- Move these into "enUS" when they've been translated in all other locales
|
flickerstreak@22
|
31 local DELETE_PROFILE = "Delete"
|
flickerstreak@22
|
32 local DELETE_PROFILE_DESC = "Deletes a profile. Note that no check is made whether this profile is in use by other characters or not."
|
flickerstreak@22
|
33 local DELETE_PROFILE_USAGE = "<profile name>"
|
flickerstreak@1
|
34
|
flickerstreak@1
|
35 if GetLocale() == "deDE" then
|
flickerstreak@1
|
36 ACTIVE = "Aktiv"
|
flickerstreak@1
|
37 ENABLED = "Aktiviert"
|
flickerstreak@1
|
38 STATE = "Status"
|
flickerstreak@1
|
39 TOGGLE_ACTIVE = "Stoppt/Aktiviert dieses Addon."
|
flickerstreak@1
|
40 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Aktiv|r", [false] = "|cffff0000Gestoppt|r" }
|
flickerstreak@1
|
41 SET_PROFILE = "Setzt das Profil f\195\188r dieses Addon."
|
flickerstreak@1
|
42 SET_PROFILE_USAGE = "{Charakter || Klasse || Realm || <Profilname>}"
|
flickerstreak@1
|
43 PROFILE = "Profil"
|
flickerstreak@1
|
44 PLAYER_OF_REALM = "%s von %s"
|
flickerstreak@1
|
45 CHOOSE_PROFILE_DESC = "W\195\164hle ein Profil."
|
flickerstreak@1
|
46 CHOOSE_PROFILE_GUI = "W\195\164hle"
|
flickerstreak@1
|
47 COPY_PROFILE_DESC = "Kopiert Einstellungen von einem anderem Profil."
|
flickerstreak@1
|
48 COPY_PROFILE_GUI = "Kopiere von"
|
flickerstreak@1
|
49 OTHER_PROFILE_DESC = "W\195\164hle ein anderes Profil."
|
flickerstreak@1
|
50 OTHER_PROFILE_GUI = "Anderes"
|
flickerstreak@1
|
51 OTHER_PROFILE_USAGE = "<Profilname>"
|
flickerstreak@22
|
52 RESET_PROFILE = "Reset profile" -- fix
|
flickerstreak@22
|
53 RESET_PROFILE_DESC = "Clear all settings of the current profile." -- fix
|
flickerstreak@1
|
54
|
flickerstreak@1
|
55 CHARACTER_COLON = "Charakter: "
|
flickerstreak@1
|
56 REALM_COLON = "Realm: "
|
flickerstreak@1
|
57 CLASS_COLON = "Klasse: "
|
flickerstreak@22
|
58
|
flickerstreak@1
|
59 DEFAULT = "Default" -- fix
|
flickerstreak@1
|
60 ALTERNATIVE = "Alternative" -- fix
|
flickerstreak@1
|
61 elseif GetLocale() == "frFR" then
|
flickerstreak@1
|
62 ACTIVE = "Actif"
|
flickerstreak@1
|
63 ENABLED = "Activ\195\169"
|
flickerstreak@1
|
64 STATE = "Etat"
|
flickerstreak@1
|
65 TOGGLE_ACTIVE = "Suspend/active cet addon."
|
flickerstreak@1
|
66 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Actif|r", [false] = "|cffff0000Suspendu|r" }
|
flickerstreak@1
|
67 SET_PROFILE = "S\195\169lectionne le profil pour cet addon."
|
flickerstreak@1
|
68 SET_PROFILE_USAGE = "{perso || classe || royaume || <nom de profil>}"
|
flickerstreak@1
|
69 PROFILE = "Profil"
|
flickerstreak@1
|
70 PLAYER_OF_REALM = "%s de %s"
|
flickerstreak@1
|
71 CHOOSE_PROFILE_DESC = "Choisissez un profil."
|
flickerstreak@1
|
72 CHOOSE_PROFILE_GUI = "Choix"
|
flickerstreak@1
|
73 COPY_PROFILE_DESC = "Copier les param\195\168tres d'un autre profil."
|
flickerstreak@1
|
74 COPY_PROFILE_GUI = "Copier \195\160 partir de"
|
flickerstreak@1
|
75 OTHER_PROFILE_DESC = "Choisissez un autre profil."
|
flickerstreak@1
|
76 OTHER_PROFILE_GUI = "Autre"
|
flickerstreak@1
|
77 OTHER_PROFILE_USAGE = "<nom de profil>"
|
flickerstreak@22
|
78 RESET_PROFILE = "Reset profile" -- fix
|
flickerstreak@22
|
79 RESET_PROFILE_DESC = "Clear all settings of the current profile." -- fix
|
flickerstreak@1
|
80
|
flickerstreak@1
|
81 CHARACTER_COLON = "Personnage: "
|
flickerstreak@1
|
82 REALM_COLON = "Royaume: "
|
flickerstreak@1
|
83 CLASS_COLON = "Classe: "
|
flickerstreak@22
|
84
|
flickerstreak@1
|
85 DEFAULT = "Default" -- fix
|
flickerstreak@1
|
86 ALTERNATIVE = "Alternative" -- fix
|
flickerstreak@1
|
87 elseif GetLocale() == "koKR" then
|
flickerstreak@22
|
88 DELETE_PROFILE = "삭제"
|
flickerstreak@22
|
89 DELETE_PROFILE_DESC = "프로필을 삭제합니다."
|
flickerstreak@22
|
90 DELETE_PROFILE_USAGE = "<프로필명>"
|
flickerstreak@22
|
91
|
flickerstreak@22
|
92 ACTIVE = "사용"
|
flickerstreak@22
|
93 ENABLED = "사용"
|
flickerstreak@1
|
94 STATE = "상태"
|
flickerstreak@22
|
95 TOGGLE_ACTIVE = "이 애드온 중지/다시 시작"
|
flickerstreak@22
|
96 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00사용|r", [false] = "|cffff0000중지|r" }
|
flickerstreak@1
|
97 SET_PROFILE = "이 애드온에 프로필 설정"
|
flickerstreak@1
|
98 SET_PROFILE_USAGE = "{캐릭터명 || 직업 || 서버명 || <프로필명>}"
|
flickerstreak@1
|
99 PROFILE = "프로필"
|
flickerstreak@1
|
100 PLAYER_OF_REALM = "%s (%s 서버)"
|
flickerstreak@22
|
101 CHOOSE_PROFILE_DESC = "프로필을 선택합니다."
|
flickerstreak@1
|
102 CHOOSE_PROFILE_GUI = "선택"
|
flickerstreak@22
|
103 COPY_PROFILE_DESC = "다른 프로필 설정을 복사합니다."
|
flickerstreak@1
|
104 COPY_PROFILE_GUI = "복사"
|
flickerstreak@22
|
105 OTHER_PROFILE_DESC = "다른 프로필을 선택합니다."
|
flickerstreak@1
|
106 OTHER_PROFILE_GUI = "기타"
|
flickerstreak@22
|
107 OTHER_PROFILE_USAGE = "<프로필명>"
|
flickerstreak@22
|
108 RESET_PROFILE = "프로필 초기화"
|
flickerstreak@22
|
109 RESET_PROFILE_DESC = "모든 세팅에서 현재 프로필을 초기화 합니다."
|
flickerstreak@1
|
110
|
flickerstreak@1
|
111 CHARACTER_COLON = "캐릭터: "
|
flickerstreak@1
|
112 REALM_COLON = "서버: "
|
flickerstreak@1
|
113 CLASS_COLON = "직업: "
|
flickerstreak@22
|
114
|
flickerstreak@22
|
115 DEFAULT = "기본값"
|
flickerstreak@22
|
116 ALTERNATIVE = "대체"
|
flickerstreak@1
|
117 elseif GetLocale() == "zhTW" then
|
flickerstreak@22
|
118 DELETE_PROFILE = "刪除"
|
flickerstreak@22
|
119 DELETE_PROFILE_DESC = "刪除記錄檔。注意,有可能別的角色也使用這個記錄檔。"
|
flickerstreak@22
|
120 DELETE_PROFILE_USAGE = "<記錄檔名稱>"
|
flickerstreak@22
|
121
|
flickerstreak@1
|
122 ACTIVE = "啟動"
|
flickerstreak@1
|
123 ENABLED = "啟用"
|
flickerstreak@1
|
124 STATE = "狀態"
|
flickerstreak@22
|
125 TOGGLE_ACTIVE = "暫停/繼續使用這個插件。"
|
flickerstreak@1
|
126 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00啟動|r", [false] = "|cffff0000已暫停|r" }
|
flickerstreak@1
|
127 SET_PROFILE = "設定這插件的記錄檔。"
|
flickerstreak@22
|
128 SET_PROFILE_USAGE = "{角色 || 職業 || 伺服器 || <記錄檔名稱>}"
|
flickerstreak@1
|
129 PROFILE = "記錄檔"
|
flickerstreak@22
|
130 PLAYER_OF_REALM = "%s - %s"
|
flickerstreak@22
|
131 CHOOSE_PROFILE_DESC = "選擇一個記錄檔。"
|
flickerstreak@1
|
132 CHOOSE_PROFILE_GUI = "選擇"
|
flickerstreak@1
|
133 COPY_PROFILE_DESC = "由其他記錄檔複製設定。"
|
flickerstreak@22
|
134 COPY_PROFILE_GUI = "複製自"
|
flickerstreak@1
|
135 OTHER_PROFILE_DESC = "選擇其他記錄檔。"
|
flickerstreak@1
|
136 OTHER_PROFILE_GUI = "其他"
|
flickerstreak@1
|
137 OTHER_PROFILE_USAGE = "<記錄檔名稱>"
|
flickerstreak@22
|
138 RESET_PROFILE = "重設記錄檔"
|
flickerstreak@22
|
139 RESET_PROFILE_DESC = "清除目前的記錄檔上的所有設定。"
|
flickerstreak@1
|
140
|
flickerstreak@22
|
141 CHARACTER_COLON = "角色: "
|
flickerstreak@22
|
142 REALM_COLON = "伺服器: "
|
flickerstreak@22
|
143 CLASS_COLON = "職業: "
|
flickerstreak@22
|
144
|
flickerstreak@22
|
145 DEFAULT = "預設"
|
flickerstreak@22
|
146 ALTERNATIVE = "替代"
|
flickerstreak@1
|
147 elseif GetLocale() == "zhCN" then
|
flickerstreak@1
|
148 ACTIVE = "\230\156\137\230\149\136"
|
flickerstreak@1
|
149 ENABLED = "\229\144\175\231\148\168"
|
flickerstreak@1
|
150 STATE = "\231\138\182\230\128\129"
|
flickerstreak@1
|
151 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
|
152 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00\230\156\137\230\149\136|r", [false] = "|cffff0000\230\154\130\229\129\156|r" }
|
flickerstreak@1
|
153 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
|
154 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
|
155 PROFILE = "\233\133\141\231\189\174\230\150\135\228\187\182"
|
flickerstreak@1
|
156 PLAYER_OF_REALM = "%s \231\154\132 %s"
|
flickerstreak@1
|
157 CHOOSE_PROFILE_DESC = "\233\128\137\230\139\169\233\133\141\231\189\174\230\150\135\228\187\182."
|
flickerstreak@1
|
158 CHOOSE_PROFILE_GUI = "\233\128\137\230\139\169"
|
flickerstreak@1
|
159 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
|
160 COPY_PROFILE_GUI = "\229\164\141\229\136\182\228\187\142"
|
flickerstreak@1
|
161 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
|
162 OTHER_PROFILE_GUI = "\229\133\182\228\187\150"
|
flickerstreak@1
|
163 OTHER_PROFILE_USAGE = "<\233\133\141\231\189\174\230\150\135\228\187\182\229\144\141\229\173\151>"
|
flickerstreak@22
|
164 RESET_PROFILE = "Reset profile" -- fix
|
flickerstreak@22
|
165 RESET_PROFILE_DESC = "Clear all settings of the current profile." -- fix
|
flickerstreak@1
|
166
|
flickerstreak@1
|
167 CHARACTER_COLON = "\229\173\151\231\172\166: "
|
flickerstreak@1
|
168 REALM_COLON = "\229\159\159: "
|
flickerstreak@1
|
169 CLASS_COLON = "\233\128\137\228\187\182\231\177\187: "
|
flickerstreak@22
|
170
|
flickerstreak@1
|
171 DEFAULT = "Default" -- fix
|
flickerstreak@1
|
172 ALTERNATIVE = "Alternative" -- fix
|
flickerstreak@22
|
173 elseif GetLocale() == "esES" then
|
flickerstreak@22
|
174 ACTIVE = "Activo"
|
flickerstreak@22
|
175 ENABLED = "Activado"
|
flickerstreak@22
|
176 STATE = "Estado"
|
flickerstreak@22
|
177 TOGGLE_ACTIVE = "Parar/Continuar este accesorio"
|
flickerstreak@22
|
178 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Activo|r", [false] = "|cffff0000Parado|r" }
|
flickerstreak@22
|
179 SET_PROFILE = "Selecciona el perfil para este accesorio."
|
flickerstreak@22
|
180 SET_PROFILE_USAGE = "{perso || clase || reino || <nombre del perfil>}"
|
flickerstreak@22
|
181 PROFILE = "Perfil"
|
flickerstreak@22
|
182 PLAYER_OF_REALM = "%s de %s"
|
flickerstreak@22
|
183 CHOOSE_PROFILE_DESC = "Elige un perfil."
|
flickerstreak@22
|
184 CHOOSE_PROFILE_GUI = "Elige"
|
flickerstreak@22
|
185 COPY_PROFILE_DESC = "Copiar de un perfil a otro"
|
flickerstreak@22
|
186 COPY_PROFILE_GUI = "Copiar desde"
|
flickerstreak@22
|
187 OTHER_PROFILE_DESC = "Elige otro perfil."
|
flickerstreak@22
|
188 OTHER_PROFILE_GUI = "Otro"
|
flickerstreak@22
|
189 OTHER_PROFILE_USAGE = "<nombre del perfil>"
|
flickerstreak@22
|
190 RESET_PROFILE = "Reset profile" -- fix
|
flickerstreak@22
|
191 RESET_PROFILE_DESC = "Clear all settings of the current profile." -- fix
|
flickerstreak@22
|
192
|
flickerstreak@22
|
193 CHARACTER_COLON = "Personaje: "
|
flickerstreak@22
|
194 REALM_COLON = "Reino: "
|
flickerstreak@22
|
195 CLASS_COLON = "Clase: "
|
flickerstreak@22
|
196
|
flickerstreak@22
|
197 DEFAULT = "Por defecto"
|
flickerstreak@22
|
198 ALTERNATIVE = "Alternativo"
|
flickerstreak@1
|
199 else -- enUS
|
flickerstreak@1
|
200 ACTIVE = "Active"
|
flickerstreak@1
|
201 ENABLED = "Enabled"
|
flickerstreak@1
|
202 STATE = "State"
|
flickerstreak@1
|
203 TOGGLE_ACTIVE = "Suspend/resume this addon."
|
flickerstreak@1
|
204 MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Active|r", [false] = "|cffff0000Suspended|r" }
|
flickerstreak@1
|
205 SET_PROFILE = "Set profile for this addon."
|
flickerstreak@1
|
206 SET_PROFILE_USAGE = "{char || class || realm || <profile name>}"
|
flickerstreak@1
|
207 PROFILE = "Profile"
|
flickerstreak@1
|
208 PLAYER_OF_REALM = "%s of %s"
|
flickerstreak@1
|
209 CHOOSE_PROFILE_DESC = "Choose a profile."
|
flickerstreak@1
|
210 CHOOSE_PROFILE_GUI = "Choose"
|
flickerstreak@1
|
211 COPY_PROFILE_DESC = "Copy settings from another profile."
|
flickerstreak@1
|
212 COPY_PROFILE_GUI = "Copy from"
|
flickerstreak@1
|
213 OTHER_PROFILE_DESC = "Choose another profile."
|
flickerstreak@1
|
214 OTHER_PROFILE_GUI = "Other"
|
flickerstreak@1
|
215 OTHER_PROFILE_USAGE = "<profile name>"
|
flickerstreak@22
|
216 RESET_PROFILE = "Reset profile"
|
flickerstreak@22
|
217 RESET_PROFILE_DESC = "Clear all settings of the current profile."
|
flickerstreak@1
|
218
|
flickerstreak@1
|
219 CHARACTER_COLON = "Character: "
|
flickerstreak@1
|
220 REALM_COLON = "Realm: "
|
flickerstreak@1
|
221 CLASS_COLON = "Class: "
|
flickerstreak@22
|
222
|
flickerstreak@1
|
223 DEFAULT = "Default"
|
flickerstreak@1
|
224 ALTERNATIVE = "Alternative"
|
flickerstreak@1
|
225 end
|
flickerstreak@22
|
226 local convertFromOldCharID
|
flickerstreak@22
|
227 do
|
flickerstreak@22
|
228 local matchStr = "^" .. PLAYER_OF_REALM:gsub("([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1"):gsub("%%s", "(.+)") .. "$"
|
flickerstreak@22
|
229 function convertFromOldCharID(str)
|
flickerstreak@22
|
230 local player, realm = str:match(matchStr)
|
flickerstreak@22
|
231 if not player then
|
flickerstreak@22
|
232 return str
|
flickerstreak@22
|
233 end
|
flickerstreak@22
|
234 return player .. " - " .. realm
|
flickerstreak@22
|
235 end
|
flickerstreak@22
|
236 end
|
flickerstreak@1
|
237
|
flickerstreak@1
|
238 local AceOO = AceLibrary("AceOO-2.0")
|
flickerstreak@1
|
239 local AceEvent
|
flickerstreak@1
|
240 local Mixin = AceOO.Mixin
|
flickerstreak@1
|
241 local AceDB = Mixin {
|
flickerstreak@1
|
242 "RegisterDB",
|
flickerstreak@1
|
243 "RegisterDefaults",
|
flickerstreak@1
|
244 "ResetDB",
|
flickerstreak@1
|
245 "SetProfile",
|
flickerstreak@1
|
246 "GetProfile",
|
flickerstreak@1
|
247 "CopyProfileFrom",
|
flickerstreak@22
|
248 "DeleteProfile",
|
flickerstreak@1
|
249 "ToggleActive",
|
flickerstreak@1
|
250 "IsActive",
|
flickerstreak@1
|
251 "AcquireDBNamespace",
|
flickerstreak@1
|
252 }
|
flickerstreak@1
|
253 local Dewdrop = AceLibrary:HasInstance("Dewdrop-2.0") and AceLibrary("Dewdrop-2.0")
|
flickerstreak@1
|
254
|
flickerstreak@1
|
255 local _G = getfenv(0)
|
flickerstreak@1
|
256
|
flickerstreak@1
|
257 local function inheritDefaults(t, defaults)
|
flickerstreak@1
|
258 if not defaults then
|
flickerstreak@1
|
259 return t
|
flickerstreak@1
|
260 end
|
flickerstreak@1
|
261 for k,v in pairs(defaults) do
|
flickerstreak@22
|
262 if k == "*" or k == "**" then
|
flickerstreak@1
|
263 local v = v
|
flickerstreak@1
|
264 if type(v) == "table" then
|
flickerstreak@1
|
265 setmetatable(t, {
|
flickerstreak@1
|
266 __index = function(self, key)
|
flickerstreak@1
|
267 if key == nil then
|
flickerstreak@1
|
268 return nil
|
flickerstreak@1
|
269 end
|
flickerstreak@1
|
270 self[key] = {}
|
flickerstreak@1
|
271 inheritDefaults(self[key], v)
|
flickerstreak@1
|
272 return self[key]
|
flickerstreak@1
|
273 end
|
flickerstreak@1
|
274 } )
|
flickerstreak@1
|
275 else
|
flickerstreak@1
|
276 setmetatable(t, {
|
flickerstreak@1
|
277 __index = function(self, key)
|
flickerstreak@1
|
278 if key == nil then
|
flickerstreak@1
|
279 return nil
|
flickerstreak@1
|
280 end
|
flickerstreak@1
|
281 self[key] = v
|
flickerstreak@1
|
282 return self[key]
|
flickerstreak@1
|
283 end
|
flickerstreak@1
|
284 } )
|
flickerstreak@1
|
285 end
|
flickerstreak@1
|
286 for key in pairs(t) do
|
flickerstreak@22
|
287 if (defaults[key] == nil or key == k) and type(t[key]) == "table" then
|
flickerstreak@1
|
288 inheritDefaults(t[key], v)
|
flickerstreak@1
|
289 end
|
flickerstreak@1
|
290 end
|
flickerstreak@1
|
291 else
|
flickerstreak@1
|
292 if type(v) == "table" then
|
flickerstreak@22
|
293 if type(rawget(t, k)) ~= "table" then
|
flickerstreak@1
|
294 t[k] = {}
|
flickerstreak@1
|
295 end
|
flickerstreak@1
|
296 inheritDefaults(t[k], v)
|
flickerstreak@22
|
297 if defaults["**"] then
|
flickerstreak@22
|
298 inheritDefaults(t[k], defaults["**"])
|
flickerstreak@22
|
299 end
|
flickerstreak@22
|
300 elseif rawget(t, k) == nil then
|
flickerstreak@1
|
301 t[k] = v
|
flickerstreak@1
|
302 end
|
flickerstreak@1
|
303 end
|
flickerstreak@1
|
304 end
|
flickerstreak@1
|
305 return t
|
flickerstreak@1
|
306 end
|
flickerstreak@1
|
307
|
flickerstreak@1
|
308 local _,race = UnitRace("player")
|
flickerstreak@1
|
309 local faction
|
flickerstreak@1
|
310 if race == "Orc" or race == "Scourge" or race == "Troll" or race == "Tauren" or race == "BloodElf" then
|
flickerstreak@1
|
311 faction = FACTION_HORDE
|
flickerstreak@1
|
312 else
|
flickerstreak@1
|
313 faction = FACTION_ALLIANCE
|
flickerstreak@1
|
314 end
|
flickerstreak@22
|
315 local server = GetRealmName():trim()
|
flickerstreak@22
|
316 local charID = UnitName("player") .. " - " .. server
|
flickerstreak@22
|
317 local realmID = server .. " - " .. faction
|
flickerstreak@1
|
318 local classID = UnitClass("player")
|
flickerstreak@1
|
319
|
flickerstreak@1
|
320 AceDB.CHAR_ID = charID
|
flickerstreak@1
|
321 AceDB.REALM_ID = realmID
|
flickerstreak@1
|
322 AceDB.CLASS_ID = classID
|
flickerstreak@1
|
323
|
flickerstreak@1
|
324 AceDB.FACTION = faction
|
flickerstreak@22
|
325 AceDB.REALM = server
|
flickerstreak@1
|
326 AceDB.NAME = UnitName("player")
|
flickerstreak@1
|
327
|
flickerstreak@1
|
328 local new, del
|
flickerstreak@1
|
329 do
|
flickerstreak@1
|
330 local list = setmetatable({}, {__mode="k"})
|
flickerstreak@1
|
331 function new()
|
flickerstreak@1
|
332 local t = next(list)
|
flickerstreak@1
|
333 if t then
|
flickerstreak@1
|
334 list[t] = nil
|
flickerstreak@1
|
335 return t
|
flickerstreak@1
|
336 else
|
flickerstreak@1
|
337 return {}
|
flickerstreak@1
|
338 end
|
flickerstreak@1
|
339 end
|
flickerstreak@22
|
340
|
flickerstreak@1
|
341 function del(t)
|
flickerstreak@1
|
342 setmetatable(t, nil)
|
flickerstreak@1
|
343 for k in pairs(t) do
|
flickerstreak@1
|
344 t[k] = nil
|
flickerstreak@1
|
345 end
|
flickerstreak@1
|
346 list[t] = true
|
flickerstreak@1
|
347 end
|
flickerstreak@1
|
348 end
|
flickerstreak@1
|
349
|
flickerstreak@1
|
350 local caseInsensitive_mt = {
|
flickerstreak@1
|
351 __index = function(self, key)
|
flickerstreak@1
|
352 if type(key) ~= "string" then
|
flickerstreak@1
|
353 return nil
|
flickerstreak@1
|
354 end
|
flickerstreak@22
|
355 local lowerKey = key:lower()
|
flickerstreak@1
|
356 for k,v in pairs(self) do
|
flickerstreak@22
|
357 if k:lower() == lowerKey then
|
flickerstreak@1
|
358 return self[k]
|
flickerstreak@1
|
359 end
|
flickerstreak@1
|
360 end
|
flickerstreak@1
|
361 end,
|
flickerstreak@1
|
362 __newindex = function(self, key, value)
|
flickerstreak@1
|
363 if type(key) ~= "string" then
|
flickerstreak@1
|
364 return error("table index is nil", 2)
|
flickerstreak@1
|
365 end
|
flickerstreak@22
|
366 local lowerKey = key:lower()
|
flickerstreak@1
|
367 for k in pairs(self) do
|
flickerstreak@22
|
368 if k:lower() == lowerKey then
|
flickerstreak@1
|
369 rawset(self, k, nil)
|
flickerstreak@1
|
370 rawset(self, key, value)
|
flickerstreak@1
|
371 return
|
flickerstreak@1
|
372 end
|
flickerstreak@1
|
373 end
|
flickerstreak@1
|
374 rawset(self, key, value)
|
flickerstreak@1
|
375 end
|
flickerstreak@1
|
376 }
|
flickerstreak@1
|
377
|
flickerstreak@1
|
378 local db_mt = { __index = function(db, key)
|
flickerstreak@1
|
379 if key == "char" then
|
flickerstreak@1
|
380 if db.charName then
|
flickerstreak@1
|
381 if type(_G[db.charName]) ~= "table" then
|
flickerstreak@1
|
382 _G[db.charName] = {}
|
flickerstreak@1
|
383 end
|
flickerstreak@1
|
384 if type(_G[db.charName].global) ~= "table" then
|
flickerstreak@1
|
385 _G[db.charName].global = {}
|
flickerstreak@1
|
386 end
|
flickerstreak@1
|
387 rawset(db, 'char', _G[db.charName].global)
|
flickerstreak@1
|
388 else
|
flickerstreak@1
|
389 if type(db.raw.chars) ~= "table" then
|
flickerstreak@1
|
390 db.raw.chars = {}
|
flickerstreak@1
|
391 end
|
flickerstreak@1
|
392 local id = charID
|
flickerstreak@1
|
393 if type(db.raw.chars[id]) ~= "table" then
|
flickerstreak@1
|
394 db.raw.chars[id] = {}
|
flickerstreak@1
|
395 end
|
flickerstreak@1
|
396 rawset(db, 'char', db.raw.chars[id])
|
flickerstreak@1
|
397 end
|
flickerstreak@1
|
398 if db.defaults and db.defaults.char then
|
flickerstreak@1
|
399 inheritDefaults(db.char, db.defaults.char)
|
flickerstreak@1
|
400 end
|
flickerstreak@1
|
401 return db.char
|
flickerstreak@1
|
402 elseif key == "realm" then
|
flickerstreak@1
|
403 if type(db.raw.realms) ~= "table" then
|
flickerstreak@1
|
404 db.raw.realms = {}
|
flickerstreak@1
|
405 end
|
flickerstreak@1
|
406 local id = realmID
|
flickerstreak@1
|
407 if type(db.raw.realms[id]) ~= "table" then
|
flickerstreak@1
|
408 db.raw.realms[id] = {}
|
flickerstreak@1
|
409 end
|
flickerstreak@1
|
410 rawset(db, 'realm', db.raw.realms[id])
|
flickerstreak@1
|
411 if db.defaults and db.defaults.realm then
|
flickerstreak@1
|
412 inheritDefaults(db.realm, db.defaults.realm)
|
flickerstreak@1
|
413 end
|
flickerstreak@1
|
414 return db.realm
|
flickerstreak@22
|
415 elseif key == "server" then
|
flickerstreak@22
|
416 if type(db.raw.servers) ~= "table" then
|
flickerstreak@22
|
417 db.raw.servers = {}
|
flickerstreak@22
|
418 end
|
flickerstreak@22
|
419 local id = server
|
flickerstreak@22
|
420 if type(db.raw.servers[id]) ~= "table" then
|
flickerstreak@22
|
421 db.raw.servers[id] = {}
|
flickerstreak@22
|
422 end
|
flickerstreak@22
|
423 rawset(db, 'server', db.raw.servers[id])
|
flickerstreak@22
|
424 if db.defaults and db.defaults.server then
|
flickerstreak@22
|
425 inheritDefaults(db.server, db.defaults.server)
|
flickerstreak@22
|
426 end
|
flickerstreak@22
|
427 return db.server
|
flickerstreak@1
|
428 elseif key == "account" then
|
flickerstreak@1
|
429 if type(db.raw.account) ~= "table" then
|
flickerstreak@1
|
430 db.raw.account = {}
|
flickerstreak@1
|
431 end
|
flickerstreak@1
|
432 rawset(db, 'account', db.raw.account)
|
flickerstreak@1
|
433 if db.defaults and db.defaults.account then
|
flickerstreak@1
|
434 inheritDefaults(db.account, db.defaults.account)
|
flickerstreak@1
|
435 end
|
flickerstreak@1
|
436 return db.account
|
flickerstreak@1
|
437 elseif key == "faction" then
|
flickerstreak@1
|
438 if type(db.raw.factions) ~= "table" then
|
flickerstreak@1
|
439 db.raw.factions = {}
|
flickerstreak@1
|
440 end
|
flickerstreak@1
|
441 local id = faction
|
flickerstreak@1
|
442 if type(db.raw.factions[id]) ~= "table" then
|
flickerstreak@1
|
443 db.raw.factions[id] = {}
|
flickerstreak@1
|
444 end
|
flickerstreak@1
|
445 rawset(db, 'faction', db.raw.factions[id])
|
flickerstreak@1
|
446 if db.defaults and db.defaults.faction then
|
flickerstreak@1
|
447 inheritDefaults(db.faction, db.defaults.faction)
|
flickerstreak@1
|
448 end
|
flickerstreak@1
|
449 return db.faction
|
flickerstreak@1
|
450 elseif key == "class" then
|
flickerstreak@1
|
451 if type(db.raw.classes) ~= "table" then
|
flickerstreak@1
|
452 db.raw.classes = {}
|
flickerstreak@1
|
453 end
|
flickerstreak@1
|
454 local id = classID
|
flickerstreak@1
|
455 if type(db.raw.classes[id]) ~= "table" then
|
flickerstreak@1
|
456 db.raw.classes[id] = {}
|
flickerstreak@1
|
457 end
|
flickerstreak@1
|
458 rawset(db, 'class', db.raw.classes[id])
|
flickerstreak@1
|
459 if db.defaults and db.defaults.class then
|
flickerstreak@1
|
460 inheritDefaults(db.class, db.defaults.class)
|
flickerstreak@1
|
461 end
|
flickerstreak@1
|
462 return db.class
|
flickerstreak@1
|
463 elseif key == "profile" then
|
flickerstreak@1
|
464 if type(db.raw.profiles) ~= "table" then
|
flickerstreak@1
|
465 db.raw.profiles = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
466 else
|
flickerstreak@1
|
467 setmetatable(db.raw.profiles, caseInsensitive_mt)
|
flickerstreak@1
|
468 end
|
flickerstreak@1
|
469 local id = db.raw.currentProfile[charID]
|
flickerstreak@1
|
470 if id == "char" then
|
flickerstreak@1
|
471 id = "char/" .. charID
|
flickerstreak@1
|
472 elseif id == "class" then
|
flickerstreak@1
|
473 id = "class/" .. classID
|
flickerstreak@1
|
474 elseif id == "realm" then
|
flickerstreak@1
|
475 id = "realm/" .. realmID
|
flickerstreak@1
|
476 end
|
flickerstreak@1
|
477 if type(db.raw.profiles[id]) ~= "table" then
|
flickerstreak@1
|
478 db.raw.profiles[id] = {}
|
flickerstreak@1
|
479 end
|
flickerstreak@1
|
480 rawset(db, 'profile', db.raw.profiles[id])
|
flickerstreak@1
|
481 if db.defaults and db.defaults.profile then
|
flickerstreak@1
|
482 inheritDefaults(db.profile, db.defaults.profile)
|
flickerstreak@1
|
483 end
|
flickerstreak@1
|
484 return db.profile
|
flickerstreak@1
|
485 elseif key == "raw" or key == "defaults" or key == "name" or key == "charName" or key == "namespaces" then
|
flickerstreak@1
|
486 return nil
|
flickerstreak@1
|
487 end
|
flickerstreak@22
|
488 error(("Cannot access key %q in db table. You may want to use db.profile[%q]"):format(tostring(key), tostring(key)), 2)
|
flickerstreak@1
|
489 end, __newindex = function(db, key, value)
|
flickerstreak@22
|
490 error(("Cannot access key %q in db table. You may want to use db.profile[%q]"):format(tostring(key), tostring(key)), 2)
|
flickerstreak@1
|
491 end }
|
flickerstreak@1
|
492
|
flickerstreak@1
|
493 local function RecalculateAceDBCopyFromList(target)
|
flickerstreak@1
|
494 local db = target.db
|
flickerstreak@1
|
495 local t = target['acedb-profile-copylist']
|
flickerstreak@1
|
496 for k,v in pairs(t) do
|
flickerstreak@1
|
497 t[k] = nil
|
flickerstreak@1
|
498 end
|
flickerstreak@1
|
499 local _,currentProfile = AceDB.GetProfile(target)
|
flickerstreak@1
|
500 if db and db.raw then
|
flickerstreak@1
|
501 if db.raw.profiles then
|
flickerstreak@1
|
502 for k in pairs(db.raw.profiles) do
|
flickerstreak@1
|
503 if currentProfile ~= k then
|
flickerstreak@22
|
504 if k:find("^char/") then
|
flickerstreak@22
|
505 local name = k:sub(6)
|
flickerstreak@22
|
506 local player, realm = name:match("^(.*) %- (.*)$")
|
flickerstreak@22
|
507 if player then
|
flickerstreak@22
|
508 name = PLAYER_OF_REALM:format(player, realm)
|
flickerstreak@22
|
509 end
|
flickerstreak@1
|
510 t[k] = CHARACTER_COLON .. name
|
flickerstreak@22
|
511 elseif k:find("^realm/") then
|
flickerstreak@22
|
512 local name = k:sub(7)
|
flickerstreak@1
|
513 t[k] = REALM_COLON .. name
|
flickerstreak@22
|
514 elseif k:find("^class/") then
|
flickerstreak@22
|
515 local name = k:sub(7)
|
flickerstreak@1
|
516 t[k] = CLASS_COLON .. name
|
flickerstreak@1
|
517 else
|
flickerstreak@1
|
518 t[k] = k
|
flickerstreak@1
|
519 end
|
flickerstreak@1
|
520 end
|
flickerstreak@1
|
521 end
|
flickerstreak@1
|
522 end
|
flickerstreak@1
|
523 if db.raw.namespaces then
|
flickerstreak@1
|
524 for _,n in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
525 if n.profiles then
|
flickerstreak@1
|
526 for k in pairs(n.profiles) do
|
flickerstreak@1
|
527 if currentProfile ~= k then
|
flickerstreak@22
|
528 if k:find('^char/') then
|
flickerstreak@22
|
529 local name = k:sub(6)
|
flickerstreak@22
|
530 local player, realm = name:match("^(.*) %- (.*)$")
|
flickerstreak@22
|
531 if player then
|
flickerstreak@22
|
532 name = PLAYER_OF_REALM:format(player, realm)
|
flickerstreak@22
|
533 end
|
flickerstreak@1
|
534 t[k] = CHARACTER_COLON .. name
|
flickerstreak@22
|
535 elseif k:find('^realm/') then
|
flickerstreak@22
|
536 local name = k:sub(7)
|
flickerstreak@1
|
537 t[k] = REALM_COLON .. name
|
flickerstreak@22
|
538 elseif k:find('^class/') then
|
flickerstreak@22
|
539 local name = k:sub(7)
|
flickerstreak@1
|
540 t[k] = CLASS_COLON .. name
|
flickerstreak@1
|
541 else
|
flickerstreak@1
|
542 t[k] = k
|
flickerstreak@1
|
543 end
|
flickerstreak@1
|
544 end
|
flickerstreak@1
|
545 end
|
flickerstreak@1
|
546 end
|
flickerstreak@1
|
547 end
|
flickerstreak@1
|
548 end
|
flickerstreak@1
|
549 end
|
flickerstreak@1
|
550 if t.Default then
|
flickerstreak@1
|
551 t.Default = DEFAULT
|
flickerstreak@1
|
552 end
|
flickerstreak@1
|
553 if t.Alternative then
|
flickerstreak@1
|
554 t.Alternative = ALTERNATIVE
|
flickerstreak@1
|
555 end
|
flickerstreak@1
|
556 end
|
flickerstreak@1
|
557
|
flickerstreak@1
|
558 local function RecalculateAceDBProfileList(target)
|
flickerstreak@1
|
559 local t = target['acedb-profile-list']
|
flickerstreak@1
|
560 for k,v in pairs(t) do
|
flickerstreak@1
|
561 t[k] = nil
|
flickerstreak@1
|
562 end
|
flickerstreak@22
|
563 t.char = CHARACTER_COLON .. PLAYER_OF_REALM:format(UnitName("player"), server)
|
flickerstreak@1
|
564 t.realm = REALM_COLON .. realmID
|
flickerstreak@1
|
565 t.class = CLASS_COLON .. classID
|
flickerstreak@1
|
566 t.Default = DEFAULT
|
flickerstreak@1
|
567 local db = target.db
|
flickerstreak@1
|
568 if db and db.raw then
|
flickerstreak@1
|
569 if db.raw.profiles then
|
flickerstreak@1
|
570 for k in pairs(db.raw.profiles) do
|
flickerstreak@22
|
571 if not k:find("^char/") and not k:find("^realm/") and not k:find("^class/") then
|
flickerstreak@1
|
572 t[k] = k
|
flickerstreak@1
|
573 end
|
flickerstreak@1
|
574 end
|
flickerstreak@1
|
575 end
|
flickerstreak@1
|
576 if db.raw.namespaces then
|
flickerstreak@1
|
577 for _,n in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
578 if n.profiles then
|
flickerstreak@1
|
579 for k in pairs(n.profiles) do
|
flickerstreak@22
|
580 if not k:find("^char/") and not k:find("^realm/") and not k:find("^class/") then
|
flickerstreak@1
|
581 t[k] = k
|
flickerstreak@1
|
582 end
|
flickerstreak@1
|
583 end
|
flickerstreak@1
|
584 end
|
flickerstreak@1
|
585 end
|
flickerstreak@1
|
586 end
|
flickerstreak@1
|
587 local curr = db.raw.currentProfile and db.raw.currentProfile[charID]
|
flickerstreak@22
|
588 if curr and not t[curr] then
|
flickerstreak@1
|
589 t[curr] = curr
|
flickerstreak@1
|
590 end
|
flickerstreak@1
|
591 end
|
flickerstreak@1
|
592 if t.Alternative then
|
flickerstreak@1
|
593 t.Alternative = ALTERNATIVE
|
flickerstreak@1
|
594 end
|
flickerstreak@1
|
595 end
|
flickerstreak@1
|
596
|
flickerstreak@1
|
597 local CrawlForSerialization
|
flickerstreak@1
|
598 local CrawlForDeserialization
|
flickerstreak@1
|
599
|
flickerstreak@1
|
600 local function SerializeObject(o)
|
flickerstreak@1
|
601 local t = { o:Serialize() }
|
flickerstreak@1
|
602 CrawlForSerialization(t)
|
flickerstreak@1
|
603 t[0] = o.class:GetLibraryVersion()
|
flickerstreak@1
|
604 return t
|
flickerstreak@1
|
605 end
|
flickerstreak@1
|
606
|
flickerstreak@1
|
607 local function DeserializeObject(t)
|
flickerstreak@1
|
608 CrawlForDeserialization(t)
|
flickerstreak@1
|
609 local className = t[0]
|
flickerstreak@1
|
610 t[0] = nil
|
flickerstreak@1
|
611 return AceLibrary(className):Deserialize(unpack(t))
|
flickerstreak@1
|
612 end
|
flickerstreak@1
|
613
|
flickerstreak@1
|
614 local function IsSerializable(t)
|
flickerstreak@1
|
615 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
|
616 end
|
flickerstreak@1
|
617
|
flickerstreak@1
|
618 function CrawlForSerialization(t)
|
flickerstreak@1
|
619 local tmp = new()
|
flickerstreak@1
|
620 for k,v in pairs(t) do
|
flickerstreak@1
|
621 tmp[k] = v
|
flickerstreak@1
|
622 end
|
flickerstreak@1
|
623 for k,v in pairs(tmp) do
|
flickerstreak@22
|
624 if type(v) == "table" and type(rawget(v, 0)) ~= "userdata" then
|
flickerstreak@1
|
625 if IsSerializable(v) then
|
flickerstreak@1
|
626 v = SerializeObject(v)
|
flickerstreak@1
|
627 t[k] = v
|
flickerstreak@1
|
628 else
|
flickerstreak@1
|
629 CrawlForSerialization(v)
|
flickerstreak@1
|
630 end
|
flickerstreak@1
|
631 end
|
flickerstreak@22
|
632 if type(k) == "table" and type(rawget(k, 0)) ~= "userdata" then
|
flickerstreak@1
|
633 if IsSerializable(k) then
|
flickerstreak@1
|
634 t[k] = nil
|
flickerstreak@1
|
635 t[SerializeObject(k)] = v
|
flickerstreak@1
|
636 else
|
flickerstreak@1
|
637 CrawlForSerialization(k)
|
flickerstreak@1
|
638 end
|
flickerstreak@1
|
639 end
|
flickerstreak@1
|
640 tmp[k] = nil
|
flickerstreak@1
|
641 k = nil
|
flickerstreak@1
|
642 end
|
flickerstreak@1
|
643 tmp = del(tmp)
|
flickerstreak@1
|
644 end
|
flickerstreak@1
|
645
|
flickerstreak@1
|
646 local function IsDeserializable(t)
|
flickerstreak@22
|
647 return type(rawget(t, 0)) == "string" and AceLibrary:HasInstance(rawget(t, 0))
|
flickerstreak@1
|
648 end
|
flickerstreak@1
|
649
|
flickerstreak@1
|
650 function CrawlForDeserialization(t)
|
flickerstreak@1
|
651 local tmp = new()
|
flickerstreak@1
|
652 for k,v in pairs(t) do
|
flickerstreak@1
|
653 tmp[k] = v
|
flickerstreak@1
|
654 end
|
flickerstreak@1
|
655 for k,v in pairs(tmp) do
|
flickerstreak@1
|
656 if type(v) == "table" then
|
flickerstreak@1
|
657 if IsDeserializable(v) then
|
flickerstreak@1
|
658 t[k] = DeserializeObject(v)
|
flickerstreak@1
|
659 del(v)
|
flickerstreak@1
|
660 v = t[k]
|
flickerstreak@22
|
661 elseif type(rawget(v, 0)) ~= "userdata" then
|
flickerstreak@1
|
662 CrawlForDeserialization(v)
|
flickerstreak@1
|
663 end
|
flickerstreak@1
|
664 end
|
flickerstreak@1
|
665 if type(k) == "table" then
|
flickerstreak@1
|
666 if IsDeserializable(k) then
|
flickerstreak@1
|
667 t[k] = nil
|
flickerstreak@1
|
668 t[DeserializeObject(k)] = v
|
flickerstreak@1
|
669 del(k)
|
flickerstreak@22
|
670 elseif type(rawget(k, 0)) ~= "userdata" then
|
flickerstreak@1
|
671 CrawlForDeserialization(k)
|
flickerstreak@1
|
672 end
|
flickerstreak@1
|
673 end
|
flickerstreak@1
|
674 tmp[k] = nil
|
flickerstreak@1
|
675 k = nil
|
flickerstreak@1
|
676 end
|
flickerstreak@1
|
677 tmp = del(tmp)
|
flickerstreak@1
|
678 end
|
flickerstreak@1
|
679
|
flickerstreak@1
|
680 local namespace_mt = { __index = function(namespace, key)
|
flickerstreak@1
|
681 local db = namespace.db
|
flickerstreak@1
|
682 local name = namespace.name
|
flickerstreak@1
|
683 if key == "char" then
|
flickerstreak@1
|
684 if db.charName then
|
flickerstreak@1
|
685 if type(_G[db.charName]) ~= "table" then
|
flickerstreak@1
|
686 _G[db.charName] = {}
|
flickerstreak@1
|
687 end
|
flickerstreak@1
|
688 if type(_G[db.charName].namespaces) ~= "table" then
|
flickerstreak@1
|
689 _G[db.charName].namespaces = {}
|
flickerstreak@1
|
690 end
|
flickerstreak@1
|
691 if type(_G[db.charName].namespaces[name]) ~= "table" then
|
flickerstreak@1
|
692 _G[db.charName].namespaces[name] = {}
|
flickerstreak@1
|
693 end
|
flickerstreak@1
|
694 rawset(namespace, 'char', _G[db.charName].namespaces[name])
|
flickerstreak@1
|
695 else
|
flickerstreak@1
|
696 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
697 db.raw.namespaces = {}
|
flickerstreak@1
|
698 end
|
flickerstreak@1
|
699 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
700 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
701 end
|
flickerstreak@1
|
702 if type(db.raw.namespaces[name].chars) ~= "table" then
|
flickerstreak@1
|
703 db.raw.namespaces[name].chars = {}
|
flickerstreak@1
|
704 end
|
flickerstreak@1
|
705 local id = charID
|
flickerstreak@1
|
706 if type(db.raw.namespaces[name].chars[id]) ~= "table" then
|
flickerstreak@1
|
707 db.raw.namespaces[name].chars[id] = {}
|
flickerstreak@1
|
708 end
|
flickerstreak@1
|
709 rawset(namespace, 'char', db.raw.namespaces[name].chars[id])
|
flickerstreak@1
|
710 end
|
flickerstreak@1
|
711 if namespace.defaults and namespace.defaults.char then
|
flickerstreak@1
|
712 inheritDefaults(namespace.char, namespace.defaults.char)
|
flickerstreak@1
|
713 end
|
flickerstreak@1
|
714 return namespace.char
|
flickerstreak@1
|
715 elseif key == "realm" then
|
flickerstreak@1
|
716 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
717 db.raw.namespaces = {}
|
flickerstreak@1
|
718 end
|
flickerstreak@1
|
719 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
720 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
721 end
|
flickerstreak@1
|
722 if type(db.raw.namespaces[name].realms) ~= "table" then
|
flickerstreak@1
|
723 db.raw.namespaces[name].realms = {}
|
flickerstreak@1
|
724 end
|
flickerstreak@1
|
725 local id = realmID
|
flickerstreak@1
|
726 if type(db.raw.namespaces[name].realms[id]) ~= "table" then
|
flickerstreak@1
|
727 db.raw.namespaces[name].realms[id] = {}
|
flickerstreak@1
|
728 end
|
flickerstreak@1
|
729 rawset(namespace, 'realm', db.raw.namespaces[name].realms[id])
|
flickerstreak@1
|
730 if namespace.defaults and namespace.defaults.realm then
|
flickerstreak@1
|
731 inheritDefaults(namespace.realm, namespace.defaults.realm)
|
flickerstreak@1
|
732 end
|
flickerstreak@1
|
733 return namespace.realm
|
flickerstreak@22
|
734 elseif key == "server" then
|
flickerstreak@22
|
735 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@22
|
736 db.raw.namespaces = {}
|
flickerstreak@22
|
737 end
|
flickerstreak@22
|
738 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@22
|
739 db.raw.namespaces[name] = {}
|
flickerstreak@22
|
740 end
|
flickerstreak@22
|
741 if type(db.raw.namespaces[name].servers) ~= "table" then
|
flickerstreak@22
|
742 db.raw.namespaces[name].servers = {}
|
flickerstreak@22
|
743 end
|
flickerstreak@22
|
744 local id = server
|
flickerstreak@22
|
745 if type(db.raw.namespaces[name].servers[id]) ~= "table" then
|
flickerstreak@22
|
746 db.raw.namespaces[name].servers[id] = {}
|
flickerstreak@22
|
747 end
|
flickerstreak@22
|
748 rawset(namespace, 'server', db.raw.namespaces[name].servers[id])
|
flickerstreak@22
|
749 if namespace.defaults and namespace.defaults.server then
|
flickerstreak@22
|
750 inheritDefaults(namespace.server, namespace.defaults.server)
|
flickerstreak@22
|
751 end
|
flickerstreak@22
|
752 return namespace.server
|
flickerstreak@1
|
753 elseif key == "account" then
|
flickerstreak@1
|
754 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
755 db.raw.namespaces = {}
|
flickerstreak@1
|
756 end
|
flickerstreak@1
|
757 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
758 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
759 end
|
flickerstreak@1
|
760 if type(db.raw.namespaces[name].account) ~= "table" then
|
flickerstreak@1
|
761 db.raw.namespaces[name].account = {}
|
flickerstreak@1
|
762 end
|
flickerstreak@1
|
763 rawset(namespace, 'account', db.raw.namespaces[name].account)
|
flickerstreak@1
|
764 if namespace.defaults and namespace.defaults.account then
|
flickerstreak@1
|
765 inheritDefaults(namespace.account, namespace.defaults.account)
|
flickerstreak@1
|
766 end
|
flickerstreak@1
|
767 return namespace.account
|
flickerstreak@1
|
768 elseif key == "faction" then
|
flickerstreak@1
|
769 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
770 db.raw.namespaces = {}
|
flickerstreak@1
|
771 end
|
flickerstreak@1
|
772 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
773 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
774 end
|
flickerstreak@1
|
775 if type(db.raw.namespaces[name].factions) ~= "table" then
|
flickerstreak@1
|
776 db.raw.namespaces[name].factions = {}
|
flickerstreak@1
|
777 end
|
flickerstreak@1
|
778 local id = faction
|
flickerstreak@1
|
779 if type(db.raw.namespaces[name].factions[id]) ~= "table" then
|
flickerstreak@1
|
780 db.raw.namespaces[name].factions[id] = {}
|
flickerstreak@1
|
781 end
|
flickerstreak@1
|
782 rawset(namespace, 'faction', db.raw.namespaces[name].factions[id])
|
flickerstreak@1
|
783 if namespace.defaults and namespace.defaults.faction then
|
flickerstreak@1
|
784 inheritDefaults(namespace.faction, namespace.defaults.faction)
|
flickerstreak@1
|
785 end
|
flickerstreak@1
|
786 return namespace.faction
|
flickerstreak@1
|
787 elseif key == "class" then
|
flickerstreak@1
|
788 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
789 db.raw.namespaces = {}
|
flickerstreak@1
|
790 end
|
flickerstreak@1
|
791 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
792 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
793 end
|
flickerstreak@1
|
794 if type(db.raw.namespaces[name].classes) ~= "table" then
|
flickerstreak@1
|
795 db.raw.namespaces[name].classes = {}
|
flickerstreak@1
|
796 end
|
flickerstreak@1
|
797 local id = classID
|
flickerstreak@1
|
798 if type(db.raw.namespaces[name].classes[id]) ~= "table" then
|
flickerstreak@1
|
799 db.raw.namespaces[name].classes[id] = {}
|
flickerstreak@1
|
800 end
|
flickerstreak@1
|
801 rawset(namespace, 'class', db.raw.namespaces[name].classes[id])
|
flickerstreak@1
|
802 if namespace.defaults and namespace.defaults.class then
|
flickerstreak@1
|
803 inheritDefaults(namespace.class, namespace.defaults.class)
|
flickerstreak@1
|
804 end
|
flickerstreak@1
|
805 return namespace.class
|
flickerstreak@1
|
806 elseif key == "profile" then
|
flickerstreak@1
|
807 if type(db.raw.namespaces) ~= "table" then
|
flickerstreak@1
|
808 db.raw.namespaces = {}
|
flickerstreak@1
|
809 end
|
flickerstreak@1
|
810 if type(db.raw.namespaces[name]) ~= "table" then
|
flickerstreak@1
|
811 db.raw.namespaces[name] = {}
|
flickerstreak@1
|
812 end
|
flickerstreak@1
|
813 if type(db.raw.namespaces[name].profiles) ~= "table" then
|
flickerstreak@1
|
814 db.raw.namespaces[name].profiles = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
815 else
|
flickerstreak@1
|
816 setmetatable(db.raw.namespaces[name].profiles, caseInsensitive_mt)
|
flickerstreak@1
|
817 end
|
flickerstreak@1
|
818 local id = db.raw.currentProfile[charID]
|
flickerstreak@1
|
819 if id == "char" then
|
flickerstreak@1
|
820 id = "char/" .. charID
|
flickerstreak@1
|
821 elseif id == "class" then
|
flickerstreak@1
|
822 id = "class/" .. classID
|
flickerstreak@1
|
823 elseif id == "realm" then
|
flickerstreak@1
|
824 id = "realm/" .. realmID
|
flickerstreak@1
|
825 end
|
flickerstreak@1
|
826 if type(db.raw.namespaces[name].profiles[id]) ~= "table" then
|
flickerstreak@1
|
827 db.raw.namespaces[name].profiles[id] = {}
|
flickerstreak@1
|
828 end
|
flickerstreak@1
|
829 rawset(namespace, 'profile', db.raw.namespaces[name].profiles[id])
|
flickerstreak@1
|
830 if namespace.defaults and namespace.defaults.profile then
|
flickerstreak@1
|
831 inheritDefaults(namespace.profile, namespace.defaults.profile)
|
flickerstreak@1
|
832 end
|
flickerstreak@1
|
833 return namespace.profile
|
flickerstreak@1
|
834 elseif key == "defaults" or key == "name" or key == "db" then
|
flickerstreak@1
|
835 return nil
|
flickerstreak@1
|
836 end
|
flickerstreak@22
|
837 error(("Cannot access key %q in db table. You may want to use db.profile[%q]"):format(tostring(key), tostring(key)), 2)
|
flickerstreak@1
|
838 end, __newindex = function(db, key, value)
|
flickerstreak@22
|
839 error(("Cannot access key %q in db table. You may want to use db.profile[%q]"):format(tostring(key), tostring(key)), 2)
|
flickerstreak@1
|
840 end }
|
flickerstreak@1
|
841
|
flickerstreak@22
|
842 local tmp = {}
|
flickerstreak@1
|
843 function AceDB:InitializeDB(addonName)
|
flickerstreak@1
|
844 local db = self.db
|
flickerstreak@22
|
845
|
flickerstreak@1
|
846 if not db then
|
flickerstreak@1
|
847 if addonName then
|
flickerstreak@1
|
848 AceDB.addonsLoaded[addonName] = true
|
flickerstreak@1
|
849 end
|
flickerstreak@1
|
850 return
|
flickerstreak@1
|
851 end
|
flickerstreak@22
|
852
|
flickerstreak@1
|
853 if db.raw then
|
flickerstreak@1
|
854 -- someone manually initialized
|
flickerstreak@1
|
855 return
|
flickerstreak@1
|
856 end
|
flickerstreak@22
|
857
|
flickerstreak@1
|
858 if type(_G[db.name]) ~= "table" then
|
flickerstreak@1
|
859 _G[db.name] = {}
|
flickerstreak@1
|
860 else
|
flickerstreak@1
|
861 CrawlForDeserialization(_G[db.name])
|
flickerstreak@1
|
862 end
|
flickerstreak@22
|
863 if db.charName then
|
flickerstreak@22
|
864 if type(_G[db.charName]) ~= "table" then
|
flickerstreak@22
|
865 _G[db.charName] = {}
|
flickerstreak@22
|
866 else
|
flickerstreak@22
|
867 CrawlForDeserialization(_G[db.charName])
|
flickerstreak@22
|
868 end
|
flickerstreak@1
|
869 end
|
flickerstreak@1
|
870 rawset(db, 'raw', _G[db.name])
|
flickerstreak@1
|
871 if not db.raw.currentProfile then
|
flickerstreak@1
|
872 db.raw.currentProfile = {}
|
flickerstreak@22
|
873 else
|
flickerstreak@22
|
874 for k,v in pairs(db.raw.currentProfile) do
|
flickerstreak@22
|
875 tmp[convertFromOldCharID(k)] = v
|
flickerstreak@22
|
876 db.raw.currentProfile[k] = nil
|
flickerstreak@22
|
877 end
|
flickerstreak@22
|
878 for k,v in pairs(tmp) do
|
flickerstreak@22
|
879 db.raw.currentProfile[k] = v
|
flickerstreak@22
|
880 tmp[k] = nil
|
flickerstreak@22
|
881 end
|
flickerstreak@1
|
882 end
|
flickerstreak@1
|
883 if not db.raw.currentProfile[charID] then
|
flickerstreak@22
|
884 db.raw.currentProfile[charID] = AceDB.registry[self] or "Default"
|
flickerstreak@22
|
885 end
|
flickerstreak@22
|
886 if db.raw.profiles then
|
flickerstreak@22
|
887 for k,v in pairs(db.raw.profiles) do
|
flickerstreak@22
|
888 local new_k = k
|
flickerstreak@22
|
889 if k:find("^char/") then
|
flickerstreak@22
|
890 new_k = "char/" .. convertFromOldCharID(k:sub(6))
|
flickerstreak@22
|
891 end
|
flickerstreak@22
|
892 tmp[new_k] = v
|
flickerstreak@22
|
893 db.raw.profiles[k] = nil
|
flickerstreak@22
|
894 end
|
flickerstreak@22
|
895 for k,v in pairs(tmp) do
|
flickerstreak@22
|
896 db.raw.profiles[k] = v
|
flickerstreak@22
|
897 tmp[k] = nil
|
flickerstreak@22
|
898 end
|
flickerstreak@22
|
899 end
|
flickerstreak@22
|
900 if db.raw.disabledModules then -- AceModuleCore-2.0
|
flickerstreak@22
|
901 for k,v in pairs(db.raw.disabledModules) do
|
flickerstreak@22
|
902 local new_k = k
|
flickerstreak@22
|
903 if k:find("^char/") then
|
flickerstreak@22
|
904 new_k = "char/" .. convertFromOldCharID(k:sub(6))
|
flickerstreak@22
|
905 end
|
flickerstreak@22
|
906 tmp[new_k] = v
|
flickerstreak@22
|
907 db.raw.disabledModules[k] = nil
|
flickerstreak@22
|
908 end
|
flickerstreak@22
|
909 for k,v in pairs(tmp) do
|
flickerstreak@22
|
910 db.raw.disabledModules[k] = v
|
flickerstreak@22
|
911 tmp[k] = nil
|
flickerstreak@22
|
912 end
|
flickerstreak@22
|
913 end
|
flickerstreak@22
|
914 if db.raw.chars then
|
flickerstreak@22
|
915 for k,v in pairs(db.raw.chars) do
|
flickerstreak@22
|
916 tmp[convertFromOldCharID(k)] = v
|
flickerstreak@22
|
917 db.raw.chars[k] = nil
|
flickerstreak@22
|
918 end
|
flickerstreak@22
|
919 for k,v in pairs(tmp) do
|
flickerstreak@22
|
920 db.raw.chars[k] = v
|
flickerstreak@22
|
921 tmp[k] = nil
|
flickerstreak@22
|
922 end
|
flickerstreak@22
|
923 end
|
flickerstreak@22
|
924 if db.raw.namespaces then
|
flickerstreak@22
|
925 for l,u in pairs(db.raw.namespaces) do
|
flickerstreak@22
|
926 if u.chars then
|
flickerstreak@22
|
927 for k,v in pairs(u.chars) do
|
flickerstreak@22
|
928 tmp[convertFromOldCharID(k)] = v
|
flickerstreak@22
|
929 u.chars[k] = nil
|
flickerstreak@22
|
930 end
|
flickerstreak@22
|
931 for k,v in pairs(tmp) do
|
flickerstreak@22
|
932 u.chars[k] = v
|
flickerstreak@22
|
933 tmp[k] = nil
|
flickerstreak@22
|
934 end
|
flickerstreak@22
|
935 end
|
flickerstreak@22
|
936 end
|
flickerstreak@1
|
937 end
|
flickerstreak@1
|
938 if db.raw.disabled then
|
flickerstreak@1
|
939 setmetatable(db.raw.disabled, caseInsensitive_mt)
|
flickerstreak@1
|
940 end
|
flickerstreak@1
|
941 if self['acedb-profile-copylist'] then
|
flickerstreak@1
|
942 RecalculateAceDBCopyFromList(self)
|
flickerstreak@1
|
943 end
|
flickerstreak@1
|
944 if self['acedb-profile-list'] then
|
flickerstreak@1
|
945 RecalculateAceDBProfileList(self)
|
flickerstreak@1
|
946 end
|
flickerstreak@1
|
947 setmetatable(db, db_mt)
|
flickerstreak@1
|
948 end
|
flickerstreak@1
|
949
|
flickerstreak@1
|
950 function AceDB:OnEmbedInitialize(target, name)
|
flickerstreak@1
|
951 if name then
|
flickerstreak@1
|
952 self:ADDON_LOADED(name)
|
flickerstreak@1
|
953 end
|
flickerstreak@1
|
954 self.InitializeDB(target, name)
|
flickerstreak@1
|
955 end
|
flickerstreak@1
|
956
|
flickerstreak@22
|
957 function AceDB:RegisterDB(name, charName, defaultProfile)
|
flickerstreak@1
|
958 AceDB:argCheck(name, 2, "string")
|
flickerstreak@1
|
959 AceDB:argCheck(charName, 3, "string", "nil")
|
flickerstreak@22
|
960 AceDB:argCheck(defaultProfile, 4, "string", "nil")
|
flickerstreak@1
|
961 if self.db then
|
flickerstreak@1
|
962 AceDB:error("Cannot call \"RegisterDB\" if self.db is set.")
|
flickerstreak@1
|
963 end
|
flickerstreak@1
|
964 local stack = debugstack()
|
flickerstreak@22
|
965 local addonName = stack:gsub(".-\n.-\\AddOns\\(.-)\\.*", "%1")
|
flickerstreak@1
|
966 self.db = {
|
flickerstreak@1
|
967 name = name,
|
flickerstreak@1
|
968 charName = charName
|
flickerstreak@1
|
969 }
|
flickerstreak@22
|
970 AceDB.registry[self] = defaultProfile or "Default"
|
flickerstreak@1
|
971 if AceDB.addonsLoaded[addonName] then
|
flickerstreak@1
|
972 AceDB.InitializeDB(self, addonName)
|
flickerstreak@1
|
973 else
|
flickerstreak@1
|
974 AceDB.addonsToBeInitialized[self] = addonName
|
flickerstreak@1
|
975 end
|
flickerstreak@1
|
976 end
|
flickerstreak@1
|
977
|
flickerstreak@1
|
978 function AceDB:RegisterDefaults(kind, defaults, a3)
|
flickerstreak@1
|
979 local name
|
flickerstreak@1
|
980 if a3 then
|
flickerstreak@1
|
981 name, kind, defaults = kind, defaults, a3
|
flickerstreak@1
|
982 AceDB:argCheck(name, 2, "string")
|
flickerstreak@1
|
983 AceDB:argCheck(kind, 3, "string")
|
flickerstreak@1
|
984 AceDB:argCheck(defaults, 4, "table")
|
flickerstreak@1
|
985 else
|
flickerstreak@1
|
986 AceDB:argCheck(kind, 2, "string")
|
flickerstreak@1
|
987 AceDB:argCheck(defaults, 3, "table")
|
flickerstreak@1
|
988 end
|
flickerstreak@22
|
989 if kind ~= "char" and kind ~= "class" and kind ~= "profile" and kind ~= "account" and kind ~= "realm" and kind ~= "faction" and kind ~= "server" then
|
flickerstreak@22
|
990 AceDB:error("Bad argument #%d to `RegisterDefaults' (\"char\", \"class\", \"profile\", \"account\", \"realm\", \"server\", or \"faction\" expected, got %q)", a3 and 3 or 2, kind)
|
flickerstreak@1
|
991 end
|
flickerstreak@1
|
992 if type(self.db) ~= "table" or type(self.db.name) ~= "string" then
|
flickerstreak@1
|
993 AceDB:error("Cannot call \"RegisterDefaults\" unless \"RegisterDB\" has been previously called.")
|
flickerstreak@1
|
994 end
|
flickerstreak@1
|
995 local db
|
flickerstreak@1
|
996 if name then
|
flickerstreak@1
|
997 local namespace = self:AcquireDBNamespace(name)
|
flickerstreak@1
|
998 if namespace.defaults and namespace.defaults[kind] then
|
flickerstreak@1
|
999 AceDB:error("\"RegisterDefaults\" has already been called for %q::%q.", name, kind)
|
flickerstreak@1
|
1000 end
|
flickerstreak@1
|
1001 db = namespace
|
flickerstreak@1
|
1002 else
|
flickerstreak@1
|
1003 if self.db.defaults and self.db.defaults[kind] then
|
flickerstreak@1
|
1004 AceDB:error("\"RegisterDefaults\" has already been called for %q.", kind)
|
flickerstreak@1
|
1005 end
|
flickerstreak@1
|
1006 db = self.db
|
flickerstreak@1
|
1007 end
|
flickerstreak@1
|
1008 if not db.defaults then
|
flickerstreak@1
|
1009 rawset(db, 'defaults', {})
|
flickerstreak@1
|
1010 end
|
flickerstreak@1
|
1011 db.defaults[kind] = defaults
|
flickerstreak@1
|
1012 if rawget(db, kind) then
|
flickerstreak@1
|
1013 inheritDefaults(db[kind], defaults)
|
flickerstreak@1
|
1014 end
|
flickerstreak@1
|
1015 end
|
flickerstreak@1
|
1016
|
flickerstreak@22
|
1017 function AceDB:ResetDB(kind, a2)
|
flickerstreak@22
|
1018 local name
|
flickerstreak@22
|
1019 if a2 then
|
flickerstreak@22
|
1020 name, kind = kind, a2
|
flickerstreak@22
|
1021 AceDB:argCheck(name, 2, "nil", "string")
|
flickerstreak@22
|
1022 AceDB:argCheck(kind, 3, "nil", "string")
|
flickerstreak@22
|
1023 else
|
flickerstreak@22
|
1024 AceDB:argCheck(kind, 2, "nil", "string")
|
flickerstreak@22
|
1025 if kind ~= "char" and kind ~= "class" and kind ~= "profile" and kind ~= "account" and kind ~= "realm" and kind ~= "faction" and kind ~= "server" then
|
flickerstreak@22
|
1026 name, kind = kind, nil
|
flickerstreak@22
|
1027 end
|
flickerstreak@22
|
1028 end
|
flickerstreak@1
|
1029 if not self.db or not self.db.raw then
|
flickerstreak@1
|
1030 AceDB:error("Cannot call \"ResetDB\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.")
|
flickerstreak@1
|
1031 end
|
flickerstreak@1
|
1032 local db = self.db
|
flickerstreak@22
|
1033 if not kind then
|
flickerstreak@22
|
1034 if not name then
|
flickerstreak@22
|
1035 if db.charName then
|
flickerstreak@22
|
1036 _G[db.charName] = nil
|
flickerstreak@22
|
1037 end
|
flickerstreak@22
|
1038 _G[db.name] = nil
|
flickerstreak@22
|
1039 rawset(db, 'raw', nil)
|
flickerstreak@22
|
1040 AceDB.InitializeDB(self)
|
flickerstreak@22
|
1041 if db.namespaces then
|
flickerstreak@22
|
1042 for name,v in pairs(db.namespaces) do
|
flickerstreak@22
|
1043 rawset(v, 'account', nil)
|
flickerstreak@22
|
1044 rawset(v, 'char', nil)
|
flickerstreak@22
|
1045 rawset(v, 'class', nil)
|
flickerstreak@22
|
1046 rawset(v, 'profile', nil)
|
flickerstreak@22
|
1047 rawset(v, 'realm', nil)
|
flickerstreak@22
|
1048 rawset(v, 'server', nil)
|
flickerstreak@22
|
1049 rawset(v, 'faction', nil)
|
flickerstreak@22
|
1050 end
|
flickerstreak@22
|
1051 end
|
flickerstreak@22
|
1052 else
|
flickerstreak@22
|
1053 if db.raw.namespaces then
|
flickerstreak@22
|
1054 db.raw.namespaces[name] = nil
|
flickerstreak@22
|
1055 end
|
flickerstreak@22
|
1056 if db.namespaces then
|
flickerstreak@22
|
1057 local v = db.namespaces[name]
|
flickerstreak@22
|
1058 if v then
|
flickerstreak@22
|
1059 rawset(v, 'account', nil)
|
flickerstreak@22
|
1060 rawset(v, 'char', nil)
|
flickerstreak@22
|
1061 rawset(v, 'class', nil)
|
flickerstreak@22
|
1062 rawset(v, 'profile', nil)
|
flickerstreak@22
|
1063 rawset(v, 'realm', nil)
|
flickerstreak@22
|
1064 rawset(v, 'server', nil)
|
flickerstreak@22
|
1065 rawset(v, 'faction', nil)
|
flickerstreak@22
|
1066 end
|
flickerstreak@1
|
1067 end
|
flickerstreak@1
|
1068 end
|
flickerstreak@1
|
1069 elseif kind == "account" then
|
flickerstreak@22
|
1070 if name then
|
flickerstreak@22
|
1071 db.raw.account = nil
|
flickerstreak@22
|
1072 rawset(db, 'account', nil)
|
flickerstreak@22
|
1073 if db.raw.namespaces then
|
flickerstreak@22
|
1074 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@22
|
1075 v.account = nil
|
flickerstreak@22
|
1076 end
|
flickerstreak@22
|
1077 end
|
flickerstreak@22
|
1078 if db.namespaces then
|
flickerstreak@22
|
1079 for name,v in pairs(db.namespaces) do
|
flickerstreak@22
|
1080 rawset(v, 'account', nil)
|
flickerstreak@22
|
1081 end
|
flickerstreak@22
|
1082 end
|
flickerstreak@22
|
1083 else
|
flickerstreak@22
|
1084 if db.raw.namespaces and db.raw.namespaces[name] then
|
flickerstreak@22
|
1085 db.raw.namespaces[name].account = nil
|
flickerstreak@22
|
1086 end
|
flickerstreak@22
|
1087 if db.namespaces then
|
flickerstreak@22
|
1088 local v = db.namespaces[name]
|
flickerstreak@22
|
1089 if v then
|
flickerstreak@22
|
1090 rawset(v, 'account', nil)
|
flickerstreak@22
|
1091 end
|
flickerstreak@1
|
1092 end
|
flickerstreak@1
|
1093 end
|
flickerstreak@1
|
1094 elseif kind == "char" then
|
flickerstreak@22
|
1095 if name then
|
flickerstreak@22
|
1096 if db.charName then
|
flickerstreak@22
|
1097 _G[db.charName] = nil
|
flickerstreak@22
|
1098 else
|
flickerstreak@22
|
1099 if db.raw.chars then
|
flickerstreak@22
|
1100 db.raw.chars[charID] = nil
|
flickerstreak@22
|
1101 end
|
flickerstreak@22
|
1102 if db.raw.namespaces then
|
flickerstreak@22
|
1103 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@22
|
1104 if v.chars then
|
flickerstreak@22
|
1105 v.chars[charID] = nil
|
flickerstreak@22
|
1106 end
|
flickerstreak@22
|
1107 end
|
flickerstreak@22
|
1108 end
|
flickerstreak@22
|
1109 end
|
flickerstreak@22
|
1110 rawset(db, 'char', nil)
|
flickerstreak@22
|
1111 if db.namespaces then
|
flickerstreak@22
|
1112 for name,v in pairs(db.namespaces) do
|
flickerstreak@22
|
1113 rawset(v, 'char', nil)
|
flickerstreak@22
|
1114 end
|
flickerstreak@22
|
1115 end
|
flickerstreak@1
|
1116 else
|
flickerstreak@22
|
1117 if db.charName then
|
flickerstreak@22
|
1118 local x = _G[db.charName]
|
flickerstreak@22
|
1119 if x.namespaces then
|
flickerstreak@22
|
1120 x.namespaces[name] = nil
|
flickerstreak@22
|
1121 end
|
flickerstreak@22
|
1122 else
|
flickerstreak@22
|
1123 if db.raw.namespaces then
|
flickerstreak@22
|
1124 local v = db.namespaces[name]
|
flickerstreak@22
|
1125 if v and v.chars then
|
flickerstreak@1
|
1126 v.chars[charID] = nil
|
flickerstreak@1
|
1127 end
|
flickerstreak@1
|
1128 end
|
flickerstreak@1
|
1129 end
|
flickerstreak@22
|
1130 if db.namespaces then
|
flickerstreak@22
|
1131 local v = db.namespaces[name]
|
flickerstreak@22
|
1132 if v then
|
flickerstreak@22
|
1133 rawset(v, 'char', nil)
|
flickerstreak@22
|
1134 end
|
flickerstreak@1
|
1135 end
|
flickerstreak@1
|
1136 end
|
flickerstreak@1
|
1137 elseif kind == "realm" then
|
flickerstreak@22
|
1138 if not name then
|
flickerstreak@22
|
1139 if db.raw.realms then
|
flickerstreak@22
|
1140 db.raw.realms[realmID] = nil
|
flickerstreak@22
|
1141 end
|
flickerstreak@22
|
1142 rawset(db, 'realm', nil)
|
flickerstreak@22
|
1143 if db.raw.namespaces then
|
flickerstreak@22
|
1144 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@22
|
1145 if v.realms then
|
flickerstreak@22
|
1146 v.realms[realmID] = nil
|
flickerstreak@22
|
1147 end
|
flickerstreak@22
|
1148 end
|
flickerstreak@22
|
1149 end
|
flickerstreak@22
|
1150 if db.namespaces then
|
flickerstreak@22
|
1151 for name,v in pairs(db.namespaces) do
|
flickerstreak@22
|
1152 rawset(v, 'realm', nil)
|
flickerstreak@22
|
1153 end
|
flickerstreak@22
|
1154 end
|
flickerstreak@22
|
1155 else
|
flickerstreak@22
|
1156 if db.raw.namespaces then
|
flickerstreak@22
|
1157 local v = db.raw.namespaces[name]
|
flickerstreak@22
|
1158 if v and v.realms then
|
flickerstreak@1
|
1159 v.realms[realmID] = nil
|
flickerstreak@1
|
1160 end
|
flickerstreak@1
|
1161 end
|
flickerstreak@22
|
1162 if db.namespaces then
|
flickerstreak@22
|
1163 local v = db.namespaces[name]
|
flickerstreak@22
|
1164 if v then
|
flickerstreak@22
|
1165 rawset(v, 'realm', nil)
|
flickerstreak@22
|
1166 end
|
flickerstreak@22
|
1167 end
|
flickerstreak@1
|
1168 end
|
flickerstreak@22
|
1169 elseif kind == "server" then
|
flickerstreak@22
|
1170 if not name then
|
flickerstreak@22
|
1171 if db.raw.servers then
|
flickerstreak@22
|
1172 db.raw.servers[server] = nil
|
flickerstreak@22
|
1173 end
|
flickerstreak@22
|
1174 rawset(db, 'server', nil)
|
flickerstreak@22
|
1175 if db.raw.namespaces then
|
flickerstreak@22
|
1176 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@22
|
1177 if v.servers then
|
flickerstreak@22
|
1178 v.servers[server] = nil
|
flickerstreak@22
|
1179 end
|
flickerstreak@22
|
1180 end
|
flickerstreak@22
|
1181 end
|
flickerstreak@22
|
1182 if db.namespaces then
|
flickerstreak@22
|
1183 for name,v in pairs(db.namespaces) do
|
flickerstreak@22
|
1184 rawset(v, 'server', nil)
|
flickerstreak@22
|
1185 end
|
flickerstreak@22
|
1186 end
|
flickerstreak@22
|
1187 else
|
flickerstreak@22
|
1188 if db.raw.namespaces then
|
flickerstreak@22
|
1189 local v = db.raw.namespaces[name]
|
flickerstreak@22
|
1190 if v and v.servers then
|
flickerstreak@22
|
1191 v.servers[server] = nil
|
flickerstreak@22
|
1192 end
|
flickerstreak@22
|
1193 end
|
flickerstreak@22
|
1194 if db.namespaces then
|
flickerstreak@22
|
1195 local v = db.namespaces[name]
|
flickerstreak@22
|
1196 if v then
|
flickerstreak@22
|
1197 rawset(v, 'server', nil)
|
flickerstreak@22
|
1198 end
|
flickerstreak@1
|
1199 end
|
flickerstreak@1
|
1200 end
|
flickerstreak@1
|
1201 elseif kind == "faction" then
|
flickerstreak@22
|
1202 if not name then
|
flickerstreak@22
|
1203 if db.raw.factions then
|
flickerstreak@22
|
1204 db.raw.factions[faction] = nil
|
flickerstreak@22
|
1205 end
|
flickerstreak@22
|
1206 rawset(db, 'faction', nil)
|
flickerstreak@22
|
1207 if db.raw.namespaces then
|
flickerstreak@22
|
1208 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@22
|
1209 if v.factions then
|
flickerstreak@22
|
1210 v.factions[faction] = nil
|
flickerstreak@22
|
1211 end
|
flickerstreak@22
|
1212 end
|
flickerstreak@22
|
1213 end
|
flickerstreak@22
|
1214 if db.namespaces then
|
flickerstreak@22
|
1215 for name,v in pairs(db.namespaces) do
|
flickerstreak@22
|
1216 rawset(v, 'faction', nil)
|
flickerstreak@22
|
1217 end
|
flickerstreak@22
|
1218 end
|
flickerstreak@22
|
1219 else
|
flickerstreak@22
|
1220 if db.raw.namespaces then
|
flickerstreak@22
|
1221 local v = db.raw.namespaces[name]
|
flickerstreak@22
|
1222 if v and v.factions then
|
flickerstreak@1
|
1223 v.factions[faction] = nil
|
flickerstreak@1
|
1224 end
|
flickerstreak@1
|
1225 end
|
flickerstreak@22
|
1226 if db.namespaces then
|
flickerstreak@22
|
1227 local v = db.namespaces[name]
|
flickerstreak@22
|
1228 if v then
|
flickerstreak@22
|
1229 rawset(v, 'faction', nil)
|
flickerstreak@22
|
1230 end
|
flickerstreak@1
|
1231 end
|
flickerstreak@1
|
1232 end
|
flickerstreak@1
|
1233 elseif kind == "class" then
|
flickerstreak@22
|
1234 if not name then
|
flickerstreak@22
|
1235 if db.raw.realms then
|
flickerstreak@22
|
1236 db.raw.realms[classID] = nil
|
flickerstreak@22
|
1237 end
|
flickerstreak@22
|
1238 rawset(db, 'class', nil)
|
flickerstreak@22
|
1239 if db.raw.namespaces then
|
flickerstreak@22
|
1240 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@22
|
1241 if v.classes then
|
flickerstreak@22
|
1242 v.classes[classID] = nil
|
flickerstreak@22
|
1243 end
|
flickerstreak@22
|
1244 end
|
flickerstreak@22
|
1245 end
|
flickerstreak@22
|
1246 if db.namespaces then
|
flickerstreak@22
|
1247 for name,v in pairs(db.namespaces) do
|
flickerstreak@22
|
1248 rawset(v, 'class', nil)
|
flickerstreak@22
|
1249 end
|
flickerstreak@22
|
1250 end
|
flickerstreak@22
|
1251 else
|
flickerstreak@22
|
1252 if db.raw.namespaces then
|
flickerstreak@22
|
1253 local v = db.raw.namespaces[name]
|
flickerstreak@22
|
1254 if v and v.classes then
|
flickerstreak@1
|
1255 v.classes[classID] = nil
|
flickerstreak@1
|
1256 end
|
flickerstreak@1
|
1257 end
|
flickerstreak@22
|
1258 if db.namespaces then
|
flickerstreak@22
|
1259 local v = db.namespaces[name]
|
flickerstreak@22
|
1260 if v then
|
flickerstreak@22
|
1261 rawset(v, 'class', nil)
|
flickerstreak@22
|
1262 end
|
flickerstreak@1
|
1263 end
|
flickerstreak@1
|
1264 end
|
flickerstreak@1
|
1265 elseif kind == "profile" then
|
flickerstreak@22
|
1266 local id = db.raw.currentProfile and db.raw.currentProfile[charID] or AceDB.registry[self] or "Default"
|
flickerstreak@1
|
1267 if id == "char" then
|
flickerstreak@1
|
1268 id = "char/" .. charID
|
flickerstreak@1
|
1269 elseif id == "class" then
|
flickerstreak@1
|
1270 id = "class/" .. classID
|
flickerstreak@1
|
1271 elseif id == "realm" then
|
flickerstreak@1
|
1272 id = "realm/" .. realmID
|
flickerstreak@1
|
1273 end
|
flickerstreak@22
|
1274
|
flickerstreak@22
|
1275 local current = self.class
|
flickerstreak@22
|
1276 while current and current ~= AceOO.Class do
|
flickerstreak@22
|
1277 if current.mixins then
|
flickerstreak@22
|
1278 for mixin in pairs(current.mixins) do
|
flickerstreak@22
|
1279 if type(mixin.OnEmbedProfileDisable) == "function" then
|
flickerstreak@22
|
1280 safecall(mixin.OnEmbedProfileDisable, mixin, self, id)
|
flickerstreak@22
|
1281 end
|
flickerstreak@22
|
1282 end
|
flickerstreak@22
|
1283 end
|
flickerstreak@22
|
1284 current = current.super
|
flickerstreak@1
|
1285 end
|
flickerstreak@22
|
1286 if type(self.OnProfileDisable) == "function" then
|
flickerstreak@22
|
1287 safecall(self.OnProfileDisable, self, id)
|
flickerstreak@22
|
1288 end
|
flickerstreak@22
|
1289 local active = self:IsActive()
|
flickerstreak@22
|
1290
|
flickerstreak@22
|
1291 if not name then
|
flickerstreak@22
|
1292 if db.raw.profiles then
|
flickerstreak@22
|
1293 db.raw.profiles[id] = nil
|
flickerstreak@22
|
1294 end
|
flickerstreak@22
|
1295 rawset(db, 'profile', nil)
|
flickerstreak@22
|
1296 if db.raw.namespaces then
|
flickerstreak@22
|
1297 for name,v in pairs(db.raw.namespaces) do
|
flickerstreak@22
|
1298 if v.profiles then
|
flickerstreak@22
|
1299 v.profiles[id] = nil
|
flickerstreak@22
|
1300 end
|
flickerstreak@22
|
1301 end
|
flickerstreak@22
|
1302 end
|
flickerstreak@22
|
1303 if db.namespaces then
|
flickerstreak@22
|
1304 for name,v in pairs(db.namespaces) do
|
flickerstreak@22
|
1305 rawset(v, 'profile', nil)
|
flickerstreak@22
|
1306 end
|
flickerstreak@22
|
1307 end
|
flickerstreak@22
|
1308 else
|
flickerstreak@22
|
1309 if db.raw.namespaces then
|
flickerstreak@22
|
1310 local v = db.raw.namespaces[name]
|
flickerstreak@22
|
1311 if v and v.profiles then
|
flickerstreak@1
|
1312 v.profiles[id] = nil
|
flickerstreak@1
|
1313 end
|
flickerstreak@1
|
1314 end
|
flickerstreak@22
|
1315 if db.namespaces then
|
flickerstreak@22
|
1316 local v = db.namespaces[name]
|
flickerstreak@22
|
1317 if v then
|
flickerstreak@22
|
1318 rawset(v, 'profile', nil)
|
flickerstreak@22
|
1319 end
|
flickerstreak@1
|
1320 end
|
flickerstreak@1
|
1321 end
|
flickerstreak@22
|
1322
|
flickerstreak@22
|
1323 local current = self.class
|
flickerstreak@22
|
1324 while current and current ~= AceOO.Class do
|
flickerstreak@22
|
1325 if current.mixins then
|
flickerstreak@22
|
1326 for mixin in pairs(current.mixins) do
|
flickerstreak@22
|
1327 if type(mixin.OnEmbedProfileEnable) == "function" then
|
flickerstreak@22
|
1328 safecall(mixin.OnEmbedProfileEnable, mixin, self, id)
|
flickerstreak@22
|
1329 end
|
flickerstreak@22
|
1330 end
|
flickerstreak@22
|
1331 end
|
flickerstreak@22
|
1332 current = current.super
|
flickerstreak@22
|
1333 end
|
flickerstreak@22
|
1334 if type(self.OnProfileEnable) == "function" then
|
flickerstreak@22
|
1335 safecall(self.OnProfileEnable, self, id)
|
flickerstreak@22
|
1336 end
|
flickerstreak@22
|
1337 local newactive = self:IsActive()
|
flickerstreak@22
|
1338 if active ~= newactive then
|
flickerstreak@22
|
1339 if newactive then
|
flickerstreak@22
|
1340 local first = nil
|
flickerstreak@22
|
1341 if AceOO.inherits(self, "AceAddon-2.0") then
|
flickerstreak@22
|
1342 local AceAddon = AceLibrary("AceAddon-2.0")
|
flickerstreak@22
|
1343 if not AceAddon.addonsStarted[self] then
|
flickerstreak@22
|
1344 return
|
flickerstreak@22
|
1345 end
|
flickerstreak@22
|
1346 if AceAddon.addonsEnabled and not AceAddon.addonsEnabled[self] then
|
flickerstreak@22
|
1347 AceAddon.addonsEnabled[self] = true
|
flickerstreak@22
|
1348 first = true
|
flickerstreak@22
|
1349 end
|
flickerstreak@22
|
1350 end
|
flickerstreak@22
|
1351 local current = self.class
|
flickerstreak@22
|
1352 while current and current ~= AceOO.Class do
|
flickerstreak@22
|
1353 if current.mixins then
|
flickerstreak@22
|
1354 for mixin in pairs(current.mixins) do
|
flickerstreak@22
|
1355 if type(mixin.OnEmbedEnable) == "function" then
|
flickerstreak@22
|
1356 safecall(mixin.OnEmbedEnable, mixin, self, first)
|
flickerstreak@22
|
1357 end
|
flickerstreak@22
|
1358 end
|
flickerstreak@22
|
1359 end
|
flickerstreak@22
|
1360 current = current.super
|
flickerstreak@22
|
1361 end
|
flickerstreak@22
|
1362 if type(self.OnEnable) == "function" then
|
flickerstreak@22
|
1363 safecall(self.OnEnable, self, first)
|
flickerstreak@22
|
1364 end
|
flickerstreak@22
|
1365 if AceEvent then
|
flickerstreak@22
|
1366 AceEvent:TriggerEvent("Ace2_AddonEnabled", self, first)
|
flickerstreak@22
|
1367 end
|
flickerstreak@22
|
1368 else
|
flickerstreak@22
|
1369 local current = self.class
|
flickerstreak@22
|
1370 while current and current ~= AceOO.Class do
|
flickerstreak@22
|
1371 if current.mixins then
|
flickerstreak@22
|
1372 for mixin in pairs(current.mixins) do
|
flickerstreak@22
|
1373 if type(mixin.OnEmbedDisable) == "function" then
|
flickerstreak@22
|
1374 safecall(mixin.OnEmbedDisable, mixin, self)
|
flickerstreak@22
|
1375 end
|
flickerstreak@22
|
1376 end
|
flickerstreak@22
|
1377 end
|
flickerstreak@22
|
1378 current = current.super
|
flickerstreak@22
|
1379 end
|
flickerstreak@22
|
1380 if type(self.OnDisable) == "function" then
|
flickerstreak@22
|
1381 safecall(self.OnDisable, self)
|
flickerstreak@22
|
1382 end
|
flickerstreak@22
|
1383 if AceEvent then
|
flickerstreak@22
|
1384 AceEvent:TriggerEvent("Ace2_AddonDisabled", self)
|
flickerstreak@22
|
1385 end
|
flickerstreak@22
|
1386 end
|
flickerstreak@22
|
1387 end
|
flickerstreak@22
|
1388 else
|
flickerstreak@22
|
1389 return -- skip event
|
flickerstreak@22
|
1390 end
|
flickerstreak@22
|
1391 if AceEvent then
|
flickerstreak@22
|
1392 AceEvent:TriggerEvent("AceDB20_ResetDB", self, self.db.name, kind)
|
flickerstreak@1
|
1393 end
|
flickerstreak@1
|
1394 end
|
flickerstreak@1
|
1395
|
flickerstreak@22
|
1396 local function cleanDefaults(t, defaults, blocker)
|
flickerstreak@1
|
1397 if defaults then
|
flickerstreak@22
|
1398 for k,v in pairs(t) do
|
flickerstreak@22
|
1399 if (not blocker or (blocker[k] == nil and blocker['*'] == nil and blocker['**'] == nil)) and (defaults[k] ~= nil or defaults['*'] ~= nil or defaults['**'] ~= nil) then
|
flickerstreak@22
|
1400 local u = defaults[k]
|
flickerstreak@22
|
1401 if u == nil then
|
flickerstreak@22
|
1402 u = defaults['*']
|
flickerstreak@22
|
1403 if u == nil then
|
flickerstreak@22
|
1404 u = defaults['**']
|
flickerstreak@22
|
1405 end
|
flickerstreak@22
|
1406 end
|
flickerstreak@22
|
1407 if v == u then
|
flickerstreak@22
|
1408 t[k] = nil
|
flickerstreak@22
|
1409 elseif type(v) == "table" and type(u) == "table" then
|
flickerstreak@22
|
1410 if cleanDefaults(v, u) then
|
flickerstreak@22
|
1411 t[k] = nil
|
flickerstreak@22
|
1412 else
|
flickerstreak@22
|
1413 local w = defaults['**']
|
flickerstreak@22
|
1414 if w ~= u then
|
flickerstreak@22
|
1415 if cleanDefaults(v, w, u) then
|
flickerstreak@1
|
1416 t[k] = nil
|
flickerstreak@1
|
1417 end
|
flickerstreak@1
|
1418 end
|
flickerstreak@1
|
1419 end
|
flickerstreak@1
|
1420 end
|
flickerstreak@1
|
1421 end
|
flickerstreak@1
|
1422 end
|
flickerstreak@1
|
1423 end
|
flickerstreak@22
|
1424 return t and next(t) == nil
|
flickerstreak@1
|
1425 end
|
flickerstreak@1
|
1426
|
flickerstreak@1
|
1427 function AceDB:GetProfile()
|
flickerstreak@1
|
1428 if not self.db or not self.db.raw then
|
flickerstreak@1
|
1429 return nil
|
flickerstreak@1
|
1430 end
|
flickerstreak@1
|
1431 if not self.db.raw.currentProfile then
|
flickerstreak@1
|
1432 self.db.raw.currentProfile = {}
|
flickerstreak@1
|
1433 end
|
flickerstreak@1
|
1434 if not self.db.raw.currentProfile[charID] then
|
flickerstreak@22
|
1435 self.db.raw.currentProfile[charID] = AceDB.registry[self] or "Default"
|
flickerstreak@1
|
1436 end
|
flickerstreak@1
|
1437 local profile = self.db.raw.currentProfile[charID]
|
flickerstreak@1
|
1438 if profile == "char" then
|
flickerstreak@1
|
1439 return "char", "char/" .. charID
|
flickerstreak@1
|
1440 elseif profile == "class" then
|
flickerstreak@1
|
1441 return "class", "class/" .. classID
|
flickerstreak@1
|
1442 elseif profile == "realm" then
|
flickerstreak@1
|
1443 return "realm", "realm/" .. realmID
|
flickerstreak@1
|
1444 end
|
flickerstreak@1
|
1445 return profile, profile
|
flickerstreak@1
|
1446 end
|
flickerstreak@1
|
1447
|
flickerstreak@1
|
1448 local function copyTable(to, from)
|
flickerstreak@1
|
1449 setmetatable(to, nil)
|
flickerstreak@1
|
1450 for k,v in pairs(from) do
|
flickerstreak@1
|
1451 if type(k) == "table" then
|
flickerstreak@1
|
1452 k = copyTable({}, k)
|
flickerstreak@1
|
1453 end
|
flickerstreak@1
|
1454 if type(v) == "table" then
|
flickerstreak@1
|
1455 v = copyTable({}, v)
|
flickerstreak@1
|
1456 end
|
flickerstreak@1
|
1457 to[k] = v
|
flickerstreak@1
|
1458 end
|
flickerstreak@1
|
1459 setmetatable(to, from)
|
flickerstreak@1
|
1460 return to
|
flickerstreak@1
|
1461 end
|
flickerstreak@1
|
1462
|
flickerstreak@1
|
1463 function AceDB:SetProfile(name)
|
flickerstreak@1
|
1464 AceDB:argCheck(name, 2, "string")
|
flickerstreak@1
|
1465 if not self.db or not self.db.raw then
|
flickerstreak@1
|
1466 AceDB:error("Cannot call \"SetProfile\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.")
|
flickerstreak@1
|
1467 end
|
flickerstreak@1
|
1468 local db = self.db
|
flickerstreak@22
|
1469 local lowerName = name:lower()
|
flickerstreak@22
|
1470 if lowerName:find("^char/") or lowerName:find("^realm/") or lowerName:find("^class/") then
|
flickerstreak@22
|
1471 if lowerName:find("^char/") then
|
flickerstreak@1
|
1472 name = "char"
|
flickerstreak@1
|
1473 else
|
flickerstreak@22
|
1474 name = lowerName:sub(1, 5)
|
flickerstreak@1
|
1475 end
|
flickerstreak@22
|
1476 lowerName = name:lower()
|
flickerstreak@1
|
1477 end
|
flickerstreak@1
|
1478 local oldName = db.raw.currentProfile[charID]
|
flickerstreak@22
|
1479 if oldName:lower() == name:lower() then
|
flickerstreak@1
|
1480 return
|
flickerstreak@1
|
1481 end
|
flickerstreak@1
|
1482 local oldProfileData = db.profile
|
flickerstreak@1
|
1483 local realName = name
|
flickerstreak@1
|
1484 if lowerName == "char" then
|
flickerstreak@1
|
1485 realName = name .. "/" .. charID
|
flickerstreak@1
|
1486 elseif lowerName == "realm" then
|
flickerstreak@1
|
1487 realName = name .. "/" .. realmID
|
flickerstreak@1
|
1488 elseif lowerName == "class" then
|
flickerstreak@1
|
1489 realName = name .. "/" .. classID
|
flickerstreak@1
|
1490 end
|
flickerstreak@1
|
1491 local current = self.class
|
flickerstreak@1
|
1492 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1493 if current.mixins then
|
flickerstreak@1
|
1494 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1495 if type(mixin.OnEmbedProfileDisable) == "function" then
|
flickerstreak@1
|
1496 safecall(mixin.OnEmbedProfileDisable, mixin, self, realName)
|
flickerstreak@1
|
1497 end
|
flickerstreak@1
|
1498 end
|
flickerstreak@1
|
1499 end
|
flickerstreak@1
|
1500 current = current.super
|
flickerstreak@1
|
1501 end
|
flickerstreak@1
|
1502 if type(self.OnProfileDisable) == "function" then
|
flickerstreak@1
|
1503 safecall(self.OnProfileDisable, self, realName)
|
flickerstreak@1
|
1504 end
|
flickerstreak@1
|
1505 local active = self:IsActive()
|
flickerstreak@1
|
1506 db.raw.currentProfile[charID] = name
|
flickerstreak@1
|
1507 rawset(db, 'profile', nil)
|
flickerstreak@1
|
1508 if db.namespaces then
|
flickerstreak@1
|
1509 for k,v in pairs(db.namespaces) do
|
flickerstreak@1
|
1510 rawset(v, 'profile', nil)
|
flickerstreak@1
|
1511 end
|
flickerstreak@1
|
1512 end
|
flickerstreak@1
|
1513 local current = self.class
|
flickerstreak@1
|
1514 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1515 if current.mixins then
|
flickerstreak@1
|
1516 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1517 if type(mixin.OnEmbedProfileEnable) == "function" then
|
flickerstreak@1
|
1518 safecall(mixin.OnEmbedProfileEnable, mixin, self, oldName, oldProfileData)
|
flickerstreak@1
|
1519 end
|
flickerstreak@1
|
1520 end
|
flickerstreak@1
|
1521 end
|
flickerstreak@1
|
1522 current = current.super
|
flickerstreak@1
|
1523 end
|
flickerstreak@1
|
1524 if type(self.OnProfileEnable) == "function" then
|
flickerstreak@1
|
1525 safecall(self.OnProfileEnable, self, oldName, oldProfileData)
|
flickerstreak@1
|
1526 end
|
flickerstreak@1
|
1527 if cleanDefaults(oldProfileData, db.defaults and db.defaults.profile) then
|
flickerstreak@1
|
1528 db.raw.profiles[oldName] = nil
|
flickerstreak@1
|
1529 if not next(db.raw.profiles) then
|
flickerstreak@1
|
1530 db.raw.profiles = nil
|
flickerstreak@1
|
1531 end
|
flickerstreak@1
|
1532 end
|
flickerstreak@1
|
1533 local newactive = self:IsActive()
|
flickerstreak@1
|
1534 if active ~= newactive then
|
flickerstreak@22
|
1535 local first = nil
|
flickerstreak@1
|
1536 if AceOO.inherits(self, "AceAddon-2.0") then
|
flickerstreak@1
|
1537 local AceAddon = AceLibrary("AceAddon-2.0")
|
flickerstreak@1
|
1538 if not AceAddon.addonsStarted[self] then
|
flickerstreak@1
|
1539 return
|
flickerstreak@1
|
1540 end
|
flickerstreak@22
|
1541 if AceAddon.addonsEnabled and not AceAddon.addonsEnabled[self] then
|
flickerstreak@22
|
1542 first = true
|
flickerstreak@22
|
1543 end
|
flickerstreak@1
|
1544 end
|
flickerstreak@1
|
1545 if newactive then
|
flickerstreak@1
|
1546 local current = self.class
|
flickerstreak@1
|
1547 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1548 if current.mixins then
|
flickerstreak@1
|
1549 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1550 if type(mixin.OnEmbedEnable) == "function" then
|
flickerstreak@22
|
1551 safecall(mixin.OnEmbedEnable, mixin, self, first)
|
flickerstreak@1
|
1552 end
|
flickerstreak@1
|
1553 end
|
flickerstreak@1
|
1554 end
|
flickerstreak@1
|
1555 current = current.super
|
flickerstreak@1
|
1556 end
|
flickerstreak@1
|
1557 if type(self.OnEnable) == "function" then
|
flickerstreak@22
|
1558 safecall(self.OnEnable, self, first)
|
flickerstreak@1
|
1559 end
|
flickerstreak@1
|
1560 if AceEvent then
|
flickerstreak@22
|
1561 AceEvent:TriggerEvent("Ace2_AddonEnabled", self, first)
|
flickerstreak@1
|
1562 end
|
flickerstreak@1
|
1563 else
|
flickerstreak@1
|
1564 local current = self.class
|
flickerstreak@1
|
1565 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1566 if current.mixins then
|
flickerstreak@1
|
1567 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1568 if type(mixin.OnEmbedDisable) == "function" then
|
flickerstreak@1
|
1569 safecall(mixin.OnEmbedDisable, mixin, self)
|
flickerstreak@1
|
1570 end
|
flickerstreak@1
|
1571 end
|
flickerstreak@1
|
1572 end
|
flickerstreak@1
|
1573 current = current.super
|
flickerstreak@1
|
1574 end
|
flickerstreak@1
|
1575 if type(self.OnDisable) == "function" then
|
flickerstreak@1
|
1576 safecall(self.OnDisable, self)
|
flickerstreak@1
|
1577 end
|
flickerstreak@1
|
1578 if AceEvent then
|
flickerstreak@1
|
1579 AceEvent:TriggerEvent("Ace2_AddonDisabled", self)
|
flickerstreak@1
|
1580 end
|
flickerstreak@1
|
1581 end
|
flickerstreak@1
|
1582 end
|
flickerstreak@1
|
1583 if self['acedb-profile-list'] then
|
flickerstreak@1
|
1584 RecalculateAceDBProfileList(self)
|
flickerstreak@1
|
1585 end
|
flickerstreak@1
|
1586 if self['acedb-profile-copylist'] then
|
flickerstreak@1
|
1587 RecalculateAceDBCopyFromList(self)
|
flickerstreak@1
|
1588 end
|
flickerstreak@1
|
1589 if Dewdrop then
|
flickerstreak@22
|
1590 Dewdrop:Refresh()
|
flickerstreak@1
|
1591 end
|
flickerstreak@1
|
1592 end
|
flickerstreak@1
|
1593
|
flickerstreak@1
|
1594 function AceDB:CopyProfileFrom(copyFrom)
|
flickerstreak@1
|
1595 AceDB:argCheck(copyFrom, 2, "string")
|
flickerstreak@1
|
1596 if not self.db or not self.db.raw then
|
flickerstreak@1
|
1597 AceDB:error("Cannot call \"CopyProfileFrom\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.")
|
flickerstreak@1
|
1598 end
|
flickerstreak@1
|
1599 local db = self.db
|
flickerstreak@22
|
1600 local lowerCopyFrom = copyFrom:lower()
|
flickerstreak@1
|
1601 if not db.raw.profiles or not db.raw.profiles[copyFrom] then
|
flickerstreak@1
|
1602 local good = false
|
flickerstreak@1
|
1603 if db.raw.namespaces then
|
flickerstreak@1
|
1604 for _,n in pairs(db.raw.namespaces) do
|
flickerstreak@1
|
1605 if n.profiles and n.profiles[copyFrom] then
|
flickerstreak@1
|
1606 good = true
|
flickerstreak@1
|
1607 break
|
flickerstreak@1
|
1608 end
|
flickerstreak@1
|
1609 end
|
flickerstreak@1
|
1610 end
|
flickerstreak@1
|
1611 if not good then
|
flickerstreak@1
|
1612 AceDB:error("Cannot copy from profile %q, it does not exist.", copyFrom)
|
flickerstreak@1
|
1613 end
|
flickerstreak@1
|
1614 end
|
flickerstreak@1
|
1615 local currentProfile = db.raw.currentProfile[charID]
|
flickerstreak@22
|
1616 if currentProfile:lower() == lowerCopyFrom then
|
flickerstreak@1
|
1617 AceDB:error("Cannot copy from profile %q, it is currently in use.", copyFrom)
|
flickerstreak@1
|
1618 end
|
flickerstreak@1
|
1619 local oldProfileData = db.profile
|
flickerstreak@1
|
1620 local current = self.class
|
flickerstreak@1
|
1621 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1622 if current.mixins then
|
flickerstreak@1
|
1623 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1624 if type(mixin.OnEmbedProfileDisable) == "function" then
|
flickerstreak@1
|
1625 safecall(mixin.OnEmbedProfileDisable, mixin, self, currentProfile)
|
flickerstreak@1
|
1626 end
|
flickerstreak@1
|
1627 end
|
flickerstreak@1
|
1628 end
|
flickerstreak@1
|
1629 current = current.super
|
flickerstreak@1
|
1630 end
|
flickerstreak@1
|
1631 if type(self.OnProfileDisable) == "function" then
|
flickerstreak@1
|
1632 safecall(self.OnProfileDisable, self, realName)
|
flickerstreak@1
|
1633 end
|
flickerstreak@1
|
1634 local active = self:IsActive()
|
flickerstreak@1
|
1635 for k,v in pairs(db.profile) do
|
flickerstreak@1
|
1636 db.profile[k] = nil
|
flickerstreak@1
|
1637 end
|
flickerstreak@1
|
1638 if db.raw.profiles[copyFrom] then
|
flickerstreak@1
|
1639 copyTable(db.profile, db.raw.profiles[copyFrom])
|
flickerstreak@1
|
1640 end
|
flickerstreak@1
|
1641 inheritDefaults(db.profile, db.defaults and db.defaults.profile)
|
flickerstreak@1
|
1642 if db.namespaces then
|
flickerstreak@1
|
1643 for l,u in pairs(db.namespaces) do
|
flickerstreak@1
|
1644 for k,v in pairs(u.profile) do
|
flickerstreak@1
|
1645 u.profile[k] = nil
|
flickerstreak@1
|
1646 end
|
flickerstreak@1
|
1647 if db.raw.namespaces[l].profiles[copyFrom] then
|
flickerstreak@1
|
1648 copyTable(u.profile, db.raw.namespaces[l].profiles[copyFrom])
|
flickerstreak@1
|
1649 end
|
flickerstreak@1
|
1650 inheritDefaults(u.profile, u.defaults and u.defaults.profile)
|
flickerstreak@1
|
1651 end
|
flickerstreak@1
|
1652 end
|
flickerstreak@1
|
1653 local current = self.class
|
flickerstreak@1
|
1654 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1655 if current.mixins then
|
flickerstreak@1
|
1656 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1657 if type(mixin.OnEmbedProfileEnable) == "function" then
|
flickerstreak@1
|
1658 safecall(mixin.OnEmbedProfileEnable, mixin, self, copyFrom, oldProfileData, copyFrom)
|
flickerstreak@1
|
1659 end
|
flickerstreak@1
|
1660 end
|
flickerstreak@1
|
1661 end
|
flickerstreak@1
|
1662 current = current.super
|
flickerstreak@1
|
1663 end
|
flickerstreak@1
|
1664 if type(self.OnProfileEnable) == "function" then
|
flickerstreak@1
|
1665 safecall(self.OnProfileEnable, self, copyFrom, oldProfileData, copyFrom)
|
flickerstreak@1
|
1666 end
|
flickerstreak@1
|
1667 local newactive = self:IsActive()
|
flickerstreak@1
|
1668 if active ~= newactive then
|
flickerstreak@1
|
1669 if AceOO.inherits(self, "AceAddon-2.0") then
|
flickerstreak@1
|
1670 local AceAddon = AceLibrary("AceAddon-2.0")
|
flickerstreak@1
|
1671 if not AceAddon.addonsStarted[self] then
|
flickerstreak@1
|
1672 return
|
flickerstreak@1
|
1673 end
|
flickerstreak@1
|
1674 end
|
flickerstreak@1
|
1675 if newactive then
|
flickerstreak@1
|
1676 local current = self.class
|
flickerstreak@1
|
1677 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1678 if current.mixins then
|
flickerstreak@1
|
1679 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1680 if type(mixin.OnEmbedEnable) == "function" then
|
flickerstreak@1
|
1681 safecall(mixin.OnEmbedEnable, mixin, self)
|
flickerstreak@1
|
1682 end
|
flickerstreak@1
|
1683 end
|
flickerstreak@1
|
1684 end
|
flickerstreak@1
|
1685 current = current.super
|
flickerstreak@1
|
1686 end
|
flickerstreak@1
|
1687 if type(self.OnEnable) == "function" then
|
flickerstreak@1
|
1688 safecall(self.OnEnable, self)
|
flickerstreak@1
|
1689 end
|
flickerstreak@1
|
1690 if AceEvent then
|
flickerstreak@1
|
1691 AceEvent:TriggerEvent("Ace2_AddonEnabled", self)
|
flickerstreak@1
|
1692 end
|
flickerstreak@1
|
1693 else
|
flickerstreak@1
|
1694 local current = self.class
|
flickerstreak@1
|
1695 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1696 if current.mixins then
|
flickerstreak@1
|
1697 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1698 if type(mixin.OnEmbedDisable) == "function" then
|
flickerstreak@1
|
1699 safecall(mixin.OnEmbedDisable, mixin, self)
|
flickerstreak@1
|
1700 end
|
flickerstreak@1
|
1701 end
|
flickerstreak@1
|
1702 end
|
flickerstreak@1
|
1703 current = current.super
|
flickerstreak@1
|
1704 end
|
flickerstreak@1
|
1705 if type(self.OnDisable) == "function" then
|
flickerstreak@1
|
1706 safecall(self.OnDisable, self)
|
flickerstreak@1
|
1707 end
|
flickerstreak@1
|
1708 if AceEvent then
|
flickerstreak@1
|
1709 AceEvent:TriggerEvent("Ace2_AddonDisabled", self)
|
flickerstreak@1
|
1710 end
|
flickerstreak@1
|
1711 end
|
flickerstreak@1
|
1712 end
|
flickerstreak@1
|
1713 if self['acedb-profile-list'] then
|
flickerstreak@1
|
1714 RecalculateAceDBProfileList(self)
|
flickerstreak@1
|
1715 end
|
flickerstreak@1
|
1716 if self['acedb-profile-copylist'] then
|
flickerstreak@1
|
1717 RecalculateAceDBCopyFromList(self)
|
flickerstreak@1
|
1718 end
|
flickerstreak@1
|
1719 if Dewdrop then
|
flickerstreak@22
|
1720 Dewdrop:Refresh()
|
flickerstreak@22
|
1721 end
|
flickerstreak@22
|
1722 end
|
flickerstreak@22
|
1723
|
flickerstreak@22
|
1724 function AceDB:DeleteProfile(profile, noconfirm)
|
flickerstreak@22
|
1725 AceDB:argCheck(profile , 2, "string")
|
flickerstreak@22
|
1726 if not self.db or not self.db.raw then
|
flickerstreak@22
|
1727 AceDB:error("Cannot call \"DeleteProfile\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.")
|
flickerstreak@22
|
1728 end
|
flickerstreak@22
|
1729 local db = self.db
|
flickerstreak@22
|
1730
|
flickerstreak@22
|
1731 local currentProfile = db.raw.currentProfile[charID]
|
flickerstreak@22
|
1732 if currentProfile:lower() == profile:lower() then
|
flickerstreak@22
|
1733 AceDB:error("Cannot delete profile %q, it is currently in use.", profile)
|
flickerstreak@22
|
1734 end
|
flickerstreak@22
|
1735
|
flickerstreak@22
|
1736 if not (noconfirm or IsShiftKeyDown()) then
|
flickerstreak@22
|
1737 if not StaticPopupDialogs["ACEDB20_CONFIRM_DELETE_DIALOG"] then
|
flickerstreak@22
|
1738 StaticPopupDialogs["ACEDB20_CONFIRM_DELETE_DIALOG"] = {}
|
flickerstreak@22
|
1739 end
|
flickerstreak@22
|
1740 local t = StaticPopupDialogs["ACEDB20_CONFIRM_DELETE_DIALOG"]
|
flickerstreak@22
|
1741 t.text = format("%s: %s?", DELETE_PROFILE, profile)
|
flickerstreak@22
|
1742 t.button1 = DELETE_PROFILE
|
flickerstreak@22
|
1743 t.button2 = CANCEL or "Cancel"
|
flickerstreak@22
|
1744 t.OnAccept = function()
|
flickerstreak@22
|
1745 self:DeleteProfile(profile, true)
|
flickerstreak@22
|
1746 end
|
flickerstreak@22
|
1747 t.timeout = 0
|
flickerstreak@22
|
1748 t.whileDead = 1
|
flickerstreak@22
|
1749 t.hideOnEscape = 1
|
flickerstreak@22
|
1750
|
flickerstreak@22
|
1751 StaticPopup_Show("ACEDB20_CONFIRM_DELETE_DIALOG")
|
flickerstreak@22
|
1752 return;
|
flickerstreak@22
|
1753 end
|
flickerstreak@22
|
1754
|
flickerstreak@22
|
1755 local good = false
|
flickerstreak@22
|
1756 if db.raw.profiles and db.raw.profiles[profile] then
|
flickerstreak@22
|
1757 good = true;
|
flickerstreak@22
|
1758 db.raw.profiles[profile] = nil;
|
flickerstreak@22
|
1759 end
|
flickerstreak@22
|
1760
|
flickerstreak@22
|
1761 if db.raw.namespaces then
|
flickerstreak@22
|
1762 for _,n in pairs(db.raw.namespaces) do
|
flickerstreak@22
|
1763 if n.profiles and n.profiles[profile] then
|
flickerstreak@22
|
1764 n.profiles[profile] = nil;
|
flickerstreak@22
|
1765 good = true
|
flickerstreak@22
|
1766 end
|
flickerstreak@22
|
1767 end
|
flickerstreak@22
|
1768 end
|
flickerstreak@22
|
1769
|
flickerstreak@22
|
1770 if not good then
|
flickerstreak@22
|
1771 AceDB:error("Cannot delete profile %q, it does not exist.", profile)
|
flickerstreak@22
|
1772 end
|
flickerstreak@22
|
1773
|
flickerstreak@22
|
1774 if self['acedb-profile-list'] then
|
flickerstreak@22
|
1775 RecalculateAceDBProfileList(self)
|
flickerstreak@22
|
1776 end
|
flickerstreak@22
|
1777 if self['acedb-profile-copylist'] then
|
flickerstreak@22
|
1778 RecalculateAceDBCopyFromList(self)
|
flickerstreak@22
|
1779 end
|
flickerstreak@22
|
1780
|
flickerstreak@22
|
1781 if Dewdrop then
|
flickerstreak@22
|
1782 Dewdrop:Refresh()
|
flickerstreak@1
|
1783 end
|
flickerstreak@1
|
1784 end
|
flickerstreak@1
|
1785
|
flickerstreak@1
|
1786 function AceDB:IsActive()
|
flickerstreak@1
|
1787 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
|
1788 end
|
flickerstreak@1
|
1789
|
flickerstreak@1
|
1790 function AceDB:ToggleActive(state)
|
flickerstreak@1
|
1791 AceDB:argCheck(state, 2, "boolean", "nil")
|
flickerstreak@1
|
1792 if not self.db or not self.db.raw then
|
flickerstreak@1
|
1793 AceDB:error("Cannot call \"ToggleActive\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.")
|
flickerstreak@1
|
1794 end
|
flickerstreak@1
|
1795 local db = self.db
|
flickerstreak@1
|
1796 if not db.raw.disabled then
|
flickerstreak@1
|
1797 db.raw.disabled = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
1798 end
|
flickerstreak@1
|
1799 local profile = db.raw.currentProfile[charID]
|
flickerstreak@1
|
1800 local disable
|
flickerstreak@1
|
1801 if state == nil then
|
flickerstreak@1
|
1802 disable = not db.raw.disabled[profile]
|
flickerstreak@1
|
1803 else
|
flickerstreak@1
|
1804 disable = not state
|
flickerstreak@1
|
1805 if disable == db.raw.disabled[profile] then
|
flickerstreak@1
|
1806 return
|
flickerstreak@1
|
1807 end
|
flickerstreak@1
|
1808 end
|
flickerstreak@1
|
1809 db.raw.disabled[profile] = disable or nil
|
flickerstreak@1
|
1810 if AceOO.inherits(self, "AceAddon-2.0") then
|
flickerstreak@1
|
1811 local AceAddon = AceLibrary("AceAddon-2.0")
|
flickerstreak@1
|
1812 if not AceAddon.addonsStarted[self] then
|
flickerstreak@1
|
1813 return
|
flickerstreak@1
|
1814 end
|
flickerstreak@1
|
1815 end
|
flickerstreak@1
|
1816 if not disable then
|
flickerstreak@1
|
1817 local current = self.class
|
flickerstreak@1
|
1818 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1819 if current.mixins then
|
flickerstreak@1
|
1820 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1821 if type(mixin.OnEmbedEnable) == "function" then
|
flickerstreak@1
|
1822 safecall(mixin.OnEmbedEnable, mixin, self)
|
flickerstreak@1
|
1823 end
|
flickerstreak@1
|
1824 end
|
flickerstreak@1
|
1825 end
|
flickerstreak@1
|
1826 current = current.super
|
flickerstreak@1
|
1827 end
|
flickerstreak@1
|
1828 if type(self.OnEnable) == "function" then
|
flickerstreak@1
|
1829 safecall(self.OnEnable, self)
|
flickerstreak@1
|
1830 end
|
flickerstreak@1
|
1831 if AceEvent then
|
flickerstreak@1
|
1832 AceEvent:TriggerEvent("Ace2_AddonEnabled", self)
|
flickerstreak@1
|
1833 end
|
flickerstreak@1
|
1834 else
|
flickerstreak@1
|
1835 local current = self.class
|
flickerstreak@1
|
1836 while current and current ~= AceOO.Class do
|
flickerstreak@1
|
1837 if current.mixins then
|
flickerstreak@1
|
1838 for mixin in pairs(current.mixins) do
|
flickerstreak@1
|
1839 if type(mixin.OnEmbedDisable) == "function" then
|
flickerstreak@1
|
1840 safecall(mixin.OnEmbedDisable, mixin, self)
|
flickerstreak@1
|
1841 end
|
flickerstreak@1
|
1842 end
|
flickerstreak@1
|
1843 end
|
flickerstreak@1
|
1844 current = current.super
|
flickerstreak@1
|
1845 end
|
flickerstreak@1
|
1846 if type(self.OnDisable) == "function" then
|
flickerstreak@1
|
1847 safecall(self.OnDisable, self)
|
flickerstreak@1
|
1848 end
|
flickerstreak@1
|
1849 if AceEvent then
|
flickerstreak@1
|
1850 AceEvent:TriggerEvent("Ace2_AddonDisabled", self)
|
flickerstreak@1
|
1851 end
|
flickerstreak@1
|
1852 end
|
flickerstreak@1
|
1853 return not disable
|
flickerstreak@1
|
1854 end
|
flickerstreak@1
|
1855
|
flickerstreak@1
|
1856 function AceDB:embed(target)
|
flickerstreak@1
|
1857 self.super.embed(self, target)
|
flickerstreak@1
|
1858 if not AceEvent then
|
flickerstreak@1
|
1859 AceDB:error(MAJOR_VERSION .. " requires AceEvent-2.0")
|
flickerstreak@1
|
1860 end
|
flickerstreak@1
|
1861 end
|
flickerstreak@1
|
1862
|
flickerstreak@1
|
1863 function AceDB:ADDON_LOADED(name)
|
flickerstreak@1
|
1864 AceDB.addonsLoaded[name] = true
|
flickerstreak@1
|
1865 for addon, addonName in pairs(AceDB.addonsToBeInitialized) do
|
flickerstreak@1
|
1866 if name == addonName then
|
flickerstreak@1
|
1867 AceDB.InitializeDB(addon, name)
|
flickerstreak@1
|
1868 AceDB.addonsToBeInitialized[addon] = nil
|
flickerstreak@1
|
1869 end
|
flickerstreak@1
|
1870 end
|
flickerstreak@1
|
1871 end
|
flickerstreak@1
|
1872
|
flickerstreak@1
|
1873 function AceDB:PLAYER_LOGOUT()
|
flickerstreak@22
|
1874 for addon, defaultProfile in pairs(AceDB.registry) do
|
flickerstreak@1
|
1875 local db = addon.db
|
flickerstreak@1
|
1876 if db then
|
flickerstreak@22
|
1877 if type(addon.OnDatabaseCleanup) == "function" then
|
flickerstreak@22
|
1878 safecall(addon.OnDatabaseCleanup, addon)
|
flickerstreak@22
|
1879 end
|
flickerstreak@1
|
1880 setmetatable(db, nil)
|
flickerstreak@1
|
1881 CrawlForSerialization(db.raw)
|
flickerstreak@1
|
1882 if type(_G[db.charName]) == "table" then
|
flickerstreak@1
|
1883 CrawlForSerialization(_G[db.charName])
|
flickerstreak@1
|
1884 end
|
flickerstreak@1
|
1885 if db.char and cleanDefaults(db.char, db.defaults and db.defaults.char) then
|
flickerstreak@1
|
1886 if db.charName and _G[db.charName] and _G[db.charName].global == db.char then
|
flickerstreak@1
|
1887 _G[db.charName].global = nil
|
flickerstreak@1
|
1888 if not next(_G[db.charName]) then
|
flickerstreak@1
|
1889 _G[db.charName] = nil
|
flickerstreak@1
|
1890 end
|
flickerstreak@1
|
1891 else
|
flickerstreak@1
|
1892 if db.raw.chars then
|
flickerstreak@1
|
1893 db.raw.chars[charID] = nil
|
flickerstreak@1
|
1894 if not next(db.raw.chars) then
|
flickerstreak@1
|
1895 db.raw.chars = nil
|
flickerstreak@1
|
1896 end
|
flickerstreak@1
|
1897 end
|
flickerstreak@1
|
1898 end
|
flickerstreak@1
|
1899 end
|
flickerstreak@1
|
1900 if db.realm and cleanDefaults(db.realm, db.defaults and db.defaults.realm) then
|
flickerstreak@1
|
1901 if db.raw.realms then
|
flickerstreak@1
|
1902 db.raw.realms[realmID] = nil
|
flickerstreak@1
|
1903 if not next(db.raw.realms) then
|
flickerstreak@1
|
1904 db.raw.realms = nil
|
flickerstreak@1
|
1905 end
|
flickerstreak@1
|
1906 end
|
flickerstreak@1
|
1907 end
|
flickerstreak@22
|
1908 if db.server and cleanDefaults(db.server, db.defaults and db.defaults.server) then
|
flickerstreak@22
|
1909 if db.raw.servers then
|
flickerstreak@22
|
1910 db.raw.servers[server] = nil
|
flickerstreak@22
|
1911 if not next(db.raw.servers) then
|
flickerstreak@22
|
1912 db.raw.servers = nil
|
flickerstreak@22
|
1913 end
|
flickerstreak@22
|
1914 end
|
flickerstreak@22
|
1915 end
|
flickerstreak@1
|
1916 if db.faction and cleanDefaults(db.faction, db.defaults and db.defaults.faction) then
|
flickerstreak@1
|
1917 if db.raw.factions then
|
flickerstreak@1
|
1918 db.raw.factions[faction] = nil
|
flickerstreak@1
|
1919 if not next(db.raw.factions) then
|
flickerstreak@1
|
1920 db.raw.factions = nil
|
flickerstreak@1
|
1921 end
|
flickerstreak@1
|
1922 end
|
flickerstreak@1
|
1923 end
|
flickerstreak@1
|
1924 if db.class and cleanDefaults(db.class, db.defaults and db.defaults.class) then
|
flickerstreak@1
|
1925 if db.raw.classes then
|
flickerstreak@1
|
1926 db.raw.classes[classID] = nil
|
flickerstreak@1
|
1927 if not next(db.raw.classes) then
|
flickerstreak@1
|
1928 db.raw.classes = nil
|
flickerstreak@1
|
1929 end
|
flickerstreak@1
|
1930 end
|
flickerstreak@1
|
1931 end
|
flickerstreak@1
|
1932 if db.account and cleanDefaults(db.account, db.defaults and db.defaults.account) then
|
flickerstreak@1
|
1933 db.raw.account = nil
|
flickerstreak@1
|
1934 end
|
flickerstreak@1
|
1935 if db.profile and cleanDefaults(db.profile, db.defaults and db.defaults.profile) then
|
flickerstreak@1
|
1936 if db.raw.profiles then
|
flickerstreak@22
|
1937 db.raw.profiles[db.raw.currentProfile and db.raw.currentProfile[charID] or defaultProfile or "Default"] = nil
|
flickerstreak@1
|
1938 if not next(db.raw.profiles) then
|
flickerstreak@1
|
1939 db.raw.profiles = nil
|
flickerstreak@1
|
1940 end
|
flickerstreak@1
|
1941 end
|
flickerstreak@1
|
1942 end
|
flickerstreak@1
|
1943 if db.namespaces and db.raw.namespaces then
|
flickerstreak@1
|
1944 for name,v in pairs(db.namespaces) do
|
flickerstreak@1
|
1945 if db.raw.namespaces[name] then
|
flickerstreak@1
|
1946 setmetatable(v, nil)
|
flickerstreak@1
|
1947 if v.char and cleanDefaults(v.char, v.defaults and v.defaults.char) then
|
flickerstreak@1
|
1948 if db.charName and _G[db.charName] and _G[db.charName].namespaces and _G[db.charName].namespaces[name] == v then
|
flickerstreak@1
|
1949 _G[db.charName].namespaces[name] = nil
|
flickerstreak@1
|
1950 if not next(_G[db.charName].namespaces) then
|
flickerstreak@1
|
1951 _G[db.charName].namespaces = nil
|
flickerstreak@1
|
1952 if not next(_G[db.charName]) then
|
flickerstreak@1
|
1953 _G[db.charName] = nil
|
flickerstreak@1
|
1954 end
|
flickerstreak@1
|
1955 end
|
flickerstreak@1
|
1956 else
|
flickerstreak@1
|
1957 if db.raw.namespaces[name].chars then
|
flickerstreak@1
|
1958 db.raw.namespaces[name].chars[charID] = nil
|
flickerstreak@1
|
1959 if not next(db.raw.namespaces[name].chars) then
|
flickerstreak@1
|
1960 db.raw.namespaces[name].chars = nil
|
flickerstreak@1
|
1961 end
|
flickerstreak@1
|
1962 end
|
flickerstreak@1
|
1963 end
|
flickerstreak@1
|
1964 end
|
flickerstreak@1
|
1965 if v.realm and cleanDefaults(v.realm, v.defaults and v.defaults.realm) then
|
flickerstreak@1
|
1966 if db.raw.namespaces[name].realms then
|
flickerstreak@1
|
1967 db.raw.namespaces[name].realms[realmID] = nil
|
flickerstreak@1
|
1968 if not next(db.raw.namespaces[name].realms) then
|
flickerstreak@1
|
1969 db.raw.namespaces[name].realms = nil
|
flickerstreak@1
|
1970 end
|
flickerstreak@1
|
1971 end
|
flickerstreak@1
|
1972 end
|
flickerstreak@22
|
1973 if v.server and cleanDefaults(v.server, v.defaults and v.defaults.server) then
|
flickerstreak@22
|
1974 if db.raw.namespaces[name].servers then
|
flickerstreak@22
|
1975 db.raw.namespaces[name].servers[server] = nil
|
flickerstreak@22
|
1976 if not next(db.raw.namespaces[name].servers) then
|
flickerstreak@22
|
1977 db.raw.namespaces[name].servers = nil
|
flickerstreak@22
|
1978 end
|
flickerstreak@22
|
1979 end
|
flickerstreak@22
|
1980 end
|
flickerstreak@1
|
1981 if v.faction and cleanDefaults(v.faction, v.defaults and v.defaults.faction) then
|
flickerstreak@1
|
1982 if db.raw.namespaces[name].factions then
|
flickerstreak@1
|
1983 db.raw.namespaces[name].factions[faction] = nil
|
flickerstreak@1
|
1984 if not next(db.raw.namespaces[name].factions) then
|
flickerstreak@1
|
1985 db.raw.namespaces[name].factions = nil
|
flickerstreak@1
|
1986 end
|
flickerstreak@1
|
1987 end
|
flickerstreak@1
|
1988 end
|
flickerstreak@1
|
1989 if v.class and cleanDefaults(v.class, v.defaults and v.defaults.class) then
|
flickerstreak@1
|
1990 if db.raw.namespaces[name].classes then
|
flickerstreak@1
|
1991 db.raw.namespaces[name].classes[classID] = nil
|
flickerstreak@1
|
1992 if not next(db.raw.namespaces[name].classes) then
|
flickerstreak@1
|
1993 db.raw.namespaces[name].classes = nil
|
flickerstreak@1
|
1994 end
|
flickerstreak@1
|
1995 end
|
flickerstreak@1
|
1996 end
|
flickerstreak@1
|
1997 if v.account and cleanDefaults(v.account, v.defaults and v.defaults.account) then
|
flickerstreak@1
|
1998 db.raw.namespaces[name].account = nil
|
flickerstreak@1
|
1999 end
|
flickerstreak@1
|
2000 if v.profile and cleanDefaults(v.profile, v.defaults and v.defaults.profile) then
|
flickerstreak@1
|
2001 if db.raw.namespaces[name].profiles then
|
flickerstreak@22
|
2002 db.raw.namespaces[name].profiles[db.raw.currentProfile and db.raw.currentProfile[charID] or defaultProfile or "Default"] = nil
|
flickerstreak@1
|
2003 if not next(db.raw.namespaces[name].profiles) then
|
flickerstreak@1
|
2004 db.raw.namespaces[name].profiles = nil
|
flickerstreak@1
|
2005 end
|
flickerstreak@1
|
2006 end
|
flickerstreak@1
|
2007 end
|
flickerstreak@1
|
2008 if not next(db.raw.namespaces[name]) then
|
flickerstreak@1
|
2009 db.raw.namespaces[name] = nil
|
flickerstreak@1
|
2010 end
|
flickerstreak@1
|
2011 end
|
flickerstreak@1
|
2012 end
|
flickerstreak@1
|
2013 if not next(db.raw.namespaces) then
|
flickerstreak@1
|
2014 db.raw.namespaces = nil
|
flickerstreak@1
|
2015 end
|
flickerstreak@1
|
2016 end
|
flickerstreak@1
|
2017 if db.raw.disabled and not next(db.raw.disabled) then
|
flickerstreak@1
|
2018 db.raw.disabled = nil
|
flickerstreak@1
|
2019 end
|
flickerstreak@1
|
2020 if db.raw.currentProfile then
|
flickerstreak@1
|
2021 for k,v in pairs(db.raw.currentProfile) do
|
flickerstreak@22
|
2022 if v:lower() == (defaultProfile or "Default"):lower() then
|
flickerstreak@1
|
2023 db.raw.currentProfile[k] = nil
|
flickerstreak@1
|
2024 end
|
flickerstreak@1
|
2025 end
|
flickerstreak@1
|
2026 if not next(db.raw.currentProfile) then
|
flickerstreak@1
|
2027 db.raw.currentProfile = nil
|
flickerstreak@1
|
2028 end
|
flickerstreak@1
|
2029 end
|
flickerstreak@1
|
2030 if _G[db.name] and not next(_G[db.name]) then
|
flickerstreak@1
|
2031 _G[db.name] = nil
|
flickerstreak@1
|
2032 end
|
flickerstreak@1
|
2033 end
|
flickerstreak@1
|
2034 end
|
flickerstreak@1
|
2035 end
|
flickerstreak@1
|
2036
|
flickerstreak@1
|
2037 function AceDB:AcquireDBNamespace(name)
|
flickerstreak@1
|
2038 AceDB:argCheck(name, 2, "string")
|
flickerstreak@1
|
2039 local db = self.db
|
flickerstreak@1
|
2040 if not db then
|
flickerstreak@1
|
2041 AceDB:error("Cannot call `AcquireDBNamespace' before `RegisterDB' has been called.", 2)
|
flickerstreak@1
|
2042 end
|
flickerstreak@1
|
2043 if not db.namespaces then
|
flickerstreak@1
|
2044 rawset(db, 'namespaces', {})
|
flickerstreak@1
|
2045 end
|
flickerstreak@1
|
2046 if not db.namespaces[name] then
|
flickerstreak@1
|
2047 local namespace = {}
|
flickerstreak@1
|
2048 db.namespaces[name] = namespace
|
flickerstreak@1
|
2049 namespace.db = db
|
flickerstreak@1
|
2050 namespace.name = name
|
flickerstreak@1
|
2051 setmetatable(namespace, namespace_mt)
|
flickerstreak@1
|
2052 end
|
flickerstreak@1
|
2053 return db.namespaces[name]
|
flickerstreak@1
|
2054 end
|
flickerstreak@1
|
2055
|
flickerstreak@1
|
2056 function AceDB:GetAceOptionsDataTable(target)
|
flickerstreak@1
|
2057 if not target['acedb-profile-list'] then
|
flickerstreak@1
|
2058 target['acedb-profile-list'] = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
2059 RecalculateAceDBProfileList(target)
|
flickerstreak@1
|
2060 end
|
flickerstreak@1
|
2061 if not target['acedb-profile-copylist'] then
|
flickerstreak@1
|
2062 target['acedb-profile-copylist'] = setmetatable({}, caseInsensitive_mt)
|
flickerstreak@1
|
2063 RecalculateAceDBCopyFromList(target)
|
flickerstreak@1
|
2064 end
|
flickerstreak@1
|
2065 return {
|
flickerstreak@1
|
2066 standby = {
|
flickerstreak@1
|
2067 cmdName = STATE,
|
flickerstreak@1
|
2068 guiName = ENABLED,
|
flickerstreak@1
|
2069 name = ACTIVE,
|
flickerstreak@1
|
2070 desc = TOGGLE_ACTIVE,
|
flickerstreak@1
|
2071 type = "toggle",
|
flickerstreak@1
|
2072 get = "IsActive",
|
flickerstreak@1
|
2073 set = "ToggleActive",
|
flickerstreak@1
|
2074 map = MAP_ACTIVESUSPENDED,
|
flickerstreak@1
|
2075 order = -3,
|
flickerstreak@1
|
2076 },
|
flickerstreak@1
|
2077 profile = {
|
flickerstreak@1
|
2078 type = 'group',
|
flickerstreak@1
|
2079 name = PROFILE,
|
flickerstreak@1
|
2080 desc = SET_PROFILE,
|
flickerstreak@1
|
2081 order = -3.5,
|
flickerstreak@1
|
2082 get = "GetProfile",
|
flickerstreak@1
|
2083 args = {
|
flickerstreak@1
|
2084 choose = {
|
flickerstreak@1
|
2085 guiName = CHOOSE_PROFILE_GUI,
|
flickerstreak@1
|
2086 cmdName = PROFILE,
|
flickerstreak@1
|
2087 desc = CHOOSE_PROFILE_DESC,
|
flickerstreak@1
|
2088 type = 'text',
|
flickerstreak@1
|
2089 get = "GetProfile",
|
flickerstreak@1
|
2090 set = "SetProfile",
|
flickerstreak@1
|
2091 validate = target['acedb-profile-list']
|
flickerstreak@1
|
2092 },
|
flickerstreak@1
|
2093 copy = {
|
flickerstreak@1
|
2094 guiName = COPY_PROFILE_GUI,
|
flickerstreak@1
|
2095 cmdName = PROFILE,
|
flickerstreak@1
|
2096 desc = COPY_PROFILE_DESC,
|
flickerstreak@1
|
2097 type = 'text',
|
flickerstreak@1
|
2098 get = false,
|
flickerstreak@1
|
2099 set = "CopyProfileFrom",
|
flickerstreak@1
|
2100 validate = target['acedb-profile-copylist'],
|
flickerstreak@1
|
2101 disabled = function()
|
flickerstreak@1
|
2102 return not next(target['acedb-profile-copylist'])
|
flickerstreak@1
|
2103 end,
|
flickerstreak@1
|
2104 },
|
flickerstreak@1
|
2105 other = {
|
flickerstreak@1
|
2106 guiName = OTHER_PROFILE_GUI,
|
flickerstreak@1
|
2107 cmdName = PROFILE,
|
flickerstreak@1
|
2108 desc = OTHER_PROFILE_DESC,
|
flickerstreak@1
|
2109 usage = OTHER_PROFILE_USAGE,
|
flickerstreak@1
|
2110 type = 'text',
|
flickerstreak@1
|
2111 get = "GetProfile",
|
flickerstreak@1
|
2112 set = "SetProfile",
|
flickerstreak@22
|
2113 },
|
flickerstreak@22
|
2114 delete = {
|
flickerstreak@22
|
2115 name = DELETE_PROFILE,
|
flickerstreak@22
|
2116 desc = DELETE_PROFILE_DESC,
|
flickerstreak@22
|
2117 usage = DELETE_PROFILE_USAGE,
|
flickerstreak@22
|
2118 type = 'text',
|
flickerstreak@22
|
2119 set = "DeleteProfile",
|
flickerstreak@22
|
2120 get = false,
|
flickerstreak@22
|
2121 validate = target['acedb-profile-copylist'],
|
flickerstreak@22
|
2122 disabled = function()
|
flickerstreak@22
|
2123 return not next(target['acedb-profile-copylist'])
|
flickerstreak@22
|
2124 end,
|
flickerstreak@22
|
2125 },
|
flickerstreak@22
|
2126 reset = {
|
flickerstreak@22
|
2127 name = RESET_PROFILE,
|
flickerstreak@22
|
2128 desc = RESET_PROFILE_DESC,
|
flickerstreak@22
|
2129 type = 'execute',
|
flickerstreak@22
|
2130 func = function()
|
flickerstreak@22
|
2131 target:ResetDB('profile')
|
flickerstreak@22
|
2132 end,
|
flickerstreak@22
|
2133 confirm = true,
|
flickerstreak@1
|
2134 }
|
flickerstreak@1
|
2135 }
|
flickerstreak@1
|
2136 },
|
flickerstreak@1
|
2137 }
|
flickerstreak@1
|
2138 end
|
flickerstreak@1
|
2139
|
flickerstreak@1
|
2140 local function activate(self, oldLib, oldDeactivate)
|
flickerstreak@1
|
2141 AceDB = self
|
flickerstreak@1
|
2142 AceEvent = AceLibrary:HasInstance("AceEvent-2.0") and AceLibrary("AceEvent-2.0")
|
flickerstreak@22
|
2143
|
flickerstreak@1
|
2144 self.addonsToBeInitialized = oldLib and oldLib.addonsToBeInitialized or {}
|
flickerstreak@1
|
2145 self.addonsLoaded = oldLib and oldLib.addonsLoaded or {}
|
flickerstreak@1
|
2146 self.registry = oldLib and oldLib.registry or {}
|
flickerstreak@22
|
2147 for k, v in pairs(self.registry) do
|
flickerstreak@22
|
2148 if v == true then
|
flickerstreak@22
|
2149 self.registry[k] = "Default"
|
flickerstreak@22
|
2150 end
|
flickerstreak@22
|
2151 end
|
flickerstreak@22
|
2152
|
flickerstreak@1
|
2153 self:activate(oldLib, oldDeactivate)
|
flickerstreak@22
|
2154
|
flickerstreak@1
|
2155 for t in pairs(self.embedList) do
|
flickerstreak@1
|
2156 if t.db then
|
flickerstreak@1
|
2157 rawset(t.db, 'char', nil)
|
flickerstreak@1
|
2158 rawset(t.db, 'realm', nil)
|
flickerstreak@1
|
2159 rawset(t.db, 'class', nil)
|
flickerstreak@1
|
2160 rawset(t.db, 'account', nil)
|
flickerstreak@22
|
2161 rawset(t.db, 'server', nil)
|
flickerstreak@1
|
2162 rawset(t.db, 'faction', nil)
|
flickerstreak@1
|
2163 rawset(t.db, 'profile', nil)
|
flickerstreak@1
|
2164 setmetatable(t.db, db_mt)
|
flickerstreak@1
|
2165 end
|
flickerstreak@1
|
2166 end
|
flickerstreak@22
|
2167
|
flickerstreak@1
|
2168 if oldLib then
|
flickerstreak@1
|
2169 oldDeactivate(oldLib)
|
flickerstreak@1
|
2170 end
|
flickerstreak@1
|
2171 end
|
flickerstreak@1
|
2172
|
flickerstreak@1
|
2173 local function external(self, major, instance)
|
flickerstreak@1
|
2174 if major == "AceEvent-2.0" then
|
flickerstreak@1
|
2175 AceEvent = instance
|
flickerstreak@22
|
2176
|
flickerstreak@1
|
2177 AceEvent:embed(self)
|
flickerstreak@22
|
2178
|
flickerstreak@1
|
2179 self:RegisterEvent("ADDON_LOADED")
|
flickerstreak@1
|
2180 self:RegisterEvent("PLAYER_LOGOUT")
|
flickerstreak@1
|
2181 elseif major == "Dewdrop-2.0" then
|
flickerstreak@1
|
2182 Dewdrop = instance
|
flickerstreak@1
|
2183 end
|
flickerstreak@1
|
2184 end
|
flickerstreak@1
|
2185
|
flickerstreak@1
|
2186 AceLibrary:Register(AceDB, MAJOR_VERSION, MINOR_VERSION, activate, nil, external)
|
flickerstreak@1
|
2187 AceDB = AceLibrary(MAJOR_VERSION)
|