From 5e7df0d94af57c1dce367cf1ed2d8b6617734295 Mon Sep 17 00:00:00 2001 From: Tercio Jose Date: Wed, 8 Nov 2023 20:25:25 -0300 Subject: [PATCH] Added Details:GetUntitClass(unitId), this call handles the Ambiguate in combatlog's player name when calling UnitClass --- boot.lua | 19 ++++++++++++++-- classes/class_utility.lua | 18 +++++++-------- classes/container_actors.lua | 2 +- core/gears.lua | 4 ++-- core/plugins_raid.lua | 8 +++---- .../window_playerbreakdown_list.lua | 3 --- functions/classes.lua | 22 +++++++++++++++++++ functions/dungeon.lua | 2 +- functions/playerclass.lua | 20 ++++++++--------- 9 files changed, 66 insertions(+), 32 deletions(-) diff --git a/boot.lua b/boot.lua index cac7fdc1a..b2642300b 100644 --- a/boot.lua +++ b/boot.lua @@ -13,8 +13,8 @@ local addonName, Details222 = ... local version, build, date, tocversion = GetBuildInfo() - Details.build_counter = 12025 - Details.alpha_build_counter = 12025 --if this is higher than the regular counter, use it instead + Details.build_counter = 12026 + Details.alpha_build_counter = 12026 --if this is higher than the regular counter, use it instead Details.dont_open_news = true Details.game_version = version Details.userversion = version .. " " .. Details.build_counter @@ -1360,6 +1360,21 @@ if (select(4, GetBuildInfo()) >= 100000) then end) end +local classCacheName = Details222.ClassCache.ByName +local classCacheGUID = Details222.ClassCache.ByGUID + +function Details222.ClassCache.GetClassFromCache(value) + return classCacheName[value] or classCacheGUID[value] +end + +function Details222.ClassCache.AddClassToCache(value, whichCache) + if (whichCache == "name") then + classCacheName[value] = true + elseif (whichCache == "guid") then + classCacheGUID[value] = true + end +end + function Details222.ClassCache.GetClass(value) local className = Details222.ClassCache.ByName[value] or Details222.ClassCache.ByGUID[value] if (className) then diff --git a/classes/class_utility.lua b/classes/class_utility.lua index 55092ca9a..323fb1036 100644 --- a/classes/class_utility.lua +++ b/classes/class_utility.lua @@ -1514,10 +1514,10 @@ function _detalhes:CatchRaidBuffUptime (in_or_out) for playername, potspellid in pairs(pot_usage) do local name, _, icon = _GetSpellInfo(potspellid) - local _, class = UnitClass(playername) + local unitClass = Details:GetUnitClass(playername) local class_color = "" - if (class and RAID_CLASS_COLORS [class]) then - class_color = RAID_CLASS_COLORS [class].colorStr + if (unitClass and RAID_CLASS_COLORS[unitClass]) then + class_color = RAID_CLASS_COLORS[unitClass].colorStr end string_output = string_output .. "|c" .. class_color .. playername .. "|r |T" .. icon .. ":14:14:0:0:64:64:0:64:0:64|t " end @@ -1586,10 +1586,10 @@ function _detalhes:CatchRaidBuffUptime (in_or_out) for playername, potspellid in pairs(pot_usage) do local name, _, icon = _GetSpellInfo(potspellid) - local _, class = UnitClass(playername) + local unitClass = Details:GetUnitClass(playername) local class_color = "" - if (class and RAID_CLASS_COLORS [class]) then - class_color = RAID_CLASS_COLORS [class].colorStr + if (unitClass and RAID_CLASS_COLORS[unitClass]) then + class_color = RAID_CLASS_COLORS[unitClass].colorStr end string_output = string_output .. "|c" .. class_color .. playername .. "|r |T" .. icon .. ":14:14:0:0:64:64:0:64:0:64|t " end @@ -1627,10 +1627,10 @@ function _detalhes:CatchRaidBuffUptime (in_or_out) local string_output = "pre-potion: " for playername, potspellid in pairs(pot_usage) do local name, _, icon = _GetSpellInfo(potspellid) - local _, class = UnitClass(playername) + local unitClass = Details:GetUnitClass(playername) local class_color = "" - if (class and RAID_CLASS_COLORS [class]) then - class_color = RAID_CLASS_COLORS [class].colorStr + if (unitClass and RAID_CLASS_COLORS[unitClass]) then + class_color = RAID_CLASS_COLORS[unitClass].colorStr end string_output = string_output .. "|c" .. class_color .. playername .. "|r |T" .. icon .. ":14:14:0:0:64:64:0:64:0:64|t " end diff --git a/classes/container_actors.lua b/classes/container_actors.lua index 443837e50..5ce447c17 100644 --- a/classes/container_actors.lua +++ b/classes/container_actors.lua @@ -458,7 +458,7 @@ end Details222.GuessSpecSchedules.Schedules[#Details222.GuessSpecSchedules.Schedules+1] = newTimer end - local _, engClass = UnitClass(actorName or "") + local engClass = Details:GetUnitClass(actorName or "") if (engClass) then actorObject.classe = engClass diff --git a/core/gears.lua b/core/gears.lua index e6db445c5..3835ad1f7 100644 --- a/core/gears.lua +++ b/core/gears.lua @@ -1758,7 +1758,7 @@ function Details.Database.StoreEncounter(combat) player_name = player_name .. "-" .. player_realm end - local _, _, class = UnitClass(player_name) + local _, _, class = Details:GetUnitClassFull(player_name) local damage_actor = damage_container_pool [damage_container_hash [player_name]] if (damage_actor) then @@ -1771,7 +1771,7 @@ function Details.Database.StoreEncounter(combat) player_name = player_name .. "-" .. player_realm end - local _, _, class = UnitClass(player_name) + local _, _, class = Details:GetUnitClassFull(player_name) local heal_actor = healing_container_pool [healing_container_hash [player_name]] if (heal_actor) then diff --git a/core/plugins_raid.lua b/core/plugins_raid.lua index 3c5f509c0..1a459c646 100644 --- a/core/plugins_raid.lua +++ b/core/plugins_raid.lua @@ -355,7 +355,7 @@ else local minute, second = _detalhes:GetCombat():GetFormatedCombatTime() - local _, class = _UnitClass(who_name) + local class = Details:GetUnitClass(who_name) local class_color = "|cFFFF3333" if (class) then @@ -457,10 +457,10 @@ local msg local minute, second = _detalhes:GetCombat():GetFormatedCombatTime() - local _, class = _UnitClass(who_name) + local class = Details:GetUnitClass(who_name) local class_color = "|cFFFFFFFF" - local _, class2 = _UnitClass(alvo_name) + local class2 = Details:GetUnitClass(alvo_name) local class_color2 = "|cFFFFFFFF" if (class) then @@ -556,7 +556,7 @@ local msg if (where == 4) then --observer - local _, class = _UnitClass(alvo_name) + local class = Details:GetUnitClass(alvo_name) local class_color = "|cFFFFFFFF" if (class) then diff --git a/frames/window_breakdown/window_playerbreakdown_list.lua b/frames/window_breakdown/window_playerbreakdown_list.lua index fd571de75..738f5bad3 100644 --- a/frames/window_breakdown/window_playerbreakdown_list.lua +++ b/frames/window_breakdown/window_playerbreakdown_list.lua @@ -225,9 +225,6 @@ function breakdownWindowPlayerList.CreatePlayerListFrame() self.playerName:SetText(Details:GetOnlyName(self.playerObject.nome)) self.rankText:SetText(self.index) --not in use - --set the player class name - --self.className:SetText(string.lower(_G.UnitClass(self.playerObject.nome) or self.playerObject:Class())) --not in use - --item level self.itemLevelText:SetText(self.playerObject.ilvl or (playerGear and playerGear.ilevel) or "0") diff --git a/functions/classes.lua b/functions/classes.lua index 0be5b42ed..a5b377931 100644 --- a/functions/classes.lua +++ b/functions/classes.lua @@ -174,6 +174,28 @@ do end end + ---return the class file name of the unit passed + local getFromCache = Details222.ClassCache.GetClassFromCache + local Ambiguate = Ambiguate + local UnitClass = UnitClass + function Details:GetUnitClass(unitId) + local class, classFileName = getFromCache(unitId) + + if (not classFileName) then + unitId = Ambiguate(unitId, "none") + classFileName = select(2, UnitClass(unitId)) + end + + return classFileName + end + + ---return the class name, class file name and class id of the unit passed + function Details:GetUnitClassFull(unitId) + unitId = Ambiguate(unitId, "none") + local locClassName, classFileName, classId = UnitClass(unitId) + return locClassName, classFileName, classId + end + function Details:GetFullName(unitId) --playerName, realmName = UnitFullName(unitId) --realm name already has spaces removed --return playerName .. "-" .. realmName diff --git a/functions/dungeon.lua b/functions/dungeon.lua index c7504a86b..66ca1284b 100644 --- a/functions/dungeon.lua +++ b/functions/dungeon.lua @@ -157,7 +157,7 @@ local tickerCallback = function(tickerObject) end end - addPlayerDamage(UnitName ("player")) + addPlayerDamage(UnitName("player")) end function mythicDungeonCharts:OnBossDefeated() diff --git a/functions/playerclass.lua b/functions/playerclass.lua index 53bb990ce..ead02d61e 100644 --- a/functions/playerclass.lua +++ b/functions/playerclass.lua @@ -103,12 +103,12 @@ do ---@param actorName string ---@return string className, number left, number right, number top, number bottom, number red, number green, number blue, number alpha function Details:GetClass(actorName) - local _, class = UnitClass(actorName) + local unitClass = Details:GetUnitClass(actorName) - if (class) then - local left, right, top, bottom = unpack(Details.class_coords[class]) - local r, g, b = unpack(Details.class_colors[class]) - return class, left, right, top, bottom, r or 1, g or 1, b or 1, 1 + if (unitClass) then + local left, right, top, bottom = unpack(Details.class_coords[unitClass]) + local r, g, b = unpack(Details.class_colors[unitClass]) + return unitClass, left, right, top, bottom, r or 1, g or 1, b or 1, 1 else local overallCombatObject = Details:GetCombat(DETAILS_SEGMENTID_OVERALL) for containerId = 1, DETAILS_COMBAT_AMOUNT_CONTAINERS do @@ -116,12 +116,12 @@ do local actorObject = actorContainer:GetActor(actorName) if (actorObject) then - class = actorObject:Class() - if (class) then + unitClass = actorObject:Class() + if (unitClass) then --found the class of the actor - local left, right, top, bottom = unpack(Details.class_coords[class] or CONST_UNKNOWN_CLASS_COORDS) - local r, g, b = unpack(Details.class_colors[class]) - return class, left, right, top, bottom, r or 1, g or 1, b or 1, 1 + local left, right, top, bottom = unpack(Details.class_coords[unitClass] or CONST_UNKNOWN_CLASS_COORDS) + local r, g, b = unpack(Details.class_colors[unitClass]) + return unitClass, left, right, top, bottom, r or 1, g or 1, b or 1, 1 end end end