Files
wow-weakauras/FreshShit/AutoLoot/AutoLootDisplay/Init.lua
2024-08-24 22:43:07 +02:00

48 lines
1.4 KiB
Lua

local iconDisplayDuration = 3
---@alias CItemInfo {name: string, icon: number, quantity: number, color: string}
---@param msg string
---@return CItemInfo, string | nil
GetItemInfo = function(msg)
local itemInfo = {name = "", icon = 134400, quantity = 0, color = ""}
local name = msg:match("h%[(.+)%]")
if not name then return itemInfo, "No item name found" end
local quantity = msg:match("x(%d+)") or 1
itemInfo.name = name
itemInfo.quantity = quantity
if WeakAurasSaved.Cyka.ItemCache[name] then
itemInfo.icon = WeakAurasSaved.Cyka.ItemCache[name].icon
end
local color = msg:match("cff(%w%w%w%w%w%w)") or "ffffff"
itemInfo.color = color
return itemInfo, nil
end
---@param msg string
---@param allstates allstates
DrawIcon = function(msg, allstates)
local info, err = GetItemInfo(msg)
if err then
print(err)
return
end
local formattedName = "\124cff" .. info.color .. "[" .. info.name .. "]\124r x" .. info.quantity
allstates[#aura_env.allstates + 1] = {
show = true,
changed = true,
index = GetTime(),
resort = true,
icon = info.icon,
name = formattedName,
progressType = "timed",
expirationTime = GetTime() + iconDisplayDuration,
duration = iconDisplayDuration,
autoHide = true,
}
end