Module:Entry/metatable: Difference between revisions

From Rhythm Heaven Wiki
Jump to navigation Jump to search
(Implementation needed in Module:Entry)
 
m (Reverted edits by Tailx (talk) to last revision by HyperNervie)
Tag: Rollback
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local titles = require("Module:Level/titles")
local titles = require("Module:Entry/titles").lookup
local megamixLabels
local entryMT = {}
local entryMT = {}


Line 9: Line 8:
end
end


function entryMT.target(entry)
function entryMT._data(entry)
return titles[entry][1]
return titles[entry.console][entry.stage].entries[entry.number]
end
end


function entryMT.selfLink(entry)
function entryMT.target(entry)
return mw.title.getCurrentTitle().prefixedText == entry.target
return entry._data[1] or ""
end
end


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


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


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


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


local function _link(entry, tempoUpSize)
local function _link(entry, args)
local t = entry.text
if entry.target == "" then return "" end
t = mw.ustring.format("[[%s|%s]]", entry.title, t)
local title = entry.selfLink and entry.target or entry.title
local t = mw.ustring.format("[[%s|%s]]", title, entry.text)
if (entry.console == "GBA" or entry.console == "Arcade")
if (entry.console == "GBA" or entry.console == "Arcade")
and entry.stage == "EX"
and entry.stage == "EX"
then
then
tempoUpSize = tempoUpSize or "72px"
local tempoUpSize = args.tempoUpSize or "72px"
title = entry.selfLink and "" or entry.title
t = mw.ustring.format("%s [[File:TempoUpExtra%s.png|%s|link=%s]]",
t = mw.ustring.format("%s [[File:TempoUpExtra%s.png|%s|link=%s]]",
t, entry.number, tempoUpSize, entry.selfLink and entry.title or "")
t, entry.number, tempoUpSize, title)
end
end
return t
return t
Line 61: Line 68:
function entryMT.defaultIconSize(entry)
function entryMT.defaultIconSize(entry)
if entry.console == "GBA" or entry.console == "Arcade" then
if entry.console == "GBA" or entry.console == "Arcade" then
return (entry.stage == "E" or entry.stage == "T") and "40px" or "20px"
return (entry.stage == "E" or entry.stage == "T") and "40px" or "x20px"
elseif entry.console == "DS" then
elseif entry.console == "DS" then
return entry.stage == "B" and "34px"
return (entry.stage == "B" or entry.stage == "C") and "34px"
or (entry.stage == "E" or entry.stage == "T") and "40px"
or (entry.stage == "E" or entry.stage == "T"
or entry.stage == "GB" or entry.stage == "GT") and "40px"
or "32px"
or "32px"
elseif entry.console == "Wii" then
elseif entry.console == "Wii" then
Line 74: Line 82:
end
end


function entryMT.iconName(entry)
function entryMT.iconVariants(entry)
local variants = {}
for _, v in ipairs(entry._data.variants or {}) do
variants[v] = true
end
return variants
end
 
local function _iconName(entry, args)
local animateStages = {
local animateStages = {
GBA = {T = true},
GBA = {T = true},
Line 84: Line 100:
}
}
local ext = animateStages[entry.console][entry.stage] and "gif" or "png"
local ext = animateStages[entry.console][entry.stage] and "gif" or "png"
local entryCode
local console = entry.console
if entry.console == "Wii" and entry.stage == "E" then
if console == "Arcade" then console = "GBA" end
local endlessCodes = {"E-4", "E-1", "E-2", "E-3", "E-4 JP", "E-5"}
local entryCode = entry._data.icon or (entry.stage .. "-" .. entry.number)
entryCode = endlessCodes[tonumber(entry.number)]
local var = args.variant
elseif entry.console == "3DS" then
if entry.iconVariants[var] then var = " " .. var
megamixLabels = megamixLabels or require("Module:Entry/3ds_labels")
else var = "" end
entryCode = megamixLabels[entry.stage][entry.number]
return mw.ustring.format("Game %s %s%s.%s", console, entryCode, var, ext)
else
end
entryCode = entry.stage .. "-" .. entry.number
 
end
function entryMT.iconName()
return mw.ustring.format("Game %s %s.%s", entry.console, entryCode, ext)
return _iconName
end
end


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


Line 107: Line 126:
end
end


local function _iconAndLink(entry, iconSize, tempoUpSize)
local function _iconAndLink(entry, args)
    return tostring(mw.html.create("span")
local span = mw.html.create("span")
        :css("white-space", "nowrap")
:css("white-space", "nowrap")
        :wikitext(entry:icon(iconSize), " ", entry:link(tempoUpSize))
:wikitext(entry:icon(args))
    )
if entry.stage ~= "?" then span:wikitext(" ", entry:link(args)) end
return tostring(span)
end
end



Latest revision as of 04:10, 5 December 2025

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

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

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

function entryMT._data(entry)
	return titles[entry.console][entry.stage].entries[entry.number]
end

function entryMT.target(entry)
	return entry._data[1] or ""
end

function entryMT.title(entry)
	return entry._data[2] or entry.target
end

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

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

function entryMT.textWithTempoUp()
	return _textWithTempoUp
end

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

local function _link(entry, args)
	if entry.target == "" then return "" end
	local title = entry.selfLink and entry.target or entry.title
	local t = mw.ustring.format("[[%s|%s]]", title, entry.text)
	if (entry.console == "GBA" or entry.console == "Arcade")
		and entry.stage == "EX"
	then
		local tempoUpSize = args.tempoUpSize or "72px"
		title = entry.selfLink and "" or entry.title
		t = mw.ustring.format("%s [[File:TempoUpExtra%s.png|%s|link=%s]]",
			t, entry.number, tempoUpSize, 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 "x20px"
	elseif entry.console == "DS" then
		return (entry.stage == "B" or entry.stage == "C") and "34px"
			or (entry.stage == "E" or entry.stage == "T"
			or entry.stage == "GB" or entry.stage == "GT") 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.iconVariants(entry)
	local variants = {}
	for _, v in ipairs(entry._data.variants or {}) do
		variants[v] = true
	end
	return variants
end

local function _iconName(entry, args)
	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 = entry._data.icon or (entry.stage .. "-" .. entry.number)
	local var = args.variant
	if entry.iconVariants[var] then var = " " .. var
	else var = "" end
	return mw.ustring.format("Game %s %s%s.%s", console, entryCode, var, ext)
end

function entryMT.iconName()
	return _iconName
end

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

function entryMT.icon()
	return _icon
end

local function _iconAndLink(entry, args)
	local span = mw.html.create("span")
		:css("white-space", "nowrap")
		:wikitext(entry:icon(args))
	if entry.stage ~= "?" then span:wikitext(" ", entry:link(args)) end
	return tostring(span)
end

function entryMT.iconAndLink()
	return _iconAndLink
end

return entryMT