Module:Franchise

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search

Allows modules to access the information stored in franchise code templates.

These functions return nil if passed an invalid code. This is not shown in the examples because it would add invalid codes to Special:WantedTemplates.

Codes are case-sensitive.

This module exports the following functions.

All media

article

article(code)

Returns

  • Wiki article name for the title

Examples

#InputResultStatus
1
article("LA")
The Legend of Zelda: Link's Awakening

canonicity

canonicity(code)

Returns

  • A string: canon, ambiguous, or non-canon.

Examples

#InputResultStatus
2
canonicity("LA")
canon
3
canonicity("CoH")
ambiguous
4
canonicity("LA (Cagiva)")
non-canon

display

display(code)

Returns

  • Formatted text for the title.

Examples

#InputResultStatus
5
display("LA")
Link's Awakening
6
display("LANS")
Link's Awakening (Nintendo Switch)
7
display("Series")
The Legend of Zelda Series

isCanon

isCanon(code)

Returns

  • True if title is canon, else false.

Examples

#InputOutputStatus
8
isCanon("LANS")
true
9
isCanon("CoH")
false
10
isCanon("E")
true
11
isCanon("Series")
true

link

link(code)

Returns

  • Formatted link used in infoboxes and so on.

Examples

#InputResultStatus
12
link("LA")
Link's Awakening
13
link("LANS")
Link's Awakening (Nintendo Switch)
14
link("LA (Cagiva)")
Link's Awakening (Cagiva)
15
link("Series")
The Legend of Zelda series

logo(code)

Returns

  • Filename for the title's logo.

Examples

#InputResultStatus
16
logo("TWW")
File:TWW English Logo.png
17
logo("E")
File:The Legend of Zelda Encyclopedia Cover.png
18
logo("Series")
File:Zelda Logo TP.png

releaseDate

releaseDate(code)

Returns

  • The "main" release date for a title.

Examples

#InputResultStatus
19
releaseDate("LA")
1993-08-06

shortName

shortName(code)

Returns

  • Short name for franchise title used in category names. Usually the subtitle.

Examples

#InputResultStatus
20
shortName("LA")
Link's Awakening
21
shortName("LANS")
Link's Awakening (Nintendo Switch)
22
shortName("LA (Cagiva)")
Link's Awakening (Cagiva)
23
shortName("Series")
The Legend of Zelda Series

sort

sort(codes)

Returns

Examples

#InputOutputStatus
24
sort({
  "LANS",
  "LA",
  "FS",
  "LADX",
  "FSAE",
  "Series",
  "LA (Cagiva)",
})
{
  "Series",
  "LA",
  "LADX",
  "LANS",
  "FS",
  "FSAE",
  "LA (Cagiva)",
}
{}


Games

baseGame

baseGame(code)

Returns

  • If code is a remake, returns the code for the original game, else returns code as-is.

Examples

#InputResultStatus
25
baseGame("TWWHD")
TWW
26
baseGame("LANS")
LA
27
baseGame("LA")
LA

graphics

graphics(code)

Returns

  • A string: 2D or 3D.

Examples

#InputResultStatus
28
graphics("LA")
2D
29
graphics("LANS")
3D

isRemake

isRemake(code)

Returns

  • True if game is a remake, remaster, or enhanced port. Else false.

Examples

#InputOutputResult
30
isRemake("LA")
false
31
isRemake("LANS")
true
32
isRemake("LADX")
true

superseder

superseder(code)

Returns

  • The game code of the latest canon version of the game corresponding to code, or an empty string if code is the latest canon version.

Examples

#InputOutputStatus
33
superseder("LA")
"LANS"
34
superseder("BotW")
""
FSAE is not returned for FS as it not considered a canon remake.
35
superseder("FS")
""


Books

publisher

publisher(code)

Returns

  • The book's publisher - in North America if available.

Examples

#InputResultStatus
36
publisher("OoT (Himekawa)")
VIZ Media
37
publisher("E")
Dark Horse Books

local p = {}
local h = {}

local cache = {}
function p.prop(code, propName)
	local cacheKey = code.." "..propName
	local cacheEntry = cache[cacheKey]
	if cacheEntry then
		return cacheEntry
	end

	local success, res = pcall(function()
		return mw.getCurrentFrame():expandTemplate({
			title = code,
			args = {propName}
		})
	end)
	if success and res and not string.find(res, "zw%-error") then
		cache[cacheKey] = res
		return res
	end
end

-- All media

function p.article(code)
	return p.prop(code, "Article")
end

function p.canonicity(code)
	return p.prop(code, "Canonicity")
end

function p.display(code)
	return p.prop(code, "Display")
end

function p.isCanon(code)
	local canonicity = p.canonicity(code)
	return canonicity and canonicity == "canon"
end

function p.link(code)
	return p.prop(code, "Link")
end

function p.logo(code)
	return p.prop(code, "Logo")
end

function p.releaseDate(code)
	return p.prop(code, "ReleaseDate")
end

function p.shortName(code)
	return p.prop(code, "ShortName")
end

function p.sort(codes)
	local invalid = {}
	local sorted = {}
	local data = {}
	
	for i, code in ipairs(codes) do
		local isCanon = p.isCanon(code)
		local releaseDate = p.releaseDate(code)
		local baseGame = p.baseGame(code)
		
		if (isCanon or releaseDate) == nil then
			table.insert(invalid, code)
		else
			table.insert(sorted, code)
			data[code] = {
				isCanon = isCanon,
				releaseDate = releaseDate,
				baseGame = baseGame,
			}
		end
	end
	
	table.sort(sorted, function(a, b)
		return h.sortKey(data, a) < h.sortKey(data, b)
	end)
	
	return sorted, invalid
end
function h.sortKey(data, code)
	local baseGame = data[code].baseGame
	local isCanon = data[code].isCanon
	local releaseDate = data[code].releaseDate
	
	if baseGame == code then
		baseGame = nil
	end
	
	local key = ""
	key = key..(code == "Series" and "0" or "1")
	
	local isCanon = isCanon or (baseGame and p.isCanon(baseGame))
	key = key..(isCanon and "0" or "1")

	if baseGame then
		key = key..p.releaseDate(baseGame)
	end

	if releaseDate == "" then
		releaseDate = "999999" -- put unreleased games last
	end
	key = key..releaseDate
	
	return key
end

-- Games

function p.baseGame(code)
	local remakeOf = p.prop(code, "RemakeOf")
	if remakeOf == nil then -- code invavlid
		return nil
	elseif remakeOf == "" then -- game is not a remake
		return code
	else
		local first = string.match(remakeOf, "^([^,]*),")
		return first or remakeOf
	end
end

function p.graphics(code)
	return p.prop(code, "Graphics")
end

function p.isRemake(code)
	local remakes = p.prop(code, "RemakeOf")
	if remakes == nil then
		return nil
	end
	return remakes ~= ""
end

function p.superseder(code)
	return p.prop(code, "SupersededBy")
end

-- Books
function p.publisher(code)
	return p.prop(code, "Publisher")
end

return p