Module:Treasure Chests

local p = {} local Data = mw.loadData("Module:Treasure Chests/Data")

local DataTable = require("Module:Data Table") local Franchise = require("Module:Franchise") local utilsArg = require("Module:UtilsArg") local utilsTable = require("Module:UtilsTable")

function p.Main(frame) local args = utilsArg.parse(frame:getParent.args, p.Templates["Treasure Chests"]) local rows = DataTable.parseRows(args.cells or {}) local maxRowSize = p.getMaxRowSize(rows) local columns = p.getColumns(args.game, maxRowSize) local dataTable = DataTable.printTable(rows, {		game = args.game,		columns = columns,	}) return dataTable end

-- Determines how many cells there are per row to determine whether the "Coordinates" column should be omitted. function p.getMaxRowSize(rows) local rowSizes = utilsTable.map(rows, function(row)		return #(row.cells or {})	end) return utilsTable.max(rowSizes) or 0 end

function p.getColumns(game, maxRowSize) local graphicsType = Franchise.graphics(game) local gameConfig = Data.games[game] or {} local defaultConfig = Data.defaults[graphicsType] local config = utilsTable.merge({}, defaultConfig, gameConfig) local columns = {}

local treasureChestColumn = string.format("Treasure Chest [Term][Nowrap]", config.treasureChest.fileType, config.treasureChest.fileSize) table.insert(columns, treasureChestColumn) local contentsColumn = string.format("Contents [Term][Nowrap]", config.contents.fileType, config.contents.fileSize) table.insert(columns, contentsColumn) if maxRowSize > 3 then table.insert(columns, "Coordinates [Nowrap]") end table.insert(columns, "Notes [Description]") return columns end

p.Templates = { ["Treasure Chests"] = { params = { game = { required = true, desc = "A game code.", type = "string", enum = Franchise.enum, },			["..."] = {				name = "cells", type = "content", trim = true, },		}	}, }

return p