Module:Franchise/Cache

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

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

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

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

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

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