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, },		},		tableParams = { {				name = "treasureChest", desc = "The type of Treasure Chest.", tags = {"Image", "Term", "Nowrap"}, },			{				name = "contents", desc = "The contents of the Treasure Chest.", tags = {"Image", "Term", "Nowrap"}, },			{				name = "coordinates", desc = "Precise location of the Treasure Chest. For games which do not support coordinates, you may use the in-game dungeon maps to indicate the location of Treasure Chests in dungeons.", optional = true, tags = {"Nowrap"}, },			{				name = "notes", desc = "Notes on how to locate the Treasure Chest in the area.", tags = {"Description"}, },		},	}, }

return p