Module:Entry: Difference between revisions

From Rhythm Heaven Wiki
Jump to navigation Jump to search
(Prevent {{}} from being preprocessed in frame:extensionTag("tabber", ...), by the way why doesn't TabberNeue on this wiki provide mw.ext.tabber???)
(Ordered doclist hopefully)
Line 33: Line 33:


function p.doclist(frame)
function p.doclist(frame)
local arg = trim(frame.args[1])
local template = ({
local template = ({
textWithTempoUp = "entry",
textWithTempoUp = "entry",
Line 40: Line 41:
icon = "ei",
icon = "ei",
iconAndLink = "eil",
iconAndLink = "eil",
})[trim(frame.args[1])]
})[arg]


local wikitable
local wikitable
local function addRow(entry)
local function addRow(entry)
local result = entry[trim(frame.args[1])]
local result = entry[arg]
if type(result) == "function" then result = result(entry) end
if type(result) == "function" then result = result(entry) end
wikitable:tag("tr")
wikitable -- Should be a <tr> here
:tag("td"):tag("code")
:tag("td"):tag("code")
:wikitext(mw.ustring.format("&#123;&#123;%s|%s|%s|%s&#125;&#125;",
:wikitext(mw.ustring.format(
"&#123;&#123;%s|%s|%s|%s&#125;&#125;",
template, entry.console, entry.stage, entry.number))
template, entry.console, entry.stage, entry.number))
:done():done()
:done():done()
:tag("td"):wikitext(result):done()
:tag("td"):wikitext(result):done()
:done()
:done() -- End <tr> and go back to <table>
end
end
local tabs = ""
local tabs = ""
for console, rhtitle in pairs(require("Module:Entry/titles")) do
for _, rh in ipairs(require("Module:Entry/titles").sequence) do
tabs = tabs .. "|-|" .. console .. "="
tabs = tabs .. "|-|" .. rh.console .. "="
wikitable = mw.html.create("table")
wikitable = mw.html.create("table")
:addClass("wikitable")
:addClass("wikitable")
Line 64: Line 66:
:css("overflow-x", "auto")
:css("overflow-x", "auto")
:tag("tr")
:tag("tr")
:tag("th"):wikitext("Stage"):done()
:tag("th"):wikitext("Source"):done()
:tag("th"):wikitext("Source"):done()
:tag("th"):wikitext("Output"):done()
:tag("th"):wikitext("Output"):done()
:done()
:done()
for stage, titles in pairs(rhtitle) do
for _, stage in ipairs(rh) do
for number, _ in ipairs(titles) do
wikitable:tag("tr"):tag("td")
addRow(p.new(console, stage, number))
:attr("rowspan", tostring(#stage.entries))
:wikitext(stage.name)
:done() -- Should be a <tr> here
for number, _ in ipairs(stage.entries) do
if number ~= 1 then wikitable:tag("tr") end
addRow(p.new(rh.console, stage.label, number))
end
end
end
end

Revision as of 10:36, 9 August 2025

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

local entryMT = require("Module:Entry/metatable")
local p = {}

function p.new(console, stage, number)
	if type(console) == "table" and stage == nil and number == nil then
		stage = console[2] or console.stage
		number = console[3] or console.number
		console = console[1] or console.console
	end
	return setmetatable({
		console = console,
		stage = stage,
		number = number
	}, entryMT)
end

local function trim(s)
	if s == nil then return nil end
	s = mw.text.trim(s)
	return s == "" and nil or s
end
trim()

function p.main(frame)
	local args = frame:getParent().args
	local entry = p.new(trim(args[1]), trim(args[2]), trim(args[3]))
	local result = entry[trim(frame.args[1])]
	if type(result) == "function" then
		return result(entry, trim(args[4]), trim(args[5]))
	end
	return result
end

function p.doclist(frame)
	local arg = trim(frame.args[1])
	local template = ({
		textWithTempoUp = "entry",
		title = "et",
		link = "el",
		iconName = "ein",
		icon = "ei",
		iconAndLink = "eil",
	})[arg]

	local wikitable
	local function addRow(entry)
		local result = entry[arg]
		if type(result) == "function" then result = result(entry) end
		wikitable -- Should be a <tr> here
			:tag("td"):tag("code")
				:wikitext(mw.ustring.format(
					"&#123;&#123;%s|%s|%s|%s&#125;&#125;",
					template, entry.console, entry.stage, entry.number))
			:done():done()
			:tag("td"):wikitext(result):done()
		:done() -- End <tr> and go back to <table>
	end
	
	local tabs = ""
	for _, rh in ipairs(require("Module:Entry/titles").sequence) do
		tabs = tabs .. "|-|" .. rh.console .. "="
		wikitable = mw.html.create("table")
			:addClass("wikitable")
			:css("white-space", "nowrap")
			:css("max-width", "100%")
			:css("overflow-x", "auto")
			:tag("tr")
				:tag("th"):wikitext("Stage"):done()
				:tag("th"):wikitext("Source"):done()
				:tag("th"):wikitext("Output"):done()
			:done()
		for _, stage in ipairs(rh) do
			wikitable:tag("tr"):tag("td")
				:attr("rowspan", tostring(#stage.entries))
				:wikitext(stage.name)
			:done() -- Should be a <tr> here
			for number, _ in ipairs(stage.entries) do
				if number ~= 1 then wikitable:tag("tr") end
				addRow(p.new(rh.console, stage.label, number))
			end
		end
		tabs = tabs .. tostring(wikitable) .. "\n"
	end
	return frame:extensionTag("tabber", tabs)
end

return p