Module:Entry/metatable: Difference between revisions

From Rhythm Heaven Wiki
Jump to navigation Jump to search
(Implementation needed in Module:Entry)
 
No edit summary
Line 1: Line 1:
local titles = require("Module:Level/titles")
local titles = require("Module:Entry/titles")
local megamixLabels
local megamixLabels
local entryMT = {}
local entryMT = {}

Revision as of 06:11, 7 August 2025

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

local titles = require("Module:Entry/titles")
local megamixLabels
local entryMT = {}

function entryMT.__index(entry, k)
	local v = entryMT[k](entry)
	rawset(entry, k, v)
	return v
end

function entryMT.target(entry)
	return titles[entry][1]
end

function entryMT.selfLink(entry)
	return mw.title.getCurrentTitle().prefixedText == entry.target
end

function entryMT.title(entry)
	if entry.selfLink then return entry.target end
	return titles[entry][2] or entry.target
end

function entryMT.text(entry)
	return titles[entry][3] or entry.title
end

local function textWithTempoUp(entry, tempoUpSize)
	local t = entry.text
	if (entry.console == "GBA" or entry.console == "Arcade")
		and entry.stage == "EX"
	then
		tempoUpSize = tempoUpSize or "72px"
		t = mw.ustring.format("%s [[File:TempoUpExtra%s.png|%s|link=]]",
			t, entry.number, tempoUpSize)
	end
	return t
end

function entryMT.textWithTempoUp()
	return textWithTempoUp
end

local function _link(entry, tempoUpSize)
	local t = entry.text
	t = mw.ustring.format("[[%s|%s]]", entry.title, t)
	if (entry.console == "GBA" or entry.console == "Arcade")
		and entry.stage == "EX"
	then
		tempoUpSize = tempoUpSize or "72px"
		t = mw.ustring.format("%s [[File:TempoUpExtra%s.png|%s|link=%s]]",
			t, entry.number, tempoUpSize, entry.selfLink and entry.title or "")
	end
	return t
end

function entryMT.link()
	return _link
end

function entryMT.defaultIconSize(entry)
	if entry.console == "GBA" or entry.console == "Arcade" then
		return (entry.stage == "E" or entry.stage == "T") and "40px" or "20px"
	elseif entry.console == "DS" then
		return entry.stage == "B" and "34px"
			or (entry.stage == "E" or entry.stage == "T") and "40px"
			or "32px"
	elseif entry.console == "Wii" then
		return (entry.stage == "E" or entry.stage == "T"
			or entry.stage == "EX" or entry.stage == "PE") and "40px" or "32px"
	elseif entry.console == "3DS" then
		return "44px"
	end
end

function entryMT.iconName(entry)
	local animateStages = {
		GBA = {T = true},
		Arcade = {},
		DS = {E = true, T = true},
		Wii = {E = true, T = true, EX = true, PE = true},
		["3DS"] = {},
		Switch = {}
	}
	local ext = animateStages[entry.console][entry.stage] and "gif" or "png"
	local entryCode
	if entry.console == "Wii" and entry.stage == "E" then
		local endlessCodes = {"E-4", "E-1", "E-2", "E-3", "E-4 JP", "E-5"}
		entryCode = endlessCodes[tonumber(entry.number)]
	elseif entry.console == "3DS" then
		megamixLabels = megamixLabels or require("Module:Entry/3ds_labels")
		entryCode = megamixLabels[entry.stage][entry.number]
	else
		entryCode = entry.stage .. "-" .. entry.number
	end
	return mw.ustring.format("Game %s %s.%s", entry.console, entryCode, ext)
end

local function _icon(entry, iconSize)
	iconSize = iconSize or entry.defaultIconSize
	return mw.ustring.format("[[File:%s|%s|link=%s]]",
		entry.iconName, iconSize, entry.selfLink and entry.title or "")
end

function entryMT.icon()
	return _icon
end

local function _iconAndLink(entry, iconSize, tempoUpSize)
    return tostring(mw.html.create("span")
        :css("white-space", "nowrap")
        :wikitext(entry:icon(iconSize), " ", entry:link(tempoUpSize))
    )
end

function entryMT.iconAndLink()
	return _iconAndLink
end

return entryMT