Module:BPMTable: Difference between revisions

From Rhythm Heaven Wiki
Jump to navigation Jump to search
(Modified the table to return html instead)
(Bugfixing)
Line 21: Line 21:
                         '<tr>'..
                         '<tr>'..
                         '<th align="center" style="color:white;background:#4A31FF;border-radius:7px;" width="50%">'..
                         '<th align="center" style="color:white;background:#4A31FF;border-radius:7px;" width="50%">'..
                         'div style="margin-left:75px;">'..
                         '<div style="margin-left:75px;">'..
                         '<font color="White">BPMs</font>'..
                         '<font color="White">BPMs</font>'..
                         '</div>'..
                         '</div>'..
Line 40: Line 40:
         i = i + 1
         i = i + 1
     end
     end
     table.insert(result, '</tr></tbody></table>')
     table.insert(result, '</tbody></table>')
     return table.concat(result, "")
     return table.concat(result, "")
end
end


return p
return p

Revision as of 12:05, 9 July 2025

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:

<tbody></tbody>
BPMs
<spanclass="mw-collapsible-toggle mw-collapsible-toggle-default mw-collapsible-toggle-collapsed"role="button" tabindex="0" aria-expanded="false"><aclass="mw-collapsible-text">Expand</a>Beat
1200
12516
{{#invoke:BPMTable|main|title=Game|180,175|Tengoku,Megamix}}

would resolve into:

<tbody></tbody>
BPMs
<spanclass="mw-collapsible-toggle mw-collapsible-toggle-default mw-collapsible-toggle-collapsed"role="button" tabindex="0" aria-expanded="false"><aclass="mw-collapsible-text">Expand</a>Game
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;">'..
                        '<tbody>'..
                        '<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"><a'..
                        'class="mw-collapsible-text">Expand</a></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, '</tbody></table>')
    return table.concat(result, "")
end

return p