-
Notifications
You must be signed in to change notification settings - Fork 5
/
Misc.lua
53 lines (48 loc) · 1.39 KB
/
Misc.lua
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
---@class RemixGemHelperPrivate
local Private = select(2, ...)
local const = Private.constants
local cache = Private.Cache
local misc = {
clickThrottles = {}
}
Private.Misc = misc
---@param percent number
---@return ColorMixin
function misc:GetPercentColor(percent)
if percent == 100 then
return const.COLORS.POSITIVE
end
if percent >= 50 then
return const.COLORS.NEUTRAL
end
return const.COLORS.NEGATIVE
end
function misc:PrintError(message, ...)
message = (... and string.format(message, ...) or message or "")
UIErrorsFrame:AddExternalErrorMessage(message)
end
---@param clickType any
---@return boolean
function misc:IsAllowedForClick(clickType)
local currentTime = GetTime()
if not self.clickThrottles[clickType] then
self.clickThrottles[clickType] = currentTime
return true
end
if self.clickThrottles[clickType] + .5 < currentTime then
self.clickThrottles[clickType] = currentTime
return true
end
if self.clickThrottles[clickType] + .25 < currentTime then
self:PrintError("You're clicking too fast")
end
return false
end
function misc.ItemSorting(a, b)
local cachedA = cache:GetItemInfo(a.itemID)
local cachedB = cache:GetItemInfo(b.itemID)
if cachedA.quality ~= cachedB.quality then
return cachedA.quality > cachedB.quality
end
return cachedA.name < cachedB.name
end