WoW-MogIt / MogIt

World of Warcraft transmogrification assistant
https://www.curseforge.com/wow/addons/mogit
11 stars 15 forks source link

Doubt with function #24

Closed Raynou closed 1 year ago

Raynou commented 1 year ago

Hi, I want to make a refactor of a function in Core.lua, but I don't understand very well what exactly the function does:

function mog:ToNumberItem(item)
    if type(item) == "string" then
        local id, diff, bonus = item:match(mog.itemStringPattern);
        -- bonus ID can also be warforged, socketed, etc
        -- if there is more than one bonus ID, need to check all
        if bonus then
            if not tonumber(bonus) then
                for bonusID in gmatch(bonus, "%d+") do
                    if bonusDiffs[tonumber(bonusID)] then
                        bonus = bonusID;
                        break;
                    end
                end
            elseif not bonusDiffs[tonumber(bonus)] then
                bonus = nil;
            end
        end
        id = id or item:match("item:(%d+)");
        return tonumber(id), tonumber(bonus), tonumber(diff);
    elseif type(item) == "number" then
        return item;
    end
end
Lombra commented 1 year ago

The function takes an item in the shape of a simple item ID, such as 113979, or an item string, such as item:113979::::::::70::512::1:9075:70. If the input is an item ID, it is returned as is. If it is an item string, the function will attempt to parse and return from it an item ID, a bonus ID and a difficulty ID.

Raynou commented 1 year ago

Thank you!