Module:CollectionLog

From Roat Pkz
Revision as of 06:30, 19 May 2025 by Hefner (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:CollectionLog/doc

local p = {}

function p.render(frame)
    local args = frame:getParent().args
    local html = mw.html.create('div'):addClass('collection-log-wrapper')

    -- Show Killcount if provided
    if args.Killcount then
        local kcDiv = mw.html.create('div')
            :addClass('collection-log-killcount')
            :wikitext(string.format('Killcount: <b>%s</b>', args.Killcount))
        html:node(kcDiv)
    end

    local grid = mw.html.create('div'):addClass('collection-log-grid')
    -- Define fixed order to keep consistent display order
    local order = {
        "Tanzanite_fang",
        "Serpentine_visage",
        "Magic_fang",
        "Uncut_onyx"
    }

    for _, name in ipairs(order) do
        local qty = tonumber(args[name]) or 0
        local obtainedClass = qty > 0 and 'obtained' or 'missing'

        local item = mw.html.create('div')
            :addClass('collection-log-item')
            :addClass(obtainedClass)

        -- Build image with optional quantity overlay
        local img = string.format(
            '[[%s|[[File:%s.png|32x32px|alt=%s|title=%s]]]]',
            name, name, name, name
        )

        item:wikitext(img)

        if qty > 1 then
            -- Add quantity badge
            local badge = mw.html.create('div')
                :addClass('collection-log-qty-badge')
                :wikitext(qty)
            item:node(badge)
        end

        grid:node(item)
    end

    html:node(grid)

    return tostring(html)
end

return p