Module:CollectionLog: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:


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


     -- Add Killcount if present, above the grid
     -- Look for Killcount first (optional)
    if args.Killcount then
    local killcount
    for _, arg in ipairs(args) do
        if arg.name == "Killcount" then
            killcount = arg.value
            break
        end
    end
 
    if killcount then
         local killcountDiv = mw.html.create('div')
         local killcountDiv = mw.html.create('div')
             :addClass('collection-log-killcount')
             :addClass('collection-log-killcount')
             :wikitext('Killcount: ' .. args.Killcount)
             :wikitext('Killcount: ' .. killcount)
         html:node(killcountDiv)
         html:node(killcountDiv)
     end
     end


    -- Collection log grid
     local grid = mw.html.create('div'):addClass('collection-log-grid')
     local grid = mw.html.create('div'):addClass('collection-log-grid')


     for name, qty in pairs(args) do
     for _, arg in ipairs(args) do
        local name = arg.name
         if name ~= "Killcount" then
         if name ~= "Killcount" then
             qty = tonumber(qty) or 0
             local qty = tonumber(arg.value) or 0
             local item = mw.html.create('div')
             local item = mw.html.create('div')
                 :addClass('collection-log-item')
                 :addClass('collection-log-item')
                 :addClass(qty > 0 and 'obtained' or 'missing')
                 :addClass(qty > 0 and 'obtained' or 'missing')


            -- Call your custom template, for example plinkp3
             item:wikitext(string.format(
             item:wikitext(string.format(
                 '[[File:%s.png|32x32px|link=|alt=%s]]',
                 '{{plinkp3|name=%s|qty=%d|obtained=%s}}',
                 name, name, name
                 name, qty, qty > 0 and 'obtained' or 'missing'
             ))
             ))
            if qty > 1 then
                local badge = mw.html.create('div')
                    :addClass('collection-log-qty-badge')
                    :wikitext(tostring(qty))
                item:node(badge)
            end


             grid:node(item)
             grid:node(item)

Revision as of 06:47, 19 May 2025

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

local p = {}

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

    -- Look for Killcount first (optional)
    local killcount
    for _, arg in ipairs(args) do
        if arg.name == "Killcount" then
            killcount = arg.value
            break
        end
    end

    if killcount then
        local killcountDiv = mw.html.create('div')
            :addClass('collection-log-killcount')
            :wikitext('Killcount: ' .. killcount)
        html:node(killcountDiv)
    end

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

    for _, arg in ipairs(args) do
        local name = arg.name
        if name ~= "Killcount" then
            local qty = tonumber(arg.value) or 0
            local item = mw.html.create('div')
                :addClass('collection-log-item')
                :addClass(qty > 0 and 'obtained' or 'missing')

            -- Call your custom template, for example plinkp3
            item:wikitext(string.format(
                '{{plinkp3|name=%s|qty=%d|obtained=%s}}',
                name, qty, qty > 0 and 'obtained' or 'missing'
            ))

            grid:node(item)
        end
    end

    html:node(grid)

    return tostring(html)
end

return p