Module:Franchise/Cache

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

local commonFields = {"canonOrder", "code", "shortName", "link", "display", "releaseDate", "canonicity", "type"} local gameFields = utilsTable.concat(commonFields, {"graphics", "family", "remakeOf", "supersededBy"}) local bookFields = utilsTable.concat(commonFields, {"phraseLink", "authors", "basedOn"}) local tvFields = commonFields

local games = utilsCargo.query("Games3", table.concat(gameFields, ","), { sortBy = "canonOrder"}) local books = utilsCargo.query("Books", table.concat(bookFields, ","), { sortBy = "canonOrder"}) local tvShows = utilsCargo.query("TelevisionShows", table.concat(tvFields, ","), { sortBy = "canonOrder"})

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

for _, game in ipairs(games) do	codes[tonumber(game.canonOrder)] = game.code table.insert(gameCodes, 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 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 codes.reference = "Data:Franchise" gameCodes.reference = "Data:Franchise"

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