Reviewed UI sources from 5df4a4f028581d347411727d0309e5f434b75668. The addon regression tests passed in this checkout.
88 lines
3.6 KiB
Lua
88 lines
3.6 KiB
Lua
OctoTransmog = OctoTransmog or {}
|
|
local T = OctoTransmog
|
|
|
|
T.prefix = "TW_TRANSMOG"
|
|
T.coinID = 51217
|
|
T.slots = {
|
|
{client=1, server=0, name="Head"},
|
|
{client=3, server=2, name="Shoulders"},
|
|
{client=4, server=3, name="Shirt"},
|
|
{client=5, server=4, name="Chest"},
|
|
{client=6, server=5, name="Waist"},
|
|
{client=7, server=6, name="Legs"},
|
|
{client=8, server=7, name="Feet"},
|
|
{client=9, server=8, name="Wrists"},
|
|
{client=10, server=9, name="Hands"},
|
|
{client=15, server=14, name="Back"},
|
|
{client=16, server=15, name="Main hand"},
|
|
{client=17, server=16, name="Off hand"},
|
|
{client=18, server=17, name="Ranged"},
|
|
{client=19, server=18, name="Tabard"},
|
|
}
|
|
|
|
T.slotByClient = {}
|
|
for _, slot in ipairs(T.slots) do T.slotByClient[slot.client] = slot end
|
|
|
|
-- Source Turtle_TransmogUI InvTypes. The current TransmogMgr parses this
|
|
-- field but does not use it when computing the available appearance list.
|
|
T.inventoryType = {
|
|
INVTYPE_HEAD=1, INVTYPE_SHOULDER=3, INVTYPE_BODY=4,
|
|
INVTYPE_CHEST=5, INVTYPE_ROBE=20, INVTYPE_WAIST=6,
|
|
INVTYPE_LEGS=7, INVTYPE_FEET=8, INVTYPE_WRIST=9,
|
|
INVTYPE_HAND=10, INVTYPE_CLOAK=16, INVTYPE_TABARD=19,
|
|
INVTYPE_WEAPON=13, INVTYPE_WEAPONMAINHAND=21,
|
|
INVTYPE_WEAPONOFFHAND=22, INVTYPE_2HWEAPON=17,
|
|
INVTYPE_SHIELD=14, INVTYPE_HOLDABLE=23,
|
|
INVTYPE_RANGED=15, INVTYPE_RANGEDRIGHT=26, INVTYPE_THROWN=25,
|
|
}
|
|
|
|
function T.ItemID(link)
|
|
if type(link) ~= "string" then return nil end
|
|
return tonumber(string.match(link, "item:(%d+)"))
|
|
end
|
|
|
|
function T.Parse(message)
|
|
if type(message) ~= "string" or #message > 4096 or string.find(message, "\0", 1, true) then return nil end
|
|
local status = string.match(message, "^TransmogStatus:(.*)$")
|
|
if status then
|
|
local rows = {}
|
|
if status == "" then return nil end
|
|
for row in string.gmatch(status, "[^,]+") do
|
|
local slot, id = string.match(row, "^(%d+):(%d+)$")
|
|
slot, id = tonumber(slot), tonumber(id)
|
|
if not slot or not id or (slot ~= 0 and not T.slotByClient[slot]) then return nil end
|
|
if slot ~= 0 then rows[slot] = id end
|
|
end
|
|
if string.sub(status, -1) == "," then return nil end
|
|
return {kind="status", rows=rows}
|
|
end
|
|
local slot, total, tail = string.match(message, "^AvailableTransmogs:(%d+):(%d+):(.+)$")
|
|
if slot then
|
|
slot, total = tonumber(slot), tonumber(total)
|
|
if not T.slotByClient[slot] or not total then return nil end
|
|
if tail == "start" or tail == "end" then
|
|
return {kind=tail, slot=slot, total=total}
|
|
end
|
|
local ids = {}
|
|
if string.find(tail, "[^%d:]") or string.find(tail, "::", 1, true) or
|
|
string.sub(tail, 1, 1) == ":" or string.sub(tail, -1) == ":" then return nil end
|
|
for number in string.gmatch(tail, "[^:]+") do
|
|
local id = tonumber(number)
|
|
if not id or id > 2147483647 then return nil end
|
|
if id ~= 0 then ids[#ids+1] = id end
|
|
end
|
|
return {kind="items", slot=slot, total=total, ids=ids}
|
|
end
|
|
local action, sourceSlot, clientSlot, code = string.match(message, "^(%a+)Result:(%d+):(%d+):(%d+)$")
|
|
if action == "Transmog" or action == "Reset" then
|
|
sourceSlot, clientSlot, code = tonumber(sourceSlot), tonumber(clientSlot), tonumber(code)
|
|
local known = T.slotByClient[clientSlot]
|
|
if not known or known.server ~= sourceSlot then return nil end
|
|
return {kind="result", action=action, slot=clientSlot, code=code}
|
|
end
|
|
if string.match(message, "^SendAvailableTransmogs:Error:") then
|
|
return {kind="error", text="The server could not list appearances for this item."}
|
|
end
|
|
return nil
|
|
end
|