Skip to content

Commit f198010

Browse files
committed
refactor: move profession equipment rescan check into Data, keep Core.lua thin
1 parent 7a4be37 commit f198010

2 files changed

Lines changed: 15 additions & 18 deletions

File tree

Core.lua

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ local addon = select(2, ...)
66
local Data = addon.Data
77
local Main = addon.Main
88
local Checklist = addon.Checklist
9-
local Utils = addon.Utils
109
local LibDataBroker = LibStub("LibDataBroker-1.1")
1110
local LibDBIcon = LibStub("LibDBIcon-1.0")
1211

@@ -198,23 +197,7 @@ function Core:OnEnable()
198197
-- Re-scan if any profession gear slot returned nil on initial scan due to
199198
-- uncached item data. equipment~=nil means scanned; equipment[i]==nil means
200199
-- slot appeared empty because item data wasn't cached yet.
201-
local character = Data:GetCharacter()
202-
if not character then return end
203-
local needsRescan = false
204-
Utils:TableForEach(character.professions or {}, function(cp)
205-
-- Rescan if any slot has a pending sentinel (item data was missing on last scan)
206-
-- or if equipment is nil (tool item was uncached so slot group was skipped entirely)
207-
if cp.equipment == nil then
208-
needsRescan = true
209-
else
210-
for i = 1, 3 do
211-
if cp.equipment[i] and cp.equipment[i].pending then
212-
needsRescan = true
213-
end
214-
end
215-
end
216-
end)
217-
if needsRescan then
200+
if Data:NeedsProfessionEquipmentRescan() then
218201
Data:ScanProfessionEquipment()
219202
self:Render()
220203
end

Data.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,20 @@ function Data:ScanAll()
467467
self:ScanProfessionEquipment()
468468
end
469469

470+
--- Returns true if profession equipment should be rescanned.
471+
--- True when any profession has never been scanned (equipment==nil) or has pending slots.
472+
function Data:NeedsProfessionEquipmentRescan()
473+
local character = self:GetCharacter()
474+
if not character then return false end
475+
for _, cp in ipairs(character.professions or {}) do
476+
if cp.equipment == nil then return true end
477+
for i = 1, 3 do
478+
if cp.equipment[i] and cp.equipment[i].pending then return true end
479+
end
480+
end
481+
return false
482+
end
483+
470484
--- Scan profession gear slots for the current character and store results in AceDB.
471485
function Data:ScanProfessionEquipment()
472486
if self:IsInChatMessagingLockdown() then return end

0 commit comments

Comments
 (0)