- updated all libraries
This commit is contained in:
+122
-14
@@ -41,7 +41,7 @@
|
||||
-- @class file
|
||||
-- @name AceDB-3.0.lua
|
||||
-- @release $Id$
|
||||
local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 27
|
||||
local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 40
|
||||
local AceDB = LibStub:NewLibrary(ACEDB_MAJOR, ACEDB_MINOR)
|
||||
|
||||
if not AceDB then return end -- No upgrade needed
|
||||
@@ -49,6 +49,7 @@ if not AceDB then return end -- No upgrade needed
|
||||
-- Lua APIs
|
||||
local type, pairs, next, error = type, pairs, next, error
|
||||
local setmetatable, rawset, rawget = setmetatable, rawset, rawget
|
||||
local strlenutf8 = strlenutf8
|
||||
|
||||
-- WoW APIs
|
||||
local _G = _G
|
||||
@@ -251,17 +252,43 @@ local preserve_keys = {
|
||||
["children"] = true,
|
||||
}
|
||||
|
||||
local realmKey = GetRealmName()
|
||||
local charKey = UnitName("player") .. " - " .. realmKey
|
||||
local _, classKey = UnitClass("player")
|
||||
local _, raceKey = UnitRace("player")
|
||||
local factionKey = UnitFactionGroup("player")
|
||||
local factionrealmKey = factionKey .. " - " .. realmKey
|
||||
local localeKey = GetLocale():lower()
|
||||
local charKey, realmKey, classKey, raceKey, factionrealmKey, factionrealmregionKey
|
||||
do
|
||||
local _
|
||||
_, classKey = UnitClass("player")
|
||||
_, raceKey = UnitRace("player")
|
||||
|
||||
local regionTable = { "US", "KR", "EU", "TW", "CN" }
|
||||
local regionKey = regionTable[GetCurrentRegion()]
|
||||
local factionrealmregionKey = factionrealmKey .. " - " .. regionKey
|
||||
if RegionalUniqueNamesEnabled and RegionalUniqueNamesEnabled() then
|
||||
local isRP = C_GameRules.IsGameRuleActive(Enum.GameRule.RPRuleset)
|
||||
local isPVP = C_GameRules.IsGameRuleActive(Enum.GameRule.PvPRuleset)
|
||||
if C_GameRules.IsGameRuleActive(Enum.GameRule.HardcoreRuleset) then
|
||||
realmKey = "Hardcore"
|
||||
elseif isRP and isPVP then
|
||||
realmKey = "RP-PvP"
|
||||
elseif isRP then
|
||||
realmKey = "RP"
|
||||
elseif isPVP then
|
||||
realmKey = "PvP"
|
||||
else
|
||||
realmKey = "PvE"
|
||||
end
|
||||
local name, surname = UnitNameUnmodified("player")
|
||||
charKey = name .. " " .. surname
|
||||
else
|
||||
realmKey = GetRealmName()
|
||||
charKey = UnitNameUnmodified("player") .. " - " .. realmKey
|
||||
end
|
||||
|
||||
local regionTable = { "US", "KR", "EU", "TW", "CN" }
|
||||
local regionName = GetCurrentRegionName()
|
||||
if regionName and regionName == "" then regionName = nil end -- PTR/Beta tends to be ""
|
||||
local regionKey = regionTable[GetCurrentRegion()] or regionName or "TR"
|
||||
|
||||
factionrealmKey = factionKey .. " - " .. realmKey
|
||||
factionrealmregionKey = factionrealmKey .. " - " .. regionKey
|
||||
end
|
||||
|
||||
-- Actual database initialization function
|
||||
local function initdb(sv, defaults, defaultProfile, olddb, parent)
|
||||
@@ -275,6 +302,18 @@ local function initdb(sv, defaults, defaultProfile, olddb, parent)
|
||||
-- Make a container for profile keys
|
||||
if not sv.profileKeys then sv.profileKeys = {} end
|
||||
|
||||
-- Validate any existing profile name
|
||||
if sv.profileKeys[charKey] then
|
||||
if type(sv.profileKeys[charKey]) ~= "string" then
|
||||
sv.profileKeys[charKey] = defaultProfile or charKey
|
||||
else
|
||||
local profileNameLength = strlenutf8(sv.profileKeys[charKey])
|
||||
if profileNameLength == 0 or profileNameLength > 50 or sv.profileKeys[charKey]:find("^ +$") then
|
||||
sv.profileKeys[charKey] = defaultProfile or charKey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Try to get the profile selected from the char db
|
||||
profileKey = sv.profileKeys[charKey] or defaultProfile or charKey
|
||||
|
||||
@@ -360,7 +399,7 @@ local function logoutHandler(frame, event)
|
||||
|
||||
-- cleanup sections that are empty without defaults
|
||||
local sv = rawget(db, "sv")
|
||||
for section in pairs(db.keys) do
|
||||
for section in pairs(rawget(db, "keys")) do
|
||||
if rawget(sv, section) then
|
||||
-- global is special, all other sections have sub-entrys
|
||||
-- also don't delete empty profiles on main dbs, only on namespaces
|
||||
@@ -377,6 +416,26 @@ local function logoutHandler(frame, event)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- second pass after everything else is cleaned up to remove empty namespaces
|
||||
-- can't be run in-loop above since there is no guaranteed order
|
||||
for db in pairs(AceDB.db_registry) do
|
||||
local sv = rawget(db, "sv")
|
||||
local namespaces = rawget(sv, "namespaces")
|
||||
if namespaces then
|
||||
for name in pairs(namespaces) do
|
||||
-- cleanout empty profiles table, if still present
|
||||
if namespaces[name].profiles and not next(namespaces[name].profiles) then
|
||||
namespaces[name].profiles = nil
|
||||
end
|
||||
|
||||
-- remove entire namespace, if needed
|
||||
if not next(namespaces[name]) then
|
||||
namespaces[name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -426,6 +485,11 @@ end
|
||||
function DBObjectLib:SetProfile(name)
|
||||
if type(name) ~= "string" then
|
||||
error(("Usage: AceDBObject:SetProfile(name): 'name' - string expected, got %q."):format(type(name)), 2)
|
||||
else
|
||||
local profileNameLength = strlenutf8(name)
|
||||
if profileNameLength == 0 or profileNameLength > 50 or name:find("^ +$") then
|
||||
error("Usage: AceDBObject:SetProfile(name): 'name' - string length must be between 1 and 50 characters.", 2)
|
||||
end
|
||||
end
|
||||
|
||||
-- changing to the same profile, dont do anything
|
||||
@@ -525,6 +589,17 @@ function DBObjectLib:DeleteProfile(name, silent)
|
||||
end
|
||||
end
|
||||
|
||||
-- remove from unloaded namespaces
|
||||
if self.sv.namespaces then
|
||||
for nsname, data in pairs(self.sv.namespaces) do
|
||||
if self.children and self.children[nsname] then
|
||||
-- already a mapped namespace
|
||||
elseif data.profiles then
|
||||
data.profiles[name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- switch all characters that use this profile back to the default
|
||||
if self.sv.profileKeys then
|
||||
for key, profile in pairs(self.sv.profileKeys) do
|
||||
@@ -570,6 +645,20 @@ function DBObjectLib:CopyProfile(name, silent)
|
||||
end
|
||||
end
|
||||
|
||||
-- copy unloaded namespaces
|
||||
if self.sv.namespaces then
|
||||
for nsname, data in pairs(self.sv.namespaces) do
|
||||
if self.children and self.children[nsname] then
|
||||
-- already a mapped namespace
|
||||
elseif data.profiles then
|
||||
-- reset the current profile
|
||||
data.profiles[self.keys.profile] = {}
|
||||
-- copy data
|
||||
copyTable(data.profiles[name], data.profiles[self.keys.profile])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileCopied, database, sourceProfileKey
|
||||
self.callbacks:Fire("OnProfileCopied", self, name)
|
||||
end
|
||||
@@ -596,6 +685,18 @@ function DBObjectLib:ResetProfile(noChildren, noCallbacks)
|
||||
end
|
||||
end
|
||||
|
||||
-- reset unloaded namespaces
|
||||
if self.sv.namespaces and not noChildren then
|
||||
for nsname, data in pairs(self.sv.namespaces) do
|
||||
if self.children and self.children[nsname] then
|
||||
-- already a mapped namespace
|
||||
elseif data.profiles then
|
||||
-- reset the current profile
|
||||
data.profiles[self.keys.profile] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Callback: OnProfileReset, database
|
||||
if not noCallbacks then
|
||||
self.callbacks:Fire("OnProfileReset", self)
|
||||
@@ -606,8 +707,8 @@ end
|
||||
-- profile.
|
||||
-- @param defaultProfile The profile name to use as the default
|
||||
function DBObjectLib:ResetDB(defaultProfile)
|
||||
if defaultProfile and type(defaultProfile) ~= "string" then
|
||||
error(("Usage: AceDBObject:ResetDB(defaultProfile): 'defaultProfile' - string or nil expected, got %q."):format(type(defaultProfile)), 2)
|
||||
if defaultProfile and type(defaultProfile) ~= "string" and defaultProfile ~= true then
|
||||
error(("Usage: AceDBObject:ResetDB(defaultProfile): 'defaultProfile' - string or true expected, got %q."):format(type(defaultProfile)), 2)
|
||||
end
|
||||
|
||||
local sv = self.sv
|
||||
@@ -720,8 +821,15 @@ function AceDB:New(tbl, defaults, defaultProfile)
|
||||
error(("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaults' - table expected, got %q."):format(type(defaults)), 2)
|
||||
end
|
||||
|
||||
if defaultProfile and type(defaultProfile) ~= "string" and defaultProfile ~= true then
|
||||
error(("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaultProfile' - string or true expected, got %q."):format(type(defaultProfile)), 2)
|
||||
if defaultProfile then
|
||||
if type(defaultProfile) == "string" then
|
||||
local profileNameLength = strlenutf8(defaultProfile)
|
||||
if profileNameLength == 0 or profileNameLength > 50 or defaultProfile:find("^ +$") then
|
||||
error("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaultProfile' - string length must be between 1 and 50 characters.", 2)
|
||||
end
|
||||
elseif defaultProfile ~= true then
|
||||
error(("Usage: AceDB:New(tbl, defaults, defaultProfile): 'defaultProfile' - string or true expected, got %q."):format(type(defaultProfile)), 2)
|
||||
end
|
||||
end
|
||||
|
||||
return initdb(tbl, defaults, defaultProfile)
|
||||
|
||||
Reference in New Issue
Block a user