-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapi.lua
More file actions
87 lines (74 loc) · 2.7 KB
/
Copy pathapi.lua
File metadata and controls
87 lines (74 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
local myname, ns = ...
local continuableContainer
_G.SimpleItemLevel.API = {}
local function itemFromArg(item)
-- take an Item or item link and returns a non-empty Item or nil
if not item then return end
if type(item) == "string" then
item = Item:CreateFromItemLink(item)
end
if item:IsItemEmpty() then
return
end
return item
end
-- Finds the item level for an item
--
-- This is almost the same as item:GetCurrentItemLevel, but it handles
-- giving caged battle pets a level as well.
--
-- `item` is an item link or an Item. Note: an Item created from
-- an itemID may be inaccurate due to item scaling.
-- Returns number or nil
SimpleItemLevel.API.ItemLevel = function(item)
item = itemFromArg(item)
local details = ns.DetailsFromItemInstant(item)
return details.level
end
-- Colorizes an item's level
--
-- `item` is an item link or an Item. Note: an Item created from
-- an itemID may be inaccurate due to item scaling.
-- Returns string, will be "|cffffffff?|r" if an invalid item is given
SimpleItemLevel.API.ItemLevelColorized = function(item)
item = itemFromArg(item)
local details = ns.DetailsFromItemInstant(item)
local color = ITEM_QUALITY_COLORS[details.quality or 1]
return color.hex .. (details.level or "?") .. "|r"
end
-- Tests whether an item is an upgrade compared to current equipment
--
-- `item` is an item link or an Item. Note: an Item created from
-- an itemID may be inaccurate due to item scaling.
-- Returns boolean
SimpleItemLevel.API.ItemIsUpgrade = function(item)
item = itemFromArg(item)
return ns.ItemIsUpgrade(item, true)
end
-- Tests whether an item is an upgrade compared to current equipment
--
-- Does all necessary data-caching for the items involved. This has more
-- overhead, but guarantees that you'll get an accurate result.
--
-- `item` is an item link or an Item. Note: an Item created from
-- an itemID may be inaccurate due to item scaling.
-- `callback` is a function which will be passed a boolean `isUpgrade`
SimpleItemLevel.API.ItemIsUpgradeAsync = function(item, callback)
if not continuableContainer then
continuableContainer = ContinuableContainer:Create()
end
item = itemFromArg(item)
if not item then
return callback(false)
end
continuableContainer:AddContinuable(item)
local _, _, _, equipLoc = C_Item.GetItemInfoInstant(item:GetItemID())
ns.ForEquippedItems(equipLoc, function(equippedItem, slot)
if not equippedItem:IsItemEmpty() then
continuableContainer:AddContinuable(equippedItem)
end
end)
continuableContainer:ContinueOnLoad(function()
callback(SimpleItemLevel.API.ItemIsUpgrade(item))
end)
end