Module:Entry/metatable

< Module:Entry
Revision as of 10:19, 9 August 2025 by HyperNervie (talk | contribs) (Adjust to Module:Entry/titles changes)

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

local titles = require("Module:Entry/titles").lookup
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)
	local t = titles[entry]
	return t[3] or t[2] or t[1]
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 "" or entry.title)
	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 console = entry.console
	if console == "Arcade" then console = "GBA" end
	local entryCode = titles[entry].icon or (entry.stage .. "-" .. entry.number)
	return mw.ustring.format("Game %s %s.%s", 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 "" or entry.title)
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