coa.5: refactor char display into guarded helpers; fix missed sites; restore login scan
release / release (push) Successful in 5s

- Extract AddCharacterTooltipHeader() + SetCharacterRowNameLevel() (Altoholic.lua);
  nil-guards centralized, callers in AccountSummary/Activity/BagUsage/Skills/tooltip.
- Fix sites the manual sweep missed: Skills.lua (row + skill ranks), Keys.lua x3,
  ShowClassIcons sort (Altoholic.lua:705, getters bypass their own or-0 via the wrapper).
- Restore login scan: OnPlayerAlive was ghost-only (fdcb25a) so iLvl never populated;
  now scans once per session. Removed dated DEBUG leftovers.
This commit is contained in:
2026-05-29 01:02:24 +02:00
parent 3fde42454e
commit 97e38d5c3d
10 changed files with 53 additions and 44 deletions
+29 -17
View File
@@ -249,10 +249,12 @@ end
-- *** Event Handlers ***
local hasScannedThisSession
local function OnPlayerAlive()
-- print("Altoholic.lua") -- DEBUG 2025 07 21
if not UnitIsGhost("player") then return end -- only scan if player released spirit and went to graveyard
-- CoA: scan once at login (see DataStore_Inventory / commit fdcb25a). FRIENDLIST_UPDATE also
-- keeps the friends list fresh; this just guarantees an initial scan without rescanning on res.
if hasScannedThisSession then return end
hasScannedThisSession = true
ScanFriends()
end
@@ -585,6 +587,22 @@ function addon:GetDelayInDays(delay)
return floor((time() - delay) / 86400)
end
-- CoA: shared, nil-safe character display helpers.
-- DataStore char-based getters return *no value* for any module that hasn't
-- scanned a given character (DataStore.lua: "if not arg1.lastUpdate then return end").
-- Fresh alts have partial per-module data, so every field is guarded here once
-- instead of being copy-pasted (and missed) across the frames.
function Altoholic:AddCharacterTooltipHeader(character)
AltoTooltip:AddDoubleLine(DS:GetColoredCharacterName(character) or "?", DS:GetColoredCharacterFaction(character) or "")
AltoTooltip:AddLine(format("%s %s |r%s %s", L["Level"],
GREEN..(DS:GetCharacterLevel(character) or 0), DS:GetCharacterRace(character) or "", DS:GetCharacterClass(character) or ""), 1, 1, 1)
end
function Altoholic:SetCharacterRowNameLevel(entry, i, icon, character)
_G[entry..i.."NameNormalText"]:SetText(icon .. format("%s (%s)", DS:GetColoredCharacterName(character) or "?", DS:GetCharacterClass(character) or ""))
_G[entry..i.."Level"]:SetText(GREEN .. (DS:GetCharacterLevel(character) or 0))
end
function Altoholic:FormatDelay(timeStamp)
-- timeStamp = value when time() was last called for a given variable (ex: last time the mailbox was checked)
if not timeStamp then
@@ -679,21 +697,18 @@ function Altoholic:ShowClassIcons()
local realm, account = Altoholic:GetCurrentRealm()
-- ####################
-- Sort characters by level first, then average item level. The getters yield no value
-- for alts whose Characters/Inventory module hasn't scanned them, so default [3]/[4] to 0.
local CharNameList = DS:GetCharacters(realm, account)
local CharNameList_sort = {}
for k,v in pairs(CharNameList) do
table.insert(CharNameList_sort,{k,v, DS:GetAverageItemLevel(v), DS:GetCharacterLevel(v)})
table.insert(CharNameList_sort, {k, v, DS:GetAverageItemLevel(v) or 0, DS:GetCharacterLevel(v) or 0})
end
-- sort for level first, avg iLevel secondly
table.sort(CharNameList_sort, function(a,b) return b[3]+b[4]*10000 < a[3]+a[4]*10000 end)
-- DEBUG_CHARLIST = CharNameList
-- print("-- altoholic DEBUG READY")
-- ####################
-- for characterName, character in pairs(DS:GetCharacters(realm, account)) do
for _,charTbl in ipairs(CharNameList_sort) do
local characterName, character = charTbl[1], charTbl[2]
@@ -763,10 +778,7 @@ function Altoholic:DrawCharacterTooltip(self, charName)
AltoTooltip:SetOwner(self, "ANCHOR_LEFT");
AltoTooltip:ClearLines();
AltoTooltip:AddDoubleLine(DS:GetColoredCharacterName(character), DS:GetColoredCharacterFaction(character))
AltoTooltip:AddLine(format("%s %s |r%s %s", L["Level"],
GREEN..(DS:GetCharacterLevel(character) or 0), DS:GetCharacterRace(character) or "", DS:GetCharacterClass(character) or ""),1,1,1)
Altoholic:AddCharacterTooltipHeader(character)
local zone, subZone = DS:GetLocation(character)
AltoTooltip:AddLine(format("%s: %s |r(%s|r)", L["Zone"], GOLD..(zone or "?"), GOLD..(subZone or "")),1,1,1)