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 games = utilsCargo.query("Games2", table.concat(gameFields, ",")) local books = utilsCargo.query("Books", table.concat(bookFields, ","))

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

for _, game in ipairs(games) do	codes[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 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 codes.reference = "Data:Franchise"

return { enum = codes, titlesByCode = titlesByCode, remakes = remakes, }