Skip to content

Commit 4a1197f

Browse files
committed
Revert "chore: cleanup the inspect method"
This reverts commit fade24f.
1 parent cc78c62 commit 4a1197f

File tree

1 file changed

+24
-50
lines changed

1 file changed

+24
-50
lines changed

Modules/Item/Inspect.lua

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ local C_Item_GetItemQualityColor = C_Item.GetItemQualityColor
5555
local C_Item_IsCorruptedItem = C_Item.IsCorruptedItem
5656
local C_Spell_GetSpellTexture = C_Spell.GetSpellTexture
5757

58-
local guids = {}
58+
local guids, inspecting = {}, false
5959

6060
local slots = {
6161
{ index = 1, name = HEADSLOT },
@@ -862,37 +862,8 @@ local function ShowInspectItemListFrame(unit, parent, ilevel, maxLevel)
862862
end
863863

864864
function IL:Inspect()
865-
---@type nil|false|{
866-
--- class: string,
867-
--- expired: integer,
868-
--- guid: WOWGUID,
869-
--- hp: number,
870-
--- ilevel: integer,
871-
--- level: number,
872-
--- name: string,
873-
--- realm: string,
874-
--- spec: string|nil,
875-
--- timer: integer,
876-
--- unit: UnitToken,
877-
--- weaponLevel: number|nil,
878-
--- isArtifact: boolean|nil,
879-
--- maxLevel: number|nil,
880-
---}
881-
local inspecting -- inspecting can be false or table
882-
883-
local function clearCurrentInspection()
884-
if inspecting then
885-
if type(inspecting) == "table" then
886-
LibSchedule:RemoveTask(inspecting.guid)
887-
inspecting = nil
888-
else
889-
inspecting = false
890-
end
891-
end
892-
end
893-
894865
hooksecurefunc("ClearInspectPlayer", function()
895-
clearCurrentInspection()
866+
inspecting = false
896867
end)
897868

898869
-- @trigger UNIT_INSPECT_STARTED
@@ -928,39 +899,42 @@ function IL:Inspect()
928899
end)
929900

930901
-- @trigger UNIT_INSPECT_READY
931-
LibEvent:attachEvent("INSPECT_READY", function(_, guid)
902+
LibEvent:attachEvent("INSPECT_READY", function(this, guid)
932903
if not guids[guid] then
933904
return
934905
end
935-
936906
LibSchedule:AddTask({
937907
identity = guid,
938908
timer = 0.5,
939909
elasped = 0.8,
940910
expired = GetTime() + 4,
941-
data = inspecting,
942-
onTimeout = function(task)
943-
clearCurrentInspection()
911+
data = guids[guid],
912+
onTimeout = function(self)
913+
inspecting = false
944914
end,
945-
onExecute = function(task)
946-
local count, ilevel, _, weaponLevel, isArtifact, maxLevel =
947-
LibItemInfo:GetUnitItemLevel(inspecting.unit)
915+
onExecute = function(self)
916+
local count, ilevel, _, weaponLevel, isArtifact, maxLevel = LibItemInfo:GetUnitItemLevel(self.data.unit)
948917
if ilevel <= 0 then
949918
return true
950919
end
951920
if count == 0 and ilevel > 0 then
952-
inspecting.timer = time()
953-
inspecting.name = UnitName(inspecting.unit)
954-
inspecting.class = select(2, UnitClass(inspecting.unit))
955-
inspecting.ilevel = ilevel
956-
inspecting.maxLevel = maxLevel
957-
inspecting.spec = GetInspectSpec(inspecting.unit)
958-
inspecting.hp = UnitHealthMax(inspecting.unit)
959-
inspecting.weaponLevel = weaponLevel
960-
inspecting.isArtifact = isArtifact
961-
LibEvent:trigger("UNIT_INSPECT_READY", inspecting)
921+
--if (UnitIsVisible(self.data.unit) or self.data.ilevel == ilevel) then
922+
self.data.timer = time()
923+
self.data.name = UnitName(self.data.unit)
924+
self.data.class = select(2, UnitClass(self.data.unit))
925+
self.data.ilevel = ilevel
926+
self.data.maxLevel = maxLevel
927+
self.data.spec = GetInspectSpec(self.data.unit)
928+
self.data.hp = UnitHealthMax(self.data.unit)
929+
self.data.weaponLevel = weaponLevel
930+
self.data.isArtifact = isArtifact
931+
LibEvent:trigger("UNIT_INSPECT_READY", self.data)
962932
inspecting = false
963933
return true
934+
--else
935+
-- self.data.ilevel = ilevel
936+
-- self.data.maxLevel = maxLevel
937+
--end
964938
end
965939
end,
966940
})
@@ -985,7 +959,7 @@ function IL:Inspect()
985959
end)
986960

987961
--高亮橙裝和武器
988-
LibEvent:attachTrigger("INSPECT_ITEMFRAME_UPDATED", function(_, itemframe)
962+
LibEvent:attachTrigger("INSPECT_ITEMFRAME_UPDATED", function(self, itemframe)
989963
local r, g, b = 0, 0.9, 0.9
990964
if itemframe.quality and itemframe.quality > 4 then
991965
r, g, b = C_Item_GetItemQualityColor(itemframe.quality)

0 commit comments

Comments
 (0)