Module:Exp Game: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
No edit summary
No edit summary
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
-- This module serves as the code for Template:Exp Game2
local p = {}
local p = {}
local utilsGame = require( "Module:UtilsGame" )
 
local utilsTable = require( "Module:UtilsTable" )
local Franchise = require("Module:Franchise")
local utilsArg = require("Module:UtilsArg")
 
local CLASS_EXP_GAME = "exp-game" -- [[Module:Infobox]] searches for this value and has to be changed if this value changes
local CLASS_NOEXCERPT = require("Module:Constants/class/noexcerpt")


-- Main function called by Template:Exp Game
-- Main function called by Template:Exp Game
function p.Main( frame )
function p.Main(frame)
local games = frame:getParent().args
local args, err = utilsArg.parse(frame:getParent().args, p.Templates["Exp Game"])
return p.Display(games)
local categories = err and err.categoryText or ""
end
 
local games = args.games
function p.Display(games)
if not games or #games == 0 then
local result = "<sup>("
return "", categories
-- Remove duplicates to make sure no game appears twice.
end
local games = utilsTable.removeDuplicates(games)
games = utilsGame.OrderGames(games, "canon")
-- For every arguments received add a note.
local gameExp = {}
for key, value in pairs(games) do
for i, game in ipairs(games) do
local fullGame = utilsGame.AbbToGame(value, true)
local shortName = Franchise.shortName(game)
if shortName then
-- If the game exists add a note.
local exp = frame:expandTemplate({
if fullGame ~= "Unknown" then
title = "Exp",
args = {shortName, game}
-- If the game is the first one, do not add a "|".
})
if key ~= 1 then
table.insert(gameExp, "<b>"..exp.."</b>")
result = result .. " | "
end
result = result .. "<span class='explain' title='" .. fullGame
result = result .. "' style='color:yellow'><b>"
result = result .. value .. "</b></span>"
end
end
end
end
gameExp = table.concat(gameExp, " &#124; ") -- &#124 is the HTML entity for the pipe character. Needs to be entered like this in order to not break tables and such
result = result .. ")</sup>"
gameExp = string.format('<sup class="%s %s">(%s)</sup>', CLASS_EXP_GAME, CLASS_NOEXCERPT, gameExp) -- Exp Game looks odd in page preview popups, "noexcerpt" removes it from the previews
return result
return gameExp, categories
end
end
p.Templates = {
["Exp Game"] = {
purpose = "Indicates for which game(s) a particular statement is true, when that statement is not true for all games.",
format = "inline",
params = {
[1] = {
name = "games",
placeholder = "game1, game2, ..., gameN",
type = "string",
required = true,
enum = Franchise.enum({ includeSeries = true }),
desc = "A comma-separated list of one or more [[Data:Franchise|game codes]].",
split = true,
sortAndRemoveDuplicates = true,
}
},
examples = {
{"OoT"},
{"Series, OoT, MM"},
{"MM, OoT, MM, OoT"},
{},
{""},
{"fakeGame"},
{"OoT, fakeGame, MM"}
}
}
}


return p
return p

Latest revision as of 13:36, 25 November 2022

This is the main module for the following templates:
local p = {}

local Franchise = require("Module:Franchise")
local utilsArg = require("Module:UtilsArg")

local CLASS_EXP_GAME = "exp-game" -- [[Module:Infobox]] searches for this value and has to be changed if this value changes
local CLASS_NOEXCERPT = require("Module:Constants/class/noexcerpt")

-- Main function called by Template:Exp Game
function p.Main(frame)
	local args, err = utilsArg.parse(frame:getParent().args, p.Templates["Exp Game"])
	local categories = err and err.categoryText or ""
	
	local games = args.games
	if not games or #games == 0 then
		return "", categories
	end
	
	local gameExp = {}
	for i, game in ipairs(games) do
		local shortName = Franchise.shortName(game)
		if shortName then
			local exp = frame:expandTemplate({
				title = "Exp",
				args = {shortName, game}
			})
			table.insert(gameExp, "<b>"..exp.."</b>")
		end
	end
	gameExp = table.concat(gameExp, " &#124; ") -- &#124 is the HTML entity for the pipe character. Needs to be entered like this in order to not break tables and such
	gameExp = string.format('<sup class="%s %s">(%s)</sup>', CLASS_EXP_GAME, CLASS_NOEXCERPT, gameExp) -- Exp Game looks odd in page preview popups, "noexcerpt" removes it from the previews
	
	return gameExp, categories
end

p.Templates = {
	["Exp Game"] = {
		purpose = "Indicates for which game(s) a particular statement is true, when that statement is not true for all games.",
		format = "inline",
		params = {
			[1] = {
				name = "games",
				placeholder = "game1, game2, ..., gameN",
				type = "string",
				required = true,
				enum = Franchise.enum({ includeSeries = true }),
				desc = "A comma-separated list of one or more [[Data:Franchise|game codes]].",
				split = true,
				sortAndRemoveDuplicates = true,
			}
		},
		examples = {
			{"OoT"},
			{"Series, OoT, MM"},
			{"MM, OoT, MM, OoT"},
			{},
			{""},
			{"fakeGame"},
			{"OoT, fakeGame, MM"}
		}
	}
}

return p