flickerstreak@1: --[[ flickerstreak@1: Name: AceDB-2.0 flickerstreak@1: Revision: $Rev: 18708 $ flickerstreak@1: Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team) flickerstreak@1: Inspired By: Ace 1.x by Turan (turan@gryphon.com) flickerstreak@1: Website: http://www.wowace.com/ flickerstreak@1: Documentation: http://www.wowace.com/index.php/AceDB-2.0 flickerstreak@1: SVN: http://svn.wowace.com/root/trunk/Ace2/AceDB-2.0 flickerstreak@1: Description: Mixin to allow for fast, clean, and featureful saved variable flickerstreak@1: access. flickerstreak@1: Dependencies: AceLibrary, AceOO-2.0, AceEvent-2.0 flickerstreak@1: ]] flickerstreak@1: flickerstreak@1: local MAJOR_VERSION = "AceDB-2.0" flickerstreak@1: local MINOR_VERSION = "$Revision: 18708 $" flickerstreak@1: flickerstreak@1: if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end flickerstreak@1: if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end flickerstreak@1: flickerstreak@1: if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end flickerstreak@1: flickerstreak@1: local function safecall(func,...) flickerstreak@1: local success, err = pcall(func,...) flickerstreak@1: if not success then geterrorhandler()(err) end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local ACTIVE, ENABLED, STATE, TOGGLE_ACTIVE, MAP_ACTIVESUSPENDED, SET_PROFILE, SET_PROFILE_USAGE, PROFILE, PLAYER_OF_REALM, CHOOSE_PROFILE_DESC, CHOOSE_PROFILE_GUI, COPY_PROFILE_DESC, COPY_PROFILE_GUI, OTHER_PROFILE_DESC, OTHER_PROFILE_GUI, OTHER_PROFILE_USAGE, CHARACTER_COLON, REALM_COLON, CLASS_COLON, DEFAULT, ALTERNATIVE flickerstreak@1: flickerstreak@1: if GetLocale() == "deDE" then flickerstreak@1: ACTIVE = "Aktiv" flickerstreak@1: ENABLED = "Aktiviert" flickerstreak@1: STATE = "Status" flickerstreak@1: TOGGLE_ACTIVE = "Stoppt/Aktiviert dieses Addon." flickerstreak@1: MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Aktiv|r", [false] = "|cffff0000Gestoppt|r" } flickerstreak@1: SET_PROFILE = "Setzt das Profil f\195\188r dieses Addon." flickerstreak@1: SET_PROFILE_USAGE = "{Charakter || Klasse || Realm || }" flickerstreak@1: PROFILE = "Profil" flickerstreak@1: PLAYER_OF_REALM = "%s von %s" flickerstreak@1: CHOOSE_PROFILE_DESC = "W\195\164hle ein Profil." flickerstreak@1: CHOOSE_PROFILE_GUI = "W\195\164hle" flickerstreak@1: COPY_PROFILE_DESC = "Kopiert Einstellungen von einem anderem Profil." flickerstreak@1: COPY_PROFILE_GUI = "Kopiere von" flickerstreak@1: OTHER_PROFILE_DESC = "W\195\164hle ein anderes Profil." flickerstreak@1: OTHER_PROFILE_GUI = "Anderes" flickerstreak@1: OTHER_PROFILE_USAGE = "" flickerstreak@1: flickerstreak@1: CHARACTER_COLON = "Charakter: " flickerstreak@1: REALM_COLON = "Realm: " flickerstreak@1: CLASS_COLON = "Klasse: " flickerstreak@1: flickerstreak@1: DEFAULT = "Default" -- fix flickerstreak@1: ALTERNATIVE = "Alternative" -- fix flickerstreak@1: elseif GetLocale() == "frFR" then flickerstreak@1: ACTIVE = "Actif" flickerstreak@1: ENABLED = "Activ\195\169" flickerstreak@1: STATE = "Etat" flickerstreak@1: TOGGLE_ACTIVE = "Suspend/active cet addon." flickerstreak@1: MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Actif|r", [false] = "|cffff0000Suspendu|r" } flickerstreak@1: SET_PROFILE = "S\195\169lectionne le profil pour cet addon." flickerstreak@1: SET_PROFILE_USAGE = "{perso || classe || royaume || }" flickerstreak@1: PROFILE = "Profil" flickerstreak@1: PLAYER_OF_REALM = "%s de %s" flickerstreak@1: CHOOSE_PROFILE_DESC = "Choisissez un profil." flickerstreak@1: CHOOSE_PROFILE_GUI = "Choix" flickerstreak@1: COPY_PROFILE_DESC = "Copier les param\195\168tres d'un autre profil." flickerstreak@1: COPY_PROFILE_GUI = "Copier \195\160 partir de" flickerstreak@1: OTHER_PROFILE_DESC = "Choisissez un autre profil." flickerstreak@1: OTHER_PROFILE_GUI = "Autre" flickerstreak@1: OTHER_PROFILE_USAGE = "" flickerstreak@1: flickerstreak@1: CHARACTER_COLON = "Personnage: " flickerstreak@1: REALM_COLON = "Royaume: " flickerstreak@1: CLASS_COLON = "Classe: " flickerstreak@1: flickerstreak@1: DEFAULT = "Default" -- fix flickerstreak@1: ALTERNATIVE = "Alternative" -- fix flickerstreak@1: elseif GetLocale() == "koKR" then flickerstreak@1: ACTIVE = "활성화" flickerstreak@1: ENABLED = "활성화" flickerstreak@1: STATE = "상태" flickerstreak@1: TOGGLE_ACTIVE = "이 애드온 중지/계속 실행" flickerstreak@1: MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00활성화|r", [false] = "|cffff0000중지됨|r" } flickerstreak@1: SET_PROFILE = "이 애드온에 프로필 설정" flickerstreak@1: SET_PROFILE_USAGE = "{캐릭터명 || 직업 || 서버명 || <프로필명>}" flickerstreak@1: PROFILE = "프로필" flickerstreak@1: PLAYER_OF_REALM = "%s (%s 서버)" flickerstreak@1: CHOOSE_PROFILE_DESC = "프로파일을 선택합니다." flickerstreak@1: CHOOSE_PROFILE_GUI = "선택" flickerstreak@1: COPY_PROFILE_DESC = "다른 프로파일에서 설정을 복사합니다." flickerstreak@1: COPY_PROFILE_GUI = "복사" flickerstreak@1: OTHER_PROFILE_DESC = "다른 프로파일을 선택합니다." flickerstreak@1: OTHER_PROFILE_GUI = "기타" flickerstreak@1: OTHER_PROFILE_USAGE = "<프로파일명>" flickerstreak@1: flickerstreak@1: CHARACTER_COLON = "캐릭터: " flickerstreak@1: REALM_COLON = "서버: " flickerstreak@1: CLASS_COLON = "직업: " flickerstreak@1: flickerstreak@1: DEFAULT = "Default" -- fix flickerstreak@1: ALTERNATIVE = "Alternative" -- fix flickerstreak@1: elseif GetLocale() == "zhTW" then flickerstreak@1: ACTIVE = "啟動" flickerstreak@1: ENABLED = "啟用" flickerstreak@1: STATE = "狀態" flickerstreak@1: TOGGLE_ACTIVE = "暫停/重啟這個插件。" flickerstreak@1: MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00啟動|r", [false] = "|cffff0000已暫停|r" } flickerstreak@1: SET_PROFILE = "設定這插件的記錄檔。" flickerstreak@1: SET_PROFILE_USAGE = "{角色 || 聯業 || 伺服器 || <記錄檔名稱>}" flickerstreak@1: PROFILE = "記錄檔" flickerstreak@1: PLAYER_OF_REALM = "%s 於 %s" flickerstreak@1: CHOOSE_PROFILE_DESC = "選擇一個記錄檔" flickerstreak@1: CHOOSE_PROFILE_GUI = "選擇" flickerstreak@1: COPY_PROFILE_DESC = "由其他記錄檔複製設定。" flickerstreak@1: COPY_PROFILE_GUI = "複製由" flickerstreak@1: OTHER_PROFILE_DESC = "選擇其他記錄檔。" flickerstreak@1: OTHER_PROFILE_GUI = "其他" flickerstreak@1: OTHER_PROFILE_USAGE = "<記錄檔名稱>" flickerstreak@1: flickerstreak@1: CHARACTER_COLON = "角色:" flickerstreak@1: REALM_COLON = "伺服器:" flickerstreak@1: CLASS_COLON = "聯業:" flickerstreak@1: flickerstreak@1: DEFAULT = "Default" -- fix flickerstreak@1: ALTERNATIVE = "Alternative" -- fix flickerstreak@1: elseif GetLocale() == "zhCN" then flickerstreak@1: ACTIVE = "\230\156\137\230\149\136" flickerstreak@1: ENABLED = "\229\144\175\231\148\168" flickerstreak@1: STATE = "\231\138\182\230\128\129" flickerstreak@1: 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: MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00\230\156\137\230\149\136|r", [false] = "|cffff0000\230\154\130\229\129\156|r" } flickerstreak@1: 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: 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: PROFILE = "\233\133\141\231\189\174\230\150\135\228\187\182" flickerstreak@1: PLAYER_OF_REALM = "%s \231\154\132 %s" flickerstreak@1: CHOOSE_PROFILE_DESC = "\233\128\137\230\139\169\233\133\141\231\189\174\230\150\135\228\187\182." flickerstreak@1: CHOOSE_PROFILE_GUI = "\233\128\137\230\139\169" flickerstreak@1: 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: COPY_PROFILE_GUI = "\229\164\141\229\136\182\228\187\142" flickerstreak@1: 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: OTHER_PROFILE_GUI = "\229\133\182\228\187\150" flickerstreak@1: OTHER_PROFILE_USAGE = "<\233\133\141\231\189\174\230\150\135\228\187\182\229\144\141\229\173\151>" flickerstreak@1: flickerstreak@1: CHARACTER_COLON = "\229\173\151\231\172\166: " flickerstreak@1: REALM_COLON = "\229\159\159: " flickerstreak@1: CLASS_COLON = "\233\128\137\228\187\182\231\177\187: " flickerstreak@1: flickerstreak@1: DEFAULT = "Default" -- fix flickerstreak@1: ALTERNATIVE = "Alternative" -- fix flickerstreak@1: else -- enUS flickerstreak@1: ACTIVE = "Active" flickerstreak@1: ENABLED = "Enabled" flickerstreak@1: STATE = "State" flickerstreak@1: TOGGLE_ACTIVE = "Suspend/resume this addon." flickerstreak@1: MAP_ACTIVESUSPENDED = { [true] = "|cff00ff00Active|r", [false] = "|cffff0000Suspended|r" } flickerstreak@1: SET_PROFILE = "Set profile for this addon." flickerstreak@1: SET_PROFILE_USAGE = "{char || class || realm || }" flickerstreak@1: PROFILE = "Profile" flickerstreak@1: PLAYER_OF_REALM = "%s of %s" flickerstreak@1: CHOOSE_PROFILE_DESC = "Choose a profile." flickerstreak@1: CHOOSE_PROFILE_GUI = "Choose" flickerstreak@1: COPY_PROFILE_DESC = "Copy settings from another profile." flickerstreak@1: COPY_PROFILE_GUI = "Copy from" flickerstreak@1: OTHER_PROFILE_DESC = "Choose another profile." flickerstreak@1: OTHER_PROFILE_GUI = "Other" flickerstreak@1: OTHER_PROFILE_USAGE = "" flickerstreak@1: flickerstreak@1: CHARACTER_COLON = "Character: " flickerstreak@1: REALM_COLON = "Realm: " flickerstreak@1: CLASS_COLON = "Class: " flickerstreak@1: flickerstreak@1: DEFAULT = "Default" flickerstreak@1: ALTERNATIVE = "Alternative" flickerstreak@1: end flickerstreak@1: flickerstreak@1: local AceOO = AceLibrary("AceOO-2.0") flickerstreak@1: local AceEvent flickerstreak@1: local Mixin = AceOO.Mixin flickerstreak@1: local AceDB = Mixin { flickerstreak@1: "RegisterDB", flickerstreak@1: "RegisterDefaults", flickerstreak@1: "ResetDB", flickerstreak@1: "SetProfile", flickerstreak@1: "GetProfile", flickerstreak@1: "CopyProfileFrom", flickerstreak@1: "ToggleActive", flickerstreak@1: "IsActive", flickerstreak@1: "AcquireDBNamespace", flickerstreak@1: } flickerstreak@1: local Dewdrop = AceLibrary:HasInstance("Dewdrop-2.0") and AceLibrary("Dewdrop-2.0") flickerstreak@1: flickerstreak@1: local _G = getfenv(0) flickerstreak@1: flickerstreak@1: local function inheritDefaults(t, defaults) flickerstreak@1: if not defaults then flickerstreak@1: return t flickerstreak@1: end flickerstreak@1: for k,v in pairs(defaults) do flickerstreak@1: if k == "*" then flickerstreak@1: local v = v flickerstreak@1: if type(v) == "table" then flickerstreak@1: setmetatable(t, { flickerstreak@1: __index = function(self, key) flickerstreak@1: if key == nil then flickerstreak@1: return nil flickerstreak@1: end flickerstreak@1: self[key] = {} flickerstreak@1: inheritDefaults(self[key], v) flickerstreak@1: return self[key] flickerstreak@1: end flickerstreak@1: } ) flickerstreak@1: else flickerstreak@1: setmetatable(t, { flickerstreak@1: __index = function(self, key) flickerstreak@1: if key == nil then flickerstreak@1: return nil flickerstreak@1: end flickerstreak@1: self[key] = v flickerstreak@1: return self[key] flickerstreak@1: end flickerstreak@1: } ) flickerstreak@1: end flickerstreak@1: for key in pairs(t) do flickerstreak@1: if (defaults[key] == nil or key == "*") and type(t[key]) == "table" then flickerstreak@1: inheritDefaults(t[key], v) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: else flickerstreak@1: if type(v) == "table" then flickerstreak@1: if type(t[k]) ~= "table" then flickerstreak@1: t[k] = {} flickerstreak@1: end flickerstreak@1: inheritDefaults(t[k], v) flickerstreak@1: elseif t[k] == nil then flickerstreak@1: t[k] = v flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: return t flickerstreak@1: end flickerstreak@1: flickerstreak@1: local _,race = UnitRace("player") flickerstreak@1: local faction flickerstreak@1: if race == "Orc" or race == "Scourge" or race == "Troll" or race == "Tauren" or race == "BloodElf" then flickerstreak@1: faction = FACTION_HORDE flickerstreak@1: else flickerstreak@1: faction = FACTION_ALLIANCE flickerstreak@1: end flickerstreak@1: local charID = string.format(PLAYER_OF_REALM, UnitName("player"), (string.gsub(GetRealmName(), "^%s*(.-)%s*$", "%1"))) flickerstreak@1: local realm = string.gsub(GetRealmName(), "^%s*(.-)%s*$", "%1") flickerstreak@1: local realmID = realm .. " - " .. faction flickerstreak@1: local classID = UnitClass("player") flickerstreak@1: flickerstreak@1: AceDB.CHAR_ID = charID flickerstreak@1: AceDB.REALM_ID = realmID flickerstreak@1: AceDB.CLASS_ID = classID flickerstreak@1: flickerstreak@1: AceDB.FACTION = faction flickerstreak@1: AceDB.REALM = realm flickerstreak@1: AceDB.NAME = UnitName("player") flickerstreak@1: flickerstreak@1: local new, del flickerstreak@1: do flickerstreak@1: local list = setmetatable({}, {__mode="k"}) flickerstreak@1: function new() flickerstreak@1: local t = next(list) flickerstreak@1: if t then flickerstreak@1: list[t] = nil flickerstreak@1: return t flickerstreak@1: else flickerstreak@1: return {} flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function del(t) flickerstreak@1: setmetatable(t, nil) flickerstreak@1: for k in pairs(t) do flickerstreak@1: t[k] = nil flickerstreak@1: end flickerstreak@1: list[t] = true flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local caseInsensitive_mt = { flickerstreak@1: __index = function(self, key) flickerstreak@1: if type(key) ~= "string" then flickerstreak@1: return nil flickerstreak@1: end flickerstreak@1: local lowerKey = string.lower(key) flickerstreak@1: for k,v in pairs(self) do flickerstreak@1: if string.lower(k) == lowerKey then flickerstreak@1: return self[k] flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end, flickerstreak@1: __newindex = function(self, key, value) flickerstreak@1: if type(key) ~= "string" then flickerstreak@1: return error("table index is nil", 2) flickerstreak@1: end flickerstreak@1: local lowerKey = string.lower(key) flickerstreak@1: for k in pairs(self) do flickerstreak@1: if string.lower(k) == lowerKey then flickerstreak@1: rawset(self, k, nil) flickerstreak@1: rawset(self, key, value) flickerstreak@1: return flickerstreak@1: end flickerstreak@1: end flickerstreak@1: rawset(self, key, value) flickerstreak@1: end flickerstreak@1: } flickerstreak@1: flickerstreak@1: local db_mt = { __index = function(db, key) flickerstreak@1: if key == "char" then flickerstreak@1: if db.charName then flickerstreak@1: if type(_G[db.charName]) ~= "table" then flickerstreak@1: _G[db.charName] = {} flickerstreak@1: end flickerstreak@1: if type(_G[db.charName].global) ~= "table" then flickerstreak@1: _G[db.charName].global = {} flickerstreak@1: end flickerstreak@1: rawset(db, 'char', _G[db.charName].global) flickerstreak@1: else flickerstreak@1: if type(db.raw.chars) ~= "table" then flickerstreak@1: db.raw.chars = {} flickerstreak@1: end flickerstreak@1: local id = charID flickerstreak@1: if type(db.raw.chars[id]) ~= "table" then flickerstreak@1: db.raw.chars[id] = {} flickerstreak@1: end flickerstreak@1: rawset(db, 'char', db.raw.chars[id]) flickerstreak@1: end flickerstreak@1: if db.defaults and db.defaults.char then flickerstreak@1: inheritDefaults(db.char, db.defaults.char) flickerstreak@1: end flickerstreak@1: return db.char flickerstreak@1: elseif key == "realm" then flickerstreak@1: if type(db.raw.realms) ~= "table" then flickerstreak@1: db.raw.realms = {} flickerstreak@1: end flickerstreak@1: local id = realmID flickerstreak@1: if type(db.raw.realms[id]) ~= "table" then flickerstreak@1: db.raw.realms[id] = {} flickerstreak@1: end flickerstreak@1: rawset(db, 'realm', db.raw.realms[id]) flickerstreak@1: if db.defaults and db.defaults.realm then flickerstreak@1: inheritDefaults(db.realm, db.defaults.realm) flickerstreak@1: end flickerstreak@1: return db.realm flickerstreak@1: elseif key == "account" then flickerstreak@1: if type(db.raw.account) ~= "table" then flickerstreak@1: db.raw.account = {} flickerstreak@1: end flickerstreak@1: rawset(db, 'account', db.raw.account) flickerstreak@1: if db.defaults and db.defaults.account then flickerstreak@1: inheritDefaults(db.account, db.defaults.account) flickerstreak@1: end flickerstreak@1: return db.account flickerstreak@1: elseif key == "faction" then flickerstreak@1: if type(db.raw.factions) ~= "table" then flickerstreak@1: db.raw.factions = {} flickerstreak@1: end flickerstreak@1: local id = faction flickerstreak@1: if type(db.raw.factions[id]) ~= "table" then flickerstreak@1: db.raw.factions[id] = {} flickerstreak@1: end flickerstreak@1: rawset(db, 'faction', db.raw.factions[id]) flickerstreak@1: if db.defaults and db.defaults.faction then flickerstreak@1: inheritDefaults(db.faction, db.defaults.faction) flickerstreak@1: end flickerstreak@1: return db.faction flickerstreak@1: elseif key == "class" then flickerstreak@1: if type(db.raw.classes) ~= "table" then flickerstreak@1: db.raw.classes = {} flickerstreak@1: end flickerstreak@1: local id = classID flickerstreak@1: if type(db.raw.classes[id]) ~= "table" then flickerstreak@1: db.raw.classes[id] = {} flickerstreak@1: end flickerstreak@1: rawset(db, 'class', db.raw.classes[id]) flickerstreak@1: if db.defaults and db.defaults.class then flickerstreak@1: inheritDefaults(db.class, db.defaults.class) flickerstreak@1: end flickerstreak@1: return db.class flickerstreak@1: elseif key == "profile" then flickerstreak@1: if type(db.raw.profiles) ~= "table" then flickerstreak@1: db.raw.profiles = setmetatable({}, caseInsensitive_mt) flickerstreak@1: else flickerstreak@1: setmetatable(db.raw.profiles, caseInsensitive_mt) flickerstreak@1: end flickerstreak@1: local id = db.raw.currentProfile[charID] flickerstreak@1: if id == "char" then flickerstreak@1: id = "char/" .. charID flickerstreak@1: elseif id == "class" then flickerstreak@1: id = "class/" .. classID flickerstreak@1: elseif id == "realm" then flickerstreak@1: id = "realm/" .. realmID flickerstreak@1: end flickerstreak@1: if type(db.raw.profiles[id]) ~= "table" then flickerstreak@1: db.raw.profiles[id] = {} flickerstreak@1: end flickerstreak@1: rawset(db, 'profile', db.raw.profiles[id]) flickerstreak@1: if db.defaults and db.defaults.profile then flickerstreak@1: inheritDefaults(db.profile, db.defaults.profile) flickerstreak@1: end flickerstreak@1: return db.profile flickerstreak@1: elseif key == "raw" or key == "defaults" or key == "name" or key == "charName" or key == "namespaces" then flickerstreak@1: return nil flickerstreak@1: end flickerstreak@1: error(string.format('Cannot access key %q in db table. You may want to use db.profile[%q]', tostring(key), tostring(key)), 2) flickerstreak@1: end, __newindex = function(db, key, value) flickerstreak@1: error(string.format('Cannot access key %q in db table. You may want to use db.profile[%q]', tostring(key), tostring(key)), 2) flickerstreak@1: end } flickerstreak@1: flickerstreak@1: local function RecalculateAceDBCopyFromList(target) flickerstreak@1: local db = target.db flickerstreak@1: local t = target['acedb-profile-copylist'] flickerstreak@1: for k,v in pairs(t) do flickerstreak@1: t[k] = nil flickerstreak@1: end flickerstreak@1: local _,currentProfile = AceDB.GetProfile(target) flickerstreak@1: if db and db.raw then flickerstreak@1: if db.raw.profiles then flickerstreak@1: for k in pairs(db.raw.profiles) do flickerstreak@1: if currentProfile ~= k then flickerstreak@1: if string.find(k, '^char/') then flickerstreak@1: local name = string.sub(k, 6) flickerstreak@1: t[k] = CHARACTER_COLON .. name flickerstreak@1: elseif string.find(k, '^realm/') then flickerstreak@1: local name = string.sub(k, 7) flickerstreak@1: t[k] = REALM_COLON .. name flickerstreak@1: elseif string.find(k, '^class/') then flickerstreak@1: local name = string.sub(k, 7) flickerstreak@1: t[k] = CLASS_COLON .. name flickerstreak@1: else flickerstreak@1: t[k] = k flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.raw.namespaces then flickerstreak@1: for _,n in pairs(db.raw.namespaces) do flickerstreak@1: if n.profiles then flickerstreak@1: for k in pairs(n.profiles) do flickerstreak@1: if currentProfile ~= k then flickerstreak@1: if string.find(k, '^char/') then flickerstreak@1: local name = string.sub(k, 6) flickerstreak@1: t[k] = CHARACTER_COLON .. name flickerstreak@1: elseif string.find(k, '^realm/') then flickerstreak@1: local name = string.sub(k, 7) flickerstreak@1: t[k] = REALM_COLON .. name flickerstreak@1: elseif string.find(k, '^class/') then flickerstreak@1: local name = string.sub(k, 7) flickerstreak@1: t[k] = CLASS_COLON .. name flickerstreak@1: else flickerstreak@1: t[k] = k flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if t.Default then flickerstreak@1: t.Default = DEFAULT flickerstreak@1: end flickerstreak@1: if t.Alternative then flickerstreak@1: t.Alternative = ALTERNATIVE flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function RecalculateAceDBProfileList(target) flickerstreak@1: local t = target['acedb-profile-list'] flickerstreak@1: for k,v in pairs(t) do flickerstreak@1: t[k] = nil flickerstreak@1: end flickerstreak@1: t.char = CHARACTER_COLON .. charID flickerstreak@1: t.realm = REALM_COLON .. realmID flickerstreak@1: t.class = CLASS_COLON .. classID flickerstreak@1: t.Default = DEFAULT flickerstreak@1: local db = target.db flickerstreak@1: if db and db.raw then flickerstreak@1: if db.raw.profiles then flickerstreak@1: for k in pairs(db.raw.profiles) do flickerstreak@1: if not string.find(k, '^char/') and not string.find(k, '^realm/') and not string.find(k, '^class/') then flickerstreak@1: t[k] = k flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.raw.namespaces then flickerstreak@1: for _,n in pairs(db.raw.namespaces) do flickerstreak@1: if n.profiles then flickerstreak@1: for k in pairs(n.profiles) do flickerstreak@1: if not string.find(k, '^char/') and not string.find(k, '^realm/') and not string.find(k, '^class/') then flickerstreak@1: t[k] = k flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: local curr = db.raw.currentProfile and db.raw.currentProfile[charID] flickerstreak@1: if curr then flickerstreak@1: t[curr] = curr flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if t.Alternative then flickerstreak@1: t.Alternative = ALTERNATIVE flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local CrawlForSerialization flickerstreak@1: local CrawlForDeserialization flickerstreak@1: flickerstreak@1: local function SerializeObject(o) flickerstreak@1: local t = { o:Serialize() } flickerstreak@1: CrawlForSerialization(t) flickerstreak@1: t[0] = o.class:GetLibraryVersion() flickerstreak@1: return t flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function DeserializeObject(t) flickerstreak@1: CrawlForDeserialization(t) flickerstreak@1: local className = t[0] flickerstreak@1: t[0] = nil flickerstreak@1: return AceLibrary(className):Deserialize(unpack(t)) flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function IsSerializable(t) flickerstreak@1: 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: end flickerstreak@1: flickerstreak@1: function CrawlForSerialization(t) flickerstreak@1: local tmp = new() flickerstreak@1: for k,v in pairs(t) do flickerstreak@1: tmp[k] = v flickerstreak@1: end flickerstreak@1: for k,v in pairs(tmp) do flickerstreak@1: if type(v) == "table" and type(v[0]) ~= "userdata" then flickerstreak@1: if IsSerializable(v) then flickerstreak@1: v = SerializeObject(v) flickerstreak@1: t[k] = v flickerstreak@1: else flickerstreak@1: CrawlForSerialization(v) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if type(k) == "table" and type(k[0]) ~= "userdata" then flickerstreak@1: if IsSerializable(k) then flickerstreak@1: t[k] = nil flickerstreak@1: t[SerializeObject(k)] = v flickerstreak@1: else flickerstreak@1: CrawlForSerialization(k) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: tmp[k] = nil flickerstreak@1: k = nil flickerstreak@1: end flickerstreak@1: tmp = del(tmp) flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function IsDeserializable(t) flickerstreak@1: return type(t[0]) == "string" and AceLibrary:HasInstance(t[0]) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function CrawlForDeserialization(t) flickerstreak@1: local tmp = new() flickerstreak@1: for k,v in pairs(t) do flickerstreak@1: tmp[k] = v flickerstreak@1: end flickerstreak@1: for k,v in pairs(tmp) do flickerstreak@1: if type(v) == "table" then flickerstreak@1: if IsDeserializable(v) then flickerstreak@1: t[k] = DeserializeObject(v) flickerstreak@1: del(v) flickerstreak@1: v = t[k] flickerstreak@1: elseif type(v[0]) ~= "userdata" then flickerstreak@1: CrawlForDeserialization(v) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if type(k) == "table" then flickerstreak@1: if IsDeserializable(k) then flickerstreak@1: t[k] = nil flickerstreak@1: t[DeserializeObject(k)] = v flickerstreak@1: del(k) flickerstreak@1: elseif type(k[0]) ~= "userdata" then flickerstreak@1: CrawlForDeserialization(k) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: tmp[k] = nil flickerstreak@1: k = nil flickerstreak@1: end flickerstreak@1: tmp = del(tmp) flickerstreak@1: end flickerstreak@1: flickerstreak@1: local namespace_mt = { __index = function(namespace, key) flickerstreak@1: local db = namespace.db flickerstreak@1: local name = namespace.name flickerstreak@1: if key == "char" then flickerstreak@1: if db.charName then flickerstreak@1: if type(_G[db.charName]) ~= "table" then flickerstreak@1: _G[db.charName] = {} flickerstreak@1: end flickerstreak@1: if type(_G[db.charName].namespaces) ~= "table" then flickerstreak@1: _G[db.charName].namespaces = {} flickerstreak@1: end flickerstreak@1: if type(_G[db.charName].namespaces[name]) ~= "table" then flickerstreak@1: _G[db.charName].namespaces[name] = {} flickerstreak@1: end flickerstreak@1: rawset(namespace, 'char', _G[db.charName].namespaces[name]) flickerstreak@1: else flickerstreak@1: if type(db.raw.namespaces) ~= "table" then flickerstreak@1: db.raw.namespaces = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name]) ~= "table" then flickerstreak@1: db.raw.namespaces[name] = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name].chars) ~= "table" then flickerstreak@1: db.raw.namespaces[name].chars = {} flickerstreak@1: end flickerstreak@1: local id = charID flickerstreak@1: if type(db.raw.namespaces[name].chars[id]) ~= "table" then flickerstreak@1: db.raw.namespaces[name].chars[id] = {} flickerstreak@1: end flickerstreak@1: rawset(namespace, 'char', db.raw.namespaces[name].chars[id]) flickerstreak@1: end flickerstreak@1: if namespace.defaults and namespace.defaults.char then flickerstreak@1: inheritDefaults(namespace.char, namespace.defaults.char) flickerstreak@1: end flickerstreak@1: return namespace.char flickerstreak@1: elseif key == "realm" then flickerstreak@1: if type(db.raw.namespaces) ~= "table" then flickerstreak@1: db.raw.namespaces = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name]) ~= "table" then flickerstreak@1: db.raw.namespaces[name] = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name].realms) ~= "table" then flickerstreak@1: db.raw.namespaces[name].realms = {} flickerstreak@1: end flickerstreak@1: local id = realmID flickerstreak@1: if type(db.raw.namespaces[name].realms[id]) ~= "table" then flickerstreak@1: db.raw.namespaces[name].realms[id] = {} flickerstreak@1: end flickerstreak@1: rawset(namespace, 'realm', db.raw.namespaces[name].realms[id]) flickerstreak@1: if namespace.defaults and namespace.defaults.realm then flickerstreak@1: inheritDefaults(namespace.realm, namespace.defaults.realm) flickerstreak@1: end flickerstreak@1: return namespace.realm flickerstreak@1: elseif key == "account" then flickerstreak@1: if type(db.raw.namespaces) ~= "table" then flickerstreak@1: db.raw.namespaces = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name]) ~= "table" then flickerstreak@1: db.raw.namespaces[name] = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name].account) ~= "table" then flickerstreak@1: db.raw.namespaces[name].account = {} flickerstreak@1: end flickerstreak@1: rawset(namespace, 'account', db.raw.namespaces[name].account) flickerstreak@1: if namespace.defaults and namespace.defaults.account then flickerstreak@1: inheritDefaults(namespace.account, namespace.defaults.account) flickerstreak@1: end flickerstreak@1: return namespace.account flickerstreak@1: elseif key == "faction" then flickerstreak@1: if type(db.raw.namespaces) ~= "table" then flickerstreak@1: db.raw.namespaces = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name]) ~= "table" then flickerstreak@1: db.raw.namespaces[name] = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name].factions) ~= "table" then flickerstreak@1: db.raw.namespaces[name].factions = {} flickerstreak@1: end flickerstreak@1: local id = faction flickerstreak@1: if type(db.raw.namespaces[name].factions[id]) ~= "table" then flickerstreak@1: db.raw.namespaces[name].factions[id] = {} flickerstreak@1: end flickerstreak@1: rawset(namespace, 'faction', db.raw.namespaces[name].factions[id]) flickerstreak@1: if namespace.defaults and namespace.defaults.faction then flickerstreak@1: inheritDefaults(namespace.faction, namespace.defaults.faction) flickerstreak@1: end flickerstreak@1: return namespace.faction flickerstreak@1: elseif key == "class" then flickerstreak@1: if type(db.raw.namespaces) ~= "table" then flickerstreak@1: db.raw.namespaces = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name]) ~= "table" then flickerstreak@1: db.raw.namespaces[name] = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name].classes) ~= "table" then flickerstreak@1: db.raw.namespaces[name].classes = {} flickerstreak@1: end flickerstreak@1: local id = classID flickerstreak@1: if type(db.raw.namespaces[name].classes[id]) ~= "table" then flickerstreak@1: db.raw.namespaces[name].classes[id] = {} flickerstreak@1: end flickerstreak@1: rawset(namespace, 'class', db.raw.namespaces[name].classes[id]) flickerstreak@1: if namespace.defaults and namespace.defaults.class then flickerstreak@1: inheritDefaults(namespace.class, namespace.defaults.class) flickerstreak@1: end flickerstreak@1: return namespace.class flickerstreak@1: elseif key == "profile" then flickerstreak@1: if type(db.raw.namespaces) ~= "table" then flickerstreak@1: db.raw.namespaces = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name]) ~= "table" then flickerstreak@1: db.raw.namespaces[name] = {} flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name].profiles) ~= "table" then flickerstreak@1: db.raw.namespaces[name].profiles = setmetatable({}, caseInsensitive_mt) flickerstreak@1: else flickerstreak@1: setmetatable(db.raw.namespaces[name].profiles, caseInsensitive_mt) flickerstreak@1: end flickerstreak@1: local id = db.raw.currentProfile[charID] flickerstreak@1: if id == "char" then flickerstreak@1: id = "char/" .. charID flickerstreak@1: elseif id == "class" then flickerstreak@1: id = "class/" .. classID flickerstreak@1: elseif id == "realm" then flickerstreak@1: id = "realm/" .. realmID flickerstreak@1: end flickerstreak@1: if type(db.raw.namespaces[name].profiles[id]) ~= "table" then flickerstreak@1: db.raw.namespaces[name].profiles[id] = {} flickerstreak@1: end flickerstreak@1: rawset(namespace, 'profile', db.raw.namespaces[name].profiles[id]) flickerstreak@1: if namespace.defaults and namespace.defaults.profile then flickerstreak@1: inheritDefaults(namespace.profile, namespace.defaults.profile) flickerstreak@1: end flickerstreak@1: return namespace.profile flickerstreak@1: elseif key == "defaults" or key == "name" or key == "db" then flickerstreak@1: return nil flickerstreak@1: end flickerstreak@1: error(string.format('Cannot access key %q in db table. You may want to use db.profile[%q]', tostring(key), tostring(key)), 2) flickerstreak@1: end, __newindex = function(db, key, value) flickerstreak@1: error(string.format('Cannot access key %q in db table. You may want to use db.profile[%q]', tostring(key), tostring(key)), 2) flickerstreak@1: end } flickerstreak@1: flickerstreak@1: function AceDB:InitializeDB(addonName) flickerstreak@1: local db = self.db flickerstreak@1: flickerstreak@1: if not db then flickerstreak@1: if addonName then flickerstreak@1: AceDB.addonsLoaded[addonName] = true flickerstreak@1: end flickerstreak@1: return flickerstreak@1: end flickerstreak@1: flickerstreak@1: if db.raw then flickerstreak@1: -- someone manually initialized flickerstreak@1: return flickerstreak@1: end flickerstreak@1: flickerstreak@1: if type(_G[db.name]) ~= "table" then flickerstreak@1: _G[db.name] = {} flickerstreak@1: else flickerstreak@1: CrawlForDeserialization(_G[db.name]) flickerstreak@1: end flickerstreak@1: if type(_G[db.charName]) == "table" then flickerstreak@1: CrawlForDeserialization(_G[db.charName]) flickerstreak@1: end flickerstreak@1: rawset(db, 'raw', _G[db.name]) flickerstreak@1: if not db.raw.currentProfile then flickerstreak@1: db.raw.currentProfile = {} flickerstreak@1: end flickerstreak@1: if not db.raw.currentProfile[charID] then flickerstreak@1: db.raw.currentProfile[charID] = "Default" flickerstreak@1: end flickerstreak@1: if db.raw.disabled then flickerstreak@1: setmetatable(db.raw.disabled, caseInsensitive_mt) flickerstreak@1: end flickerstreak@1: if self['acedb-profile-copylist'] then flickerstreak@1: RecalculateAceDBCopyFromList(self) flickerstreak@1: end flickerstreak@1: if self['acedb-profile-list'] then flickerstreak@1: RecalculateAceDBProfileList(self) flickerstreak@1: end flickerstreak@1: setmetatable(db, db_mt) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:OnEmbedInitialize(target, name) flickerstreak@1: if name then flickerstreak@1: self:ADDON_LOADED(name) flickerstreak@1: end flickerstreak@1: self.InitializeDB(target, name) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:RegisterDB(name, charName) flickerstreak@1: AceDB:argCheck(name, 2, "string") flickerstreak@1: AceDB:argCheck(charName, 3, "string", "nil") flickerstreak@1: if self.db then flickerstreak@1: AceDB:error("Cannot call \"RegisterDB\" if self.db is set.") flickerstreak@1: end flickerstreak@1: local stack = debugstack() flickerstreak@1: local addonName = string.gsub(stack, ".-\n.-\\AddOns\\(.-)\\.*", "%1") flickerstreak@1: self.db = { flickerstreak@1: name = name, flickerstreak@1: charName = charName flickerstreak@1: } flickerstreak@1: if AceDB.addonsLoaded[addonName] then flickerstreak@1: AceDB.InitializeDB(self, addonName) flickerstreak@1: else flickerstreak@1: AceDB.addonsToBeInitialized[self] = addonName flickerstreak@1: end flickerstreak@1: AceDB.registry[self] = true flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:RegisterDefaults(kind, defaults, a3) flickerstreak@1: local name flickerstreak@1: if a3 then flickerstreak@1: name, kind, defaults = kind, defaults, a3 flickerstreak@1: AceDB:argCheck(name, 2, "string") flickerstreak@1: AceDB:argCheck(kind, 3, "string") flickerstreak@1: AceDB:argCheck(defaults, 4, "table") flickerstreak@1: else flickerstreak@1: AceDB:argCheck(kind, 2, "string") flickerstreak@1: AceDB:argCheck(defaults, 3, "table") flickerstreak@1: end flickerstreak@1: if kind ~= "char" and kind ~= "class" and kind ~= "profile" and kind ~= "account" and kind ~= "realm" and kind ~= "faction" then flickerstreak@1: AceDB:error("Bad argument #%d to `RegisterDefaults' (\"char\", \"class\", \"profile\", \"account\", \"realm\", or \"faction\" expected, got %q)", a3 and 3 or 2, kind) flickerstreak@1: end flickerstreak@1: if type(self.db) ~= "table" or type(self.db.name) ~= "string" then flickerstreak@1: AceDB:error("Cannot call \"RegisterDefaults\" unless \"RegisterDB\" has been previously called.") flickerstreak@1: end flickerstreak@1: local db flickerstreak@1: if name then flickerstreak@1: local namespace = self:AcquireDBNamespace(name) flickerstreak@1: if namespace.defaults and namespace.defaults[kind] then flickerstreak@1: AceDB:error("\"RegisterDefaults\" has already been called for %q::%q.", name, kind) flickerstreak@1: end flickerstreak@1: db = namespace flickerstreak@1: else flickerstreak@1: if self.db.defaults and self.db.defaults[kind] then flickerstreak@1: AceDB:error("\"RegisterDefaults\" has already been called for %q.", kind) flickerstreak@1: end flickerstreak@1: db = self.db flickerstreak@1: end flickerstreak@1: if not db.defaults then flickerstreak@1: rawset(db, 'defaults', {}) flickerstreak@1: end flickerstreak@1: db.defaults[kind] = defaults flickerstreak@1: if rawget(db, kind) then flickerstreak@1: inheritDefaults(db[kind], defaults) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:ResetDB(kind) flickerstreak@1: AceDB:argCheck(kind, 2, "nil", "string") flickerstreak@1: if not self.db or not self.db.raw then flickerstreak@1: AceDB:error("Cannot call \"ResetDB\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.") flickerstreak@1: end flickerstreak@1: local db = self.db flickerstreak@1: if kind == nil then flickerstreak@1: if db.charName then flickerstreak@1: _G[db.charName] = nil flickerstreak@1: end flickerstreak@1: _G[db.name] = nil flickerstreak@1: rawset(db, 'raw', nil) flickerstreak@1: AceDB.InitializeDB(self) flickerstreak@1: if db.namespaces then flickerstreak@1: for name,v in pairs(db.namespaces) do flickerstreak@1: rawset(v, 'account', nil) flickerstreak@1: rawset(v, 'char', nil) flickerstreak@1: rawset(v, 'class', nil) flickerstreak@1: rawset(v, 'profile', nil) flickerstreak@1: rawset(v, 'realm', nil) flickerstreak@1: rawset(v, 'faction', nil) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: elseif kind == "account" then flickerstreak@1: db.raw.account = nil flickerstreak@1: rawset(db, 'account', nil) flickerstreak@1: if db.namespaces then flickerstreak@1: for name,v in pairs(db.namespaces) do flickerstreak@1: rawset(v, 'account', nil) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: elseif kind == "char" then flickerstreak@1: if db.charName then flickerstreak@1: _G[db.charName] = nil flickerstreak@1: else flickerstreak@1: if db.raw.chars then flickerstreak@1: db.raw.chars[charID] = nil flickerstreak@1: end flickerstreak@1: if db.raw.namespaces then flickerstreak@1: for name,v in pairs(db.raw.namespaces) do flickerstreak@1: if v.chars then flickerstreak@1: v.chars[charID] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: rawset(db, 'char', nil) flickerstreak@1: if db.namespaces then flickerstreak@1: for name,v in pairs(db.namespaces) do flickerstreak@1: rawset(v, 'char', nil) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: elseif kind == "realm" then flickerstreak@1: if db.raw.realms then flickerstreak@1: db.raw.realms[realmID] = nil flickerstreak@1: end flickerstreak@1: rawset(db, 'realm', nil) flickerstreak@1: if db.raw.namespaces then flickerstreak@1: for name,v in pairs(db.raw.namespaces) do flickerstreak@1: if v.realms then flickerstreak@1: v.realms[realmID] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.namespaces then flickerstreak@1: for name,v in pairs(db.namespaces) do flickerstreak@1: rawset(v, 'realm', nil) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: elseif kind == "faction" then flickerstreak@1: if db.raw.factions then flickerstreak@1: db.raw.factions[faction] = nil flickerstreak@1: end flickerstreak@1: rawset(db, 'faction', nil) flickerstreak@1: if db.raw.namespaces then flickerstreak@1: for name,v in pairs(db.raw.namespaces) do flickerstreak@1: if v.factions then flickerstreak@1: v.factions[faction] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.namespaces then flickerstreak@1: for name,v in pairs(db.namespaces) do flickerstreak@1: rawset(v, 'faction', nil) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: elseif kind == "class" then flickerstreak@1: if db.raw.realms then flickerstreak@1: db.raw.realms[classID] = nil flickerstreak@1: end flickerstreak@1: rawset(db, 'class', nil) flickerstreak@1: if db.raw.namespaces then flickerstreak@1: for name,v in pairs(db.raw.namespaces) do flickerstreak@1: if v.classes then flickerstreak@1: v.classes[classID] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.namespaces then flickerstreak@1: for name,v in pairs(db.namespaces) do flickerstreak@1: rawset(v, 'class', nil) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: elseif kind == "profile" then flickerstreak@1: local id = db.raw.currentProfile and db.raw.currentProfile[charID] or "Default" flickerstreak@1: if id == "char" then flickerstreak@1: id = "char/" .. charID flickerstreak@1: elseif id == "class" then flickerstreak@1: id = "class/" .. classID flickerstreak@1: elseif id == "realm" then flickerstreak@1: id = "realm/" .. realmID flickerstreak@1: end flickerstreak@1: if db.raw.profiles then flickerstreak@1: db.raw.profiles[id] = nil flickerstreak@1: end flickerstreak@1: rawset(db, 'profile', nil) flickerstreak@1: if db.raw.namespaces then flickerstreak@1: for name,v in pairs(db.raw.namespaces) do flickerstreak@1: if v.profiles then flickerstreak@1: v.profiles[id] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.namespaces then flickerstreak@1: for name,v in pairs(db.namespaces) do flickerstreak@1: rawset(v, 'profile', nil) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function cleanDefaults(t, defaults) flickerstreak@1: if defaults then flickerstreak@1: for k,v in pairs(defaults) do flickerstreak@1: if k == "*" then flickerstreak@1: if type(v) == "table" then flickerstreak@1: for k in pairs(t) do flickerstreak@1: if (defaults[k] == nil or k == "*") and type(t[k]) == "table" then flickerstreak@1: if cleanDefaults(t[k], v) then flickerstreak@1: t[k] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: else flickerstreak@1: for k in pairs(t) do flickerstreak@1: if (defaults[k] == nil or k == "*") and t[k] == v then flickerstreak@1: t[k] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: else flickerstreak@1: if type(v) == "table" then flickerstreak@1: if type(t[k]) == "table" then flickerstreak@1: if cleanDefaults(t[k], v) then flickerstreak@1: t[k] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: elseif t[k] == v then flickerstreak@1: t[k] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: return t and not next(t) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:GetProfile() flickerstreak@1: if not self.db or not self.db.raw then flickerstreak@1: return nil flickerstreak@1: end flickerstreak@1: if not self.db.raw.currentProfile then flickerstreak@1: self.db.raw.currentProfile = {} flickerstreak@1: end flickerstreak@1: if not self.db.raw.currentProfile[charID] then flickerstreak@1: self.db.raw.currentProfile[charID] = "Default" flickerstreak@1: end flickerstreak@1: local profile = self.db.raw.currentProfile[charID] flickerstreak@1: if profile == "char" then flickerstreak@1: return "char", "char/" .. charID flickerstreak@1: elseif profile == "class" then flickerstreak@1: return "class", "class/" .. classID flickerstreak@1: elseif profile == "realm" then flickerstreak@1: return "realm", "realm/" .. realmID flickerstreak@1: end flickerstreak@1: return profile, profile flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function copyTable(to, from) flickerstreak@1: setmetatable(to, nil) flickerstreak@1: for k,v in pairs(from) do flickerstreak@1: if type(k) == "table" then flickerstreak@1: k = copyTable({}, k) flickerstreak@1: end flickerstreak@1: if type(v) == "table" then flickerstreak@1: v = copyTable({}, v) flickerstreak@1: end flickerstreak@1: to[k] = v flickerstreak@1: end flickerstreak@1: setmetatable(to, from) flickerstreak@1: return to flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:SetProfile(name) flickerstreak@1: AceDB:argCheck(name, 2, "string") flickerstreak@1: if not self.db or not self.db.raw then flickerstreak@1: AceDB:error("Cannot call \"SetProfile\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.") flickerstreak@1: end flickerstreak@1: local db = self.db flickerstreak@1: local lowerName = string.lower(name) flickerstreak@1: if string.sub(lowerName, 1, 5) == "char/" or string.sub(lowerName, 1, 6) == "realm/" or string.sub(lowerName, 1, 6) == "class/" then flickerstreak@1: if string.sub(lowerName, 1, 5) == "char/" then flickerstreak@1: name = "char" flickerstreak@1: else flickerstreak@1: name = string.sub(lowerName, 1, 5) flickerstreak@1: end flickerstreak@1: lowerName = string.lower(name) flickerstreak@1: end flickerstreak@1: local oldName = db.raw.currentProfile[charID] flickerstreak@1: if string.lower(oldName) == string.lower(name) then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: local oldProfileData = db.profile flickerstreak@1: local realName = name flickerstreak@1: if lowerName == "char" then flickerstreak@1: realName = name .. "/" .. charID flickerstreak@1: elseif lowerName == "realm" then flickerstreak@1: realName = name .. "/" .. realmID flickerstreak@1: elseif lowerName == "class" then flickerstreak@1: realName = name .. "/" .. classID flickerstreak@1: end flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedProfileDisable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedProfileDisable, mixin, self, realName) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnProfileDisable) == "function" then flickerstreak@1: safecall(self.OnProfileDisable, self, realName) flickerstreak@1: end flickerstreak@1: local active = self:IsActive() flickerstreak@1: db.raw.currentProfile[charID] = name flickerstreak@1: rawset(db, 'profile', nil) flickerstreak@1: if db.namespaces then flickerstreak@1: for k,v in pairs(db.namespaces) do flickerstreak@1: rawset(v, 'profile', nil) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedProfileEnable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedProfileEnable, mixin, self, oldName, oldProfileData) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnProfileEnable) == "function" then flickerstreak@1: safecall(self.OnProfileEnable, self, oldName, oldProfileData) flickerstreak@1: end flickerstreak@1: if cleanDefaults(oldProfileData, db.defaults and db.defaults.profile) then flickerstreak@1: db.raw.profiles[oldName] = nil flickerstreak@1: if not next(db.raw.profiles) then flickerstreak@1: db.raw.profiles = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: local newactive = self:IsActive() flickerstreak@1: if active ~= newactive then flickerstreak@1: if AceOO.inherits(self, "AceAddon-2.0") then flickerstreak@1: local AceAddon = AceLibrary("AceAddon-2.0") flickerstreak@1: if not AceAddon.addonsStarted[self] then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if newactive then flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedEnable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedEnable, mixin, self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnEnable) == "function" then flickerstreak@1: safecall(self.OnEnable, self) flickerstreak@1: end flickerstreak@1: if AceEvent then flickerstreak@1: AceEvent:TriggerEvent("Ace2_AddonEnabled", self) flickerstreak@1: end flickerstreak@1: else flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedDisable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedDisable, mixin, self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnDisable) == "function" then flickerstreak@1: safecall(self.OnDisable, self) flickerstreak@1: end flickerstreak@1: if AceEvent then flickerstreak@1: AceEvent:TriggerEvent("Ace2_AddonDisabled", self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if self['acedb-profile-list'] then flickerstreak@1: RecalculateAceDBProfileList(self) flickerstreak@1: end flickerstreak@1: if self['acedb-profile-copylist'] then flickerstreak@1: RecalculateAceDBCopyFromList(self) flickerstreak@1: end flickerstreak@1: if Dewdrop then flickerstreak@1: Dewdrop:Refresh(1) flickerstreak@1: Dewdrop:Refresh(2) flickerstreak@1: Dewdrop:Refresh(3) flickerstreak@1: Dewdrop:Refresh(4) flickerstreak@1: Dewdrop:Refresh(5) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:CopyProfileFrom(copyFrom) flickerstreak@1: AceDB:argCheck(copyFrom, 2, "string") flickerstreak@1: if not self.db or not self.db.raw then flickerstreak@1: AceDB:error("Cannot call \"CopyProfileFrom\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.") flickerstreak@1: end flickerstreak@1: local db = self.db flickerstreak@1: local lowerCopyFrom = string.lower(copyFrom) flickerstreak@1: if not db.raw.profiles or not db.raw.profiles[copyFrom] then flickerstreak@1: local good = false flickerstreak@1: if db.raw.namespaces then flickerstreak@1: for _,n in pairs(db.raw.namespaces) do flickerstreak@1: if n.profiles and n.profiles[copyFrom] then flickerstreak@1: good = true flickerstreak@1: break flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if not good then flickerstreak@1: AceDB:error("Cannot copy from profile %q, it does not exist.", copyFrom) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: local currentProfile = db.raw.currentProfile[charID] flickerstreak@1: if string.lower(currentProfile) == lowerCopyFrom then flickerstreak@1: AceDB:error("Cannot copy from profile %q, it is currently in use.", copyFrom) flickerstreak@1: end flickerstreak@1: local oldProfileData = db.profile flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedProfileDisable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedProfileDisable, mixin, self, currentProfile) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnProfileDisable) == "function" then flickerstreak@1: safecall(self.OnProfileDisable, self, realName) flickerstreak@1: end flickerstreak@1: local active = self:IsActive() flickerstreak@1: for k,v in pairs(db.profile) do flickerstreak@1: db.profile[k] = nil flickerstreak@1: end flickerstreak@1: if db.raw.profiles[copyFrom] then flickerstreak@1: copyTable(db.profile, db.raw.profiles[copyFrom]) flickerstreak@1: end flickerstreak@1: inheritDefaults(db.profile, db.defaults and db.defaults.profile) flickerstreak@1: if db.namespaces then flickerstreak@1: for l,u in pairs(db.namespaces) do flickerstreak@1: for k,v in pairs(u.profile) do flickerstreak@1: u.profile[k] = nil flickerstreak@1: end flickerstreak@1: if db.raw.namespaces[l].profiles[copyFrom] then flickerstreak@1: copyTable(u.profile, db.raw.namespaces[l].profiles[copyFrom]) flickerstreak@1: end flickerstreak@1: inheritDefaults(u.profile, u.defaults and u.defaults.profile) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedProfileEnable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedProfileEnable, mixin, self, copyFrom, oldProfileData, copyFrom) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnProfileEnable) == "function" then flickerstreak@1: safecall(self.OnProfileEnable, self, copyFrom, oldProfileData, copyFrom) flickerstreak@1: end flickerstreak@1: local newactive = self:IsActive() flickerstreak@1: if active ~= newactive then flickerstreak@1: if AceOO.inherits(self, "AceAddon-2.0") then flickerstreak@1: local AceAddon = AceLibrary("AceAddon-2.0") flickerstreak@1: if not AceAddon.addonsStarted[self] then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if newactive then flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedEnable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedEnable, mixin, self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnEnable) == "function" then flickerstreak@1: safecall(self.OnEnable, self) flickerstreak@1: end flickerstreak@1: if AceEvent then flickerstreak@1: AceEvent:TriggerEvent("Ace2_AddonEnabled", self) flickerstreak@1: end flickerstreak@1: else flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedDisable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedDisable, mixin, self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnDisable) == "function" then flickerstreak@1: safecall(self.OnDisable, self) flickerstreak@1: end flickerstreak@1: if AceEvent then flickerstreak@1: AceEvent:TriggerEvent("Ace2_AddonDisabled", self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if self['acedb-profile-list'] then flickerstreak@1: RecalculateAceDBProfileList(self) flickerstreak@1: end flickerstreak@1: if self['acedb-profile-copylist'] then flickerstreak@1: RecalculateAceDBCopyFromList(self) flickerstreak@1: end flickerstreak@1: if Dewdrop then flickerstreak@1: Dewdrop:Refresh(1) flickerstreak@1: Dewdrop:Refresh(2) flickerstreak@1: Dewdrop:Refresh(3) flickerstreak@1: Dewdrop:Refresh(4) flickerstreak@1: Dewdrop:Refresh(5) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:IsActive() flickerstreak@1: 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: end flickerstreak@1: flickerstreak@1: function AceDB:ToggleActive(state) flickerstreak@1: AceDB:argCheck(state, 2, "boolean", "nil") flickerstreak@1: if not self.db or not self.db.raw then flickerstreak@1: AceDB:error("Cannot call \"ToggleActive\" before \"RegisterDB\" has been called and before \"ADDON_LOADED\" has been fired.") flickerstreak@1: end flickerstreak@1: local db = self.db flickerstreak@1: if not db.raw.disabled then flickerstreak@1: db.raw.disabled = setmetatable({}, caseInsensitive_mt) flickerstreak@1: end flickerstreak@1: local profile = db.raw.currentProfile[charID] flickerstreak@1: local disable flickerstreak@1: if state == nil then flickerstreak@1: disable = not db.raw.disabled[profile] flickerstreak@1: else flickerstreak@1: disable = not state flickerstreak@1: if disable == db.raw.disabled[profile] then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: end flickerstreak@1: db.raw.disabled[profile] = disable or nil flickerstreak@1: if AceOO.inherits(self, "AceAddon-2.0") then flickerstreak@1: local AceAddon = AceLibrary("AceAddon-2.0") flickerstreak@1: if not AceAddon.addonsStarted[self] then flickerstreak@1: return flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if not disable then flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedEnable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedEnable, mixin, self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnEnable) == "function" then flickerstreak@1: safecall(self.OnEnable, self) flickerstreak@1: end flickerstreak@1: if AceEvent then flickerstreak@1: AceEvent:TriggerEvent("Ace2_AddonEnabled", self) flickerstreak@1: end flickerstreak@1: else flickerstreak@1: local current = self.class flickerstreak@1: while current and current ~= AceOO.Class do flickerstreak@1: if current.mixins then flickerstreak@1: for mixin in pairs(current.mixins) do flickerstreak@1: if type(mixin.OnEmbedDisable) == "function" then flickerstreak@1: safecall(mixin.OnEmbedDisable, mixin, self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: current = current.super flickerstreak@1: end flickerstreak@1: if type(self.OnDisable) == "function" then flickerstreak@1: safecall(self.OnDisable, self) flickerstreak@1: end flickerstreak@1: if AceEvent then flickerstreak@1: AceEvent:TriggerEvent("Ace2_AddonDisabled", self) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: return not disable flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:embed(target) flickerstreak@1: self.super.embed(self, target) flickerstreak@1: if not AceEvent then flickerstreak@1: AceDB:error(MAJOR_VERSION .. " requires AceEvent-2.0") flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:ADDON_LOADED(name) flickerstreak@1: AceDB.addonsLoaded[name] = true flickerstreak@1: for addon, addonName in pairs(AceDB.addonsToBeInitialized) do flickerstreak@1: if name == addonName then flickerstreak@1: AceDB.InitializeDB(addon, name) flickerstreak@1: AceDB.addonsToBeInitialized[addon] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:PLAYER_LOGOUT() flickerstreak@1: for addon in pairs(AceDB.registry) do flickerstreak@1: local db = addon.db flickerstreak@1: if db then flickerstreak@1: setmetatable(db, nil) flickerstreak@1: CrawlForSerialization(db.raw) flickerstreak@1: if type(_G[db.charName]) == "table" then flickerstreak@1: CrawlForSerialization(_G[db.charName]) flickerstreak@1: end flickerstreak@1: if db.char and cleanDefaults(db.char, db.defaults and db.defaults.char) then flickerstreak@1: if db.charName and _G[db.charName] and _G[db.charName].global == db.char then flickerstreak@1: _G[db.charName].global = nil flickerstreak@1: if not next(_G[db.charName]) then flickerstreak@1: _G[db.charName] = nil flickerstreak@1: end flickerstreak@1: else flickerstreak@1: if db.raw.chars then flickerstreak@1: db.raw.chars[charID] = nil flickerstreak@1: if not next(db.raw.chars) then flickerstreak@1: db.raw.chars = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.realm and cleanDefaults(db.realm, db.defaults and db.defaults.realm) then flickerstreak@1: if db.raw.realms then flickerstreak@1: db.raw.realms[realmID] = nil flickerstreak@1: if not next(db.raw.realms) then flickerstreak@1: db.raw.realms = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.faction and cleanDefaults(db.faction, db.defaults and db.defaults.faction) then flickerstreak@1: if db.raw.factions then flickerstreak@1: db.raw.factions[faction] = nil flickerstreak@1: if not next(db.raw.factions) then flickerstreak@1: db.raw.factions = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.class and cleanDefaults(db.class, db.defaults and db.defaults.class) then flickerstreak@1: if db.raw.classes then flickerstreak@1: db.raw.classes[classID] = nil flickerstreak@1: if not next(db.raw.classes) then flickerstreak@1: db.raw.classes = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.account and cleanDefaults(db.account, db.defaults and db.defaults.account) then flickerstreak@1: db.raw.account = nil flickerstreak@1: end flickerstreak@1: if db.profile and cleanDefaults(db.profile, db.defaults and db.defaults.profile) then flickerstreak@1: if db.raw.profiles then flickerstreak@1: db.raw.profiles[db.raw.currentProfile and db.raw.currentProfile[charID] or "Default"] = nil flickerstreak@1: if not next(db.raw.profiles) then flickerstreak@1: db.raw.profiles = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.namespaces and db.raw.namespaces then flickerstreak@1: for name,v in pairs(db.namespaces) do flickerstreak@1: if db.raw.namespaces[name] then flickerstreak@1: setmetatable(v, nil) flickerstreak@1: if v.char and cleanDefaults(v.char, v.defaults and v.defaults.char) then flickerstreak@1: if db.charName and _G[db.charName] and _G[db.charName].namespaces and _G[db.charName].namespaces[name] == v then flickerstreak@1: _G[db.charName].namespaces[name] = nil flickerstreak@1: if not next(_G[db.charName].namespaces) then flickerstreak@1: _G[db.charName].namespaces = nil flickerstreak@1: if not next(_G[db.charName]) then flickerstreak@1: _G[db.charName] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: else flickerstreak@1: if db.raw.namespaces[name].chars then flickerstreak@1: db.raw.namespaces[name].chars[charID] = nil flickerstreak@1: if not next(db.raw.namespaces[name].chars) then flickerstreak@1: db.raw.namespaces[name].chars = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if v.realm and cleanDefaults(v.realm, v.defaults and v.defaults.realm) then flickerstreak@1: if db.raw.namespaces[name].realms then flickerstreak@1: db.raw.namespaces[name].realms[realmID] = nil flickerstreak@1: if not next(db.raw.namespaces[name].realms) then flickerstreak@1: db.raw.namespaces[name].realms = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if v.faction and cleanDefaults(v.faction, v.defaults and v.defaults.faction) then flickerstreak@1: if db.raw.namespaces[name].factions then flickerstreak@1: db.raw.namespaces[name].factions[faction] = nil flickerstreak@1: if not next(db.raw.namespaces[name].factions) then flickerstreak@1: db.raw.namespaces[name].factions = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if v.class and cleanDefaults(v.class, v.defaults and v.defaults.class) then flickerstreak@1: if db.raw.namespaces[name].classes then flickerstreak@1: db.raw.namespaces[name].classes[classID] = nil flickerstreak@1: if not next(db.raw.namespaces[name].classes) then flickerstreak@1: db.raw.namespaces[name].classes = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if v.account and cleanDefaults(v.account, v.defaults and v.defaults.account) then flickerstreak@1: db.raw.namespaces[name].account = nil flickerstreak@1: end flickerstreak@1: if v.profile and cleanDefaults(v.profile, v.defaults and v.defaults.profile) then flickerstreak@1: if db.raw.namespaces[name].profiles then flickerstreak@1: db.raw.namespaces[name].profiles[db.raw.currentProfile and db.raw.currentProfile[charID] or "Default"] = nil flickerstreak@1: if not next(db.raw.namespaces[name].profiles) then flickerstreak@1: db.raw.namespaces[name].profiles = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if not next(db.raw.namespaces[name]) then flickerstreak@1: db.raw.namespaces[name] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if not next(db.raw.namespaces) then flickerstreak@1: db.raw.namespaces = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if db.raw.disabled and not next(db.raw.disabled) then flickerstreak@1: db.raw.disabled = nil flickerstreak@1: end flickerstreak@1: if db.raw.currentProfile then flickerstreak@1: for k,v in pairs(db.raw.currentProfile) do flickerstreak@1: if string.lower(v) == "default" then flickerstreak@1: db.raw.currentProfile[k] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if not next(db.raw.currentProfile) then flickerstreak@1: db.raw.currentProfile = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: if _G[db.name] and not next(_G[db.name]) then flickerstreak@1: _G[db.name] = nil flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:AcquireDBNamespace(name) flickerstreak@1: AceDB:argCheck(name, 2, "string") flickerstreak@1: local db = self.db flickerstreak@1: if not db then flickerstreak@1: AceDB:error("Cannot call `AcquireDBNamespace' before `RegisterDB' has been called.", 2) flickerstreak@1: end flickerstreak@1: if not db.namespaces then flickerstreak@1: rawset(db, 'namespaces', {}) flickerstreak@1: end flickerstreak@1: if not db.namespaces[name] then flickerstreak@1: local namespace = {} flickerstreak@1: db.namespaces[name] = namespace flickerstreak@1: namespace.db = db flickerstreak@1: namespace.name = name flickerstreak@1: setmetatable(namespace, namespace_mt) flickerstreak@1: end flickerstreak@1: return db.namespaces[name] flickerstreak@1: end flickerstreak@1: flickerstreak@1: function AceDB:GetAceOptionsDataTable(target) flickerstreak@1: if not target['acedb-profile-list'] then flickerstreak@1: target['acedb-profile-list'] = setmetatable({}, caseInsensitive_mt) flickerstreak@1: RecalculateAceDBProfileList(target) flickerstreak@1: end flickerstreak@1: if not target['acedb-profile-copylist'] then flickerstreak@1: target['acedb-profile-copylist'] = setmetatable({}, caseInsensitive_mt) flickerstreak@1: RecalculateAceDBCopyFromList(target) flickerstreak@1: end flickerstreak@1: return { flickerstreak@1: standby = { flickerstreak@1: cmdName = STATE, flickerstreak@1: guiName = ENABLED, flickerstreak@1: name = ACTIVE, flickerstreak@1: desc = TOGGLE_ACTIVE, flickerstreak@1: type = "toggle", flickerstreak@1: get = "IsActive", flickerstreak@1: set = "ToggleActive", flickerstreak@1: map = MAP_ACTIVESUSPENDED, flickerstreak@1: order = -3, flickerstreak@1: }, flickerstreak@1: profile = { flickerstreak@1: type = 'group', flickerstreak@1: name = PROFILE, flickerstreak@1: desc = SET_PROFILE, flickerstreak@1: order = -3.5, flickerstreak@1: get = "GetProfile", flickerstreak@1: args = { flickerstreak@1: choose = { flickerstreak@1: guiName = CHOOSE_PROFILE_GUI, flickerstreak@1: cmdName = PROFILE, flickerstreak@1: desc = CHOOSE_PROFILE_DESC, flickerstreak@1: type = 'text', flickerstreak@1: get = "GetProfile", flickerstreak@1: set = "SetProfile", flickerstreak@1: validate = target['acedb-profile-list'] flickerstreak@1: }, flickerstreak@1: copy = { flickerstreak@1: guiName = COPY_PROFILE_GUI, flickerstreak@1: cmdName = PROFILE, flickerstreak@1: desc = COPY_PROFILE_DESC, flickerstreak@1: type = 'text', flickerstreak@1: get = false, flickerstreak@1: set = "CopyProfileFrom", flickerstreak@1: validate = target['acedb-profile-copylist'], flickerstreak@1: disabled = function() flickerstreak@1: return not next(target['acedb-profile-copylist']) flickerstreak@1: end, flickerstreak@1: }, flickerstreak@1: other = { flickerstreak@1: guiName = OTHER_PROFILE_GUI, flickerstreak@1: cmdName = PROFILE, flickerstreak@1: desc = OTHER_PROFILE_DESC, flickerstreak@1: usage = OTHER_PROFILE_USAGE, flickerstreak@1: type = 'text', flickerstreak@1: get = "GetProfile", flickerstreak@1: set = "SetProfile", flickerstreak@1: } flickerstreak@1: } flickerstreak@1: }, flickerstreak@1: } flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function activate(self, oldLib, oldDeactivate) flickerstreak@1: AceDB = self flickerstreak@1: AceEvent = AceLibrary:HasInstance("AceEvent-2.0") and AceLibrary("AceEvent-2.0") flickerstreak@1: flickerstreak@1: self.addonsToBeInitialized = oldLib and oldLib.addonsToBeInitialized or {} flickerstreak@1: self.addonsLoaded = oldLib and oldLib.addonsLoaded or {} flickerstreak@1: self.registry = oldLib and oldLib.registry or {} flickerstreak@1: flickerstreak@1: self:activate(oldLib, oldDeactivate) flickerstreak@1: flickerstreak@1: for t in pairs(self.embedList) do flickerstreak@1: if t.db then flickerstreak@1: rawset(t.db, 'char', nil) flickerstreak@1: rawset(t.db, 'realm', nil) flickerstreak@1: rawset(t.db, 'class', nil) flickerstreak@1: rawset(t.db, 'account', nil) flickerstreak@1: rawset(t.db, 'faction', nil) flickerstreak@1: rawset(t.db, 'profile', nil) flickerstreak@1: setmetatable(t.db, db_mt) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: if oldLib then flickerstreak@1: oldDeactivate(oldLib) flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: local function external(self, major, instance) flickerstreak@1: if major == "AceEvent-2.0" then flickerstreak@1: AceEvent = instance flickerstreak@1: flickerstreak@1: AceEvent:embed(self) flickerstreak@1: flickerstreak@1: self:RegisterEvent("ADDON_LOADED") flickerstreak@1: self:RegisterEvent("PLAYER_LOGOUT") flickerstreak@1: elseif major == "Dewdrop-2.0" then flickerstreak@1: Dewdrop = instance flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: AceLibrary:Register(AceDB, MAJOR_VERSION, MINOR_VERSION, activate, nil, external) flickerstreak@1: AceDB = AceLibrary(MAJOR_VERSION)