Module:SMM costumes

From the Super Mario Wiki, the Mario encyclopedia
Jump to navigationJump to search

This module outputs the {{SMM costumes}} table with data from here.


local COSTUMES = mw.loadJsonData('Module:SMM costumes/data.json')
local tables = require('Module:Table')

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local current_title = string.lower(mw.title.getCurrentTitle().text)
    local wikitext = '{|class="wikitable '
    if args[2] then
        wikitext = wikitext .. "sortable "
    end
    if args.noorigin then
        wikitext = wikitext .. 'col5left'
    else
        wikitext = wikitext .. 'col6left'
    end
    wikitext = wikitext .. '" style="text-align:center;--bg2:#6B8CFF;--darkbg2:#000E47"\n'
    wikitext = wikitext .. '!data-sort-type="number"|#\n'
    wikitext = wikitext .. '!class="unsortable"|Image\n'
    wikitext = wikitext .. '!data-sort-type="alphabetical"width="6%"|Costume\n'

    if not args.noorigin then
        wikitext = wikitext .. '!width="10%"|Origin\n'
    end

    wikitext = wikitext .. '!width="23%"|Unlock method\n'
    wikitext = wikitext .. '!class="unsortable"|Notes\n'

    local link_tracker = tables.LinkTracker.new(current_title)

    for k, v in ipairs(args) do
        v = tables.trim(v)
        if v ~= "" then
            local costume = COSTUMES[v]

            if costume == nil then
                error("Costume parameter " .. k .. " is invalid: " .. v)
            else
                wikitext = wikitext .. frame:preprocess("|-{{anchor|" .. costume.number .. "}}\n")
                wikitext = wikitext .. "|" .. frame:preprocess(costume.number or "") .. "\n"
                wikitext = wikitext .. "|" .. frame:preprocess(costume.image or tables.noimage("SMM Costume " .. v)) .. "\n"
                wikitext = wikitext .. "|" .. frame:preprocess(costume.name or "") .. "\n"

                if not args.noorigin then
                    wikitext = wikitext .. "|" .. frame:preprocess(link_tracker:parse(costume.origin)) .. "\n"
                end

                wikitext = wikitext .. "|" .. frame:preprocess(link_tracker:parse(costume.unlock)) .. "\n"
                wikitext = wikitext .. "|" .. frame:preprocess(link_tracker:parse(costume.notes)) .. "\n"
            end
        end
    end

    wikitext = wikitext .. "|}"

    return wikitext
end

return p