Module:BPMTable

Revision as of 12:21, 9 July 2025 by TheAlternateDoctor (talk | contribs) (Bugfixing #3)

Module accepts 3 arguments:

  • title: Name of the second column. Most likely to be "Beat", or "Game".
  • Unnamed argument 1: List of tempos, separated by a comma. Ex: "120,125"
  • Unnamed argument 2: List of labels. Displayed to the right of the corresponding tempo. Ex: "Tengoku,Megamix" or "0,16"

For instance:

{{#invoke:BPMTable|main|title=Beat|120,125|0,16}}

would resolve into:

BPMs
ExpandBeat
1200
12516
{{#invoke:BPMTable|main|title=Game|180,175|Tengoku,Megamix}}

would resolve into:

BPMs
ExpandGame
180Tengoku
175Megamix

local p = {}

function p.main(frame)
    local title = frame.args["title"]
    local items = frame.args[1]
    if items ~= nil then
        items = mw.text.split(items, ",")
    else
        items = {}
    end
    local labels = frame.args[2]
    if labels ~= nil then
        labels = mw.text.split(labels, ",")
    else
        labels = {}
    end
    local result = {}
    table.insert(result, '<table class="mw-collapsible mw-collapsed mw-made-collapsible" style="color:white;width:25%;clear:both;background:black;border-radius: 10px;">'..
                        '<tr>'..
                        '<th align="center" style="color:white;background:#4A31FF;border-radius:7px;" width="50%">'..
                        '<div style="margin-left:75px;">'..
                        '<font color="White">BPMs</font>'..
                        '</div>'..
                        '</th>'..
                        '<th align="center" style="color:white;background:#4A31FF;border-radius:7px;">'..
                        '<span class="mw-collapsible-toggle mw-collapsible-toggle-default mw-collapsible-toggle-collapsed" role="button" tabindex="0" aria-expanded="false">'..
                        '<span class="mw-collapsible-text">Expand</span></span>'..title..
                        '</th>'..
                        '</tr>')
    local i = 1
    while items[i] do
        table.insert(result, '<tr style="display: none;"><td>'..items[i]..'</td>')
        if labels[i] ~= nil then
            table.insert(result, '<td>'..labels[i]..'</td>')
        end
        table.insert(result, '</tr>')
        i = i + 1
    end
    table.insert(result, '</table>')
    return table.concat(result, "")
end

return p