mirror of
https://github.com/Bluewhale1337/ElvUIModernized.git
synced 2026-07-27 08:24:44 +00:00
update ClassCache
This commit is contained in:
+55
-114
@@ -25,6 +25,7 @@ local UnitName = UnitName
|
|||||||
|
|
||||||
local UNKNOWN = UNKNOWN
|
local UNKNOWN = UNKNOWN
|
||||||
|
|
||||||
|
local MYREALM = E.myrealm
|
||||||
local GAME_LOCALE = GetLocale()
|
local GAME_LOCALE = GetLocale()
|
||||||
local ENGLISH_CLASS_NAMES
|
local ENGLISH_CLASS_NAMES
|
||||||
|
|
||||||
@@ -50,41 +51,27 @@ local function GetEnglishClassName(class)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function WhoCallback(result)
|
local function WhoCallback(result)
|
||||||
if result then
|
if result and result.NoLocaleClass then
|
||||||
if result.NoLocaleClass then
|
|
||||||
CC:CachePlayer(result.Name, result.NoLocaleClass)
|
CC:CachePlayer(result.Name, result.NoLocaleClass)
|
||||||
CC:SendMessage("ClassCacheQueryResult", result.Name, result.NoLocaleClass)
|
CC:SendMessage("ClassCacheQueryResult", result.Name, result.NoLocaleClass)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function CC:GetClassByName(name, realm)
|
function CC:GetClassByName(name, realm)
|
||||||
if not name or name == "" then return end
|
if not name or name == "" then return end
|
||||||
if realm and realm == "" then return end
|
if realm and realm == "" then return end
|
||||||
|
|
||||||
if E.db.general.classCacheStoreInDB then
|
local cacheDB = self:GetCacheTable()
|
||||||
|
|
||||||
if realm then
|
if realm then
|
||||||
if self.cache[realm] and self.cache[realm][name] then
|
if cacheDB[realm] and cacheDB[realm][name] then
|
||||||
return self.cache[realm][name]
|
return cacheDB[realm][name]
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if self.cache[E.myrealm][name] then
|
if cacheDB[MYREALM][name] then
|
||||||
return self.cache[E.myrealm][name]
|
return cacheDB[MYREALM][name]
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if realm then
|
|
||||||
if self.tempCache[realm] and self.tempCache[realm][name] then
|
|
||||||
return self.tempCache[realm][name]
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if self.tempCache[E.myrealm][name] then
|
|
||||||
return self.tempCache[E.myrealm][name]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -109,68 +96,32 @@ function CC:CachePlayer(name, class, realm)
|
|||||||
|
|
||||||
if realm and realm == "" then return end
|
if realm and realm == "" then return end
|
||||||
|
|
||||||
if E.db.general.classCacheStoreInDB then
|
local cacheDB = self:GetCacheTable()
|
||||||
if realm and not self.cache[realm] then
|
realm = realm or MYREALM
|
||||||
self.cache[realm] = {}
|
|
||||||
|
cacheDB[realm] = cacheDB[realm] or {}
|
||||||
|
|
||||||
|
if cacheDB[realm][name] ~= class then
|
||||||
|
CC:SendMessage("ClassCache_ClassUpdated", name, class)
|
||||||
end
|
end
|
||||||
|
|
||||||
if realm then
|
cacheDB[realm][name] = class
|
||||||
self.cache[realm][name] = class
|
|
||||||
else
|
|
||||||
self.cache[E.myrealm][name] = class
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if realm and not self.tempCache[realm] then
|
|
||||||
self.tempCache[realm] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
if realm then
|
|
||||||
self.tempCache[realm][name] = class
|
|
||||||
else
|
|
||||||
self.tempCache[E.myrealm][name] = class
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function CC:SwitchCacheType(init)
|
function CC:SwitchCacheType(init)
|
||||||
if E.db.general.classCacheStoreInDB then
|
local newDB = self:GetCacheTable()
|
||||||
if not self.cache[E.myrealm] then
|
|
||||||
self.cache[E.myrealm] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
if not self.cache[E.myrealm][E.myname] then
|
newDB[MYREALM] = newDB[MYREALM] or {}
|
||||||
self.cache[E.myrealm][E.myname] = E.myclass
|
newDB[MYREALM][E.myname] = E.myclass
|
||||||
end
|
|
||||||
|
|
||||||
if not init then
|
if not init then
|
||||||
for realm in pairs(self.tempCache) do
|
local oldDB = E.db.general.classCacheStoreInDB and self.tempCache or self.cache
|
||||||
if not self.cache[realm] then
|
|
||||||
self.cache[realm] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
for name, class in pairs(self.tempCache[realm]) do
|
for realm in pairs(oldDB) do
|
||||||
self.cache[realm][name] = class
|
newDB[realm] = newDB[realm] or {}
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if not self.tempCache[E.myrealm] then
|
|
||||||
self.tempCache[E.myrealm] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
if not self.tempCache[E.myrealm][E.myname] then
|
for name, class in pairs(oldDB[realm]) do
|
||||||
self.tempCache[E.myrealm][E.myname] = E.myclass
|
newDB[realm][name] = class
|
||||||
end
|
|
||||||
|
|
||||||
if not init then
|
|
||||||
for realm in pairs(self.cache) do
|
|
||||||
if not self.cache[realm] then
|
|
||||||
self.tempCache[realm] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
for name, class in pairs(self.cache[realm]) do
|
|
||||||
self.tempCache[realm][name] = class
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -192,23 +143,18 @@ function CC:GetCacheSize(global)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local size = 0
|
local size = 0
|
||||||
|
local cacheDB = global and self.cache or self.tempCache
|
||||||
|
|
||||||
if global then
|
for realm in pairs(cacheDB) do
|
||||||
for realm in pairs(self.cache) do
|
for _ in pairs(cacheDB[realm]) do
|
||||||
for _ in pairs(self.cache[realm]) do
|
|
||||||
size = size + 1
|
size = size + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if global then
|
||||||
self.cacheDBSize = size
|
self.cacheDBSize = size
|
||||||
self.cacheDBCalculationTime = GetTime()
|
self.cacheDBCalculationTime = GetTime()
|
||||||
else
|
else
|
||||||
for realm in pairs(self.tempCache) do
|
|
||||||
for _ in pairs(self.tempCache[realm]) do
|
|
||||||
size = size + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self.cacheLocalSize = size
|
self.cacheLocalSize = size
|
||||||
self.cacheLocalCalculationTime = GetTime()
|
self.cacheLocalCalculationTime = GetTime()
|
||||||
end
|
end
|
||||||
@@ -217,25 +163,20 @@ function CC:GetCacheSize(global)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function CC:WipeCache(global)
|
function CC:WipeCache(global)
|
||||||
if global then
|
local cacheDB = global and self.cache or self.tempCache
|
||||||
for realm in pairs(self.cache) do
|
|
||||||
wipe(self.cache[realm])
|
for realm in pairs(cacheDB) do
|
||||||
|
wipe(cacheDB[realm])
|
||||||
end
|
end
|
||||||
|
|
||||||
wipe(self.cache)
|
wipe(cacheDB)
|
||||||
self:SwitchCacheType(true)
|
self:SwitchCacheType(true)
|
||||||
self.cacheDBCalculationTime = 0
|
|
||||||
|
|
||||||
|
if global then
|
||||||
|
self.cacheDBCalculationTime = 0
|
||||||
E:Print(L["Class DB cache wiped."])
|
E:Print(L["Class DB cache wiped."])
|
||||||
else
|
else
|
||||||
for realm in pairs(self.tempCache) do
|
|
||||||
wipe(self.tempCache[realm])
|
|
||||||
end
|
|
||||||
|
|
||||||
wipe(self.tempCache)
|
|
||||||
self:SwitchCacheType(true)
|
|
||||||
self.cacheLocalCalculationTime = 0
|
self.cacheLocalCalculationTime = 0
|
||||||
|
|
||||||
E:Print(L["Class session cache wiped."])
|
E:Print(L["Class session cache wiped."])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -245,12 +186,12 @@ function CC:PLAYER_ENTERING_WORLD()
|
|||||||
self.inInstance = inInstance
|
self.inInstance = inInstance
|
||||||
|
|
||||||
if instanceType == "pvp" then
|
if instanceType == "pvp" then
|
||||||
self.inBattleground = true
|
self.onBattleground = instanceType
|
||||||
else
|
else
|
||||||
self.inBattleground = false
|
self.onBattleground = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.inInstance or self.inBattleground then
|
if self.inInstance or self.onBattleground then
|
||||||
self.lastNumPlayers = 0
|
self.lastNumPlayers = 0
|
||||||
|
|
||||||
self:UnregisterEvent("PLAYER_TARGET_CHANGED")
|
self:UnregisterEvent("PLAYER_TARGET_CHANGED")
|
||||||
@@ -262,7 +203,7 @@ function CC:PLAYER_ENTERING_WORLD()
|
|||||||
|
|
||||||
self:RegisterEvent("UPDATE_BATTLEFIELD_SCORE")
|
self:RegisterEvent("UPDATE_BATTLEFIELD_SCORE")
|
||||||
|
|
||||||
if self.inBattleground then
|
if self.onBattleground then
|
||||||
self:UPDATE_BATTLEFIELD_SCORE()
|
self:UPDATE_BATTLEFIELD_SCORE()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -301,13 +242,13 @@ function CC:PLAYER_GUILD_UPDATE()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function CC:FRIENDLIST_UPDATE()
|
function CC:FRIENDLIST_UPDATE()
|
||||||
local name, class, _
|
local name, classLocalized, _
|
||||||
|
|
||||||
for i = 1, GetNumFriends() do
|
for i = 1, GetNumFriends() do
|
||||||
name, _, class = GetFriendInfo(i)
|
name, _, classLocalized = GetFriendInfo(i)
|
||||||
|
|
||||||
if class then
|
if classLocalized then
|
||||||
self:CachePlayer(name, GetEnglishClassName(class))
|
self:CachePlayer(name, GetEnglishClassName(classLocalized))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -315,13 +256,13 @@ end
|
|||||||
function CC:GUILD_ROSTER_UPDATE(_, update)
|
function CC:GUILD_ROSTER_UPDATE(_, update)
|
||||||
if not update then return end
|
if not update then return end
|
||||||
|
|
||||||
local name, class, _
|
local name, classLocalized, _
|
||||||
|
|
||||||
for i = 1, GetNumGuildMembers() do
|
for i = 1, GetNumGuildMembers() do
|
||||||
name, _, _, _, _, _, _, _, _, _, class = GetGuildRosterInfo(i)
|
name, _, _, _, _, classLocalized = GetGuildRosterInfo(i)
|
||||||
|
|
||||||
if class then
|
if classLocalized then
|
||||||
self:CachePlayer(name, class)
|
self:CachePlayer(name, GetEnglishClassName(classLocalized))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -335,7 +276,7 @@ function CC:PARTY_MEMBERS_CHANGED()
|
|||||||
|
|
||||||
if not class then return end
|
if not class then return end
|
||||||
|
|
||||||
if self.inBattleground then
|
if self.onBattleground then
|
||||||
self:CachePlayer(name, class, realm)
|
self:CachePlayer(name, class, realm)
|
||||||
else
|
else
|
||||||
self:CachePlayer(name, class)
|
self:CachePlayer(name, class)
|
||||||
@@ -352,7 +293,7 @@ function CC:RAID_ROSTER_UPDATE()
|
|||||||
|
|
||||||
if not class then return end
|
if not class then return end
|
||||||
|
|
||||||
if self.inBattleground then
|
if self.onBattleground then
|
||||||
self:CachePlayer(name, class, realm)
|
self:CachePlayer(name, class, realm)
|
||||||
else
|
else
|
||||||
self:CachePlayer(name, class)
|
self:CachePlayer(name, class)
|
||||||
@@ -368,7 +309,7 @@ function CC:PLAYER_TARGET_CHANGED()
|
|||||||
|
|
||||||
local name, realm = UnitName("target")
|
local name, realm = UnitName("target")
|
||||||
|
|
||||||
if self.inBattleground then
|
if self.onBattleground then
|
||||||
self:CachePlayer(name, class, realm)
|
self:CachePlayer(name, class, realm)
|
||||||
else
|
else
|
||||||
self:CachePlayer(name, class)
|
self:CachePlayer(name, class)
|
||||||
@@ -383,7 +324,7 @@ function CC:UPDATE_MOUSEOVER_UNIT()
|
|||||||
|
|
||||||
local name, realm = UnitName("mouseover")
|
local name, realm = UnitName("mouseover")
|
||||||
|
|
||||||
if self.inBattleground then
|
if self.onBattleground then
|
||||||
self:CachePlayer(name, class, realm)
|
self:CachePlayer(name, class, realm)
|
||||||
else
|
else
|
||||||
self:CachePlayer(name, class)
|
self:CachePlayer(name, class)
|
||||||
@@ -400,14 +341,14 @@ function CC:UPDATE_BATTLEFIELD_SCORE()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local name, realm, class, _
|
local name, realm, classLocalized, _
|
||||||
|
|
||||||
for i = 1, numPlayers do
|
for i = 1, numPlayers do
|
||||||
name, _, _, _, _, _, _, _, _, class = GetBattlefieldScore(i)
|
name, _, _, _, _, _, _, _, classLocalized = GetBattlefieldScore(i)
|
||||||
|
|
||||||
if name and class then
|
if name and classLocalized then
|
||||||
name, realm = split("-", name)
|
name, realm = split("-", name)
|
||||||
self:CachePlayer(name, class, realm)
|
self:CachePlayer(name, GetEnglishClassName(classLocalized), realm)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user