Zelda Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!

Come join the Zelda Wiki community Discord server!

READ MORE

Zelda Wiki
Advertisement

local utilsCargo = require("Module:UtilsCargo")
local utilsString = require("Module:UtilsString")
local utilsTable = require("Module:UtilsTable")

local gameFields = "canonOrder, code, article, shortName, link, display, logo, releaseDate, canonicity, type, graphics, family, remakeOf, supersededBy"
local bookFields = "canonOrder, code, article, shortName, link, display, logo, releaseDate, canonicity, type, phraseLink, authors, basedOn"
local tvFields = "canonOrder, code, article, shortName, link, display, logo, releaseDate, canonicity, type"
local compilationFields = "code, article, shortName, link, display, logo, releaseDate, canonicity, type, titles"
local groupFields=  "code, article, shortName, link, display, logo, releaseDate, canonicity, games"

local games = utilsCargo.query("Games", gameFields, { sortBy = "canonOrder", limit = 200 })
local books = utilsCargo.query("Books", bookFields, { sortBy = "canonOrder" })
local tvShows = utilsCargo.query("TelevisionShows", tvFields, { sortBy = "canonOrder" })
local compilations = utilsCargo.query("Compilations", compilationFields, { sortBy = "releaseDate" })
local groups = utilsCargo.query("GameGroups", groupFields, { sortBy = "releaseDate" })
 -- Cargo isn't sorting properly for some reason
groups =  utilsTable.sortBy(groups, "releaseDate")
compilations = utilsTable.sortBy(compilations, "releaseDate")

local codes = {}
local gameCodes = {}
local titlesByCode = {}
local remakes = {}

for _, game in ipairs(games) do
	codes[tonumber(game.canonOrder)] = game.code
	gameCodes[tonumber(game.canonOrder)] = game.code
	titlesByCode[string.lower(game.code)] = game
	if utilsString.notEmpty(game.remakeOf) then
		remakes[string.lower(game.remakeOf)] = utilsTable.concat(remakes[string.lower(game.remakeOf)], game.code)
	end
end
gameCodes = utilsTable.compact(gameCodes)

for _, book in ipairs(books) do
	if utilsString.notEmpty(book.code) then -- workaround for Cargo bug inserting duplicate rows (but without code) 
		codes[tonumber(book.canonOrder)] = book.code
		titlesByCode[string.lower(book.code)] = book
	end
end

for _, tvShow in ipairs(tvShows) do
	codes[tonumber(tvShow.canonOrder)] = tvShow.code
	titlesByCode[string.lower(tvShow.code)] = tvShow
end

for _, compilation in ipairs(compilations) do
	titlesByCode[string.lower(compilation.code)] = compilation
end

for _, group in ipairs(groups) do
	titlesByCode[string.lower(group.code)] = group
end

codes.reference = "[[Data:Franchise]]"
gameCodes.reference = "[[Data:Franchise]]"

return {
	enum = codes,
	enumGames = gameCodes,
	games = games,
	titlesByCode = titlesByCode,
	remakes = remakes,
	compilations = compilations,
	groups = groups,
}
Advertisement