Module:Entry: Difference between revisions

From Rhythm Heaven Wiki
Jump to navigation Jump to search
(Ordered doclist hopefully)
(oops)
Line 70: Line 70:
:tag("th"):wikitext("Output"):done()
:tag("th"):wikitext("Output"):done()
:done()
:done()
for _, stage in ipairs(rh) do
for _, stage in ipairs(rh.stages) do
wikitable:tag("tr"):tag("td")
wikitable:tag("tr"):tag("td")
:attr("rowspan", tostring(#stage.entries))
:attr("rowspan", tostring(#stage.entries))

Revision as of 10:42, 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.stages) 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