Module:Wares

local p = {}

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

local VAR_ITEMS = "Module:Wares/items"

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Wares"]) local categories = err and err.categoryText or "" if err and err.args and err.args.game then return "", categories end local items = utilsVar.get(VAR_ITEMS) local hasDescriptions = #(utilsTable.filter(items, "description")) > 0 local hasStock = #(utilsTable.filter(items, "stock")) > 0 local showQuantityColumn = args.showQuantityColumn local columns = {"Item"} if showQuantityColumn then table.insert(columns, "Quantity") end if args.prices and #args.prices > 0 then table.insert(columns, string.format("Prices [Colspan:%d]", #args.prices)) columns = utilsTable.concat(columns, args.prices) else table.insert(columns, "Price") end if hasStock then table.insert(columns, "Stock") end if hasDescriptions then table.insert(columns, "Description") end local tableArgs = DataTable.formatTable({}, {		game = args.game,		columns = columns,	}) local dataTable = DataTable.printTable(tableArgs) return dataTable end

function p.Item(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Wares/Item"]) args.categories = err and err.categoryText or "" utilsVar.add(VAR_ITEMS, args) end

p.Templates = { ["Wares"] = { description = "Lists items sold by merchants or in shops", format = "block", paramOrder = {"game", "prices", "showQuantityColumn", "..."}, params = { game = { required = true, desc = "A game code.", type = "string", enum = Franchise.enum, },			prices = { desc = "", type = "string", split = true, trim = true, nilIfEmpty = true, },			showQuantityColumn = { desc = "", type = "boolean", default = false, trim = true, nilIfEmpty = true, },			["..."] = {				name = "items", type = "content", },		},	},	["Wares/Item"] = { repeatedGroup = { name = "prices", params = {"price"}, allowSingle = true, },		paramOrder = {"item", "price", "display", "quantity", "stock", "description", "locations", "weather"}, params = { item = { desc = "", required = true, type = "wiki-page-name", trim = true, nilIfEmpty = true, },			price = { desc = "", required = true, type = "string", trim = true, nilIfEmpty = true, },			display = { desc = "", type = "content", trim = true, nilIfEmpty = true, },			quantity = { desc = "", type = "number", trim = true, nilIfEmpty = true, },			stock = { desc = "", type = "number", trim = true, nilIfEmpty = true, },			description = { desc = "", type = "content", trim = true, nilIfEmpty = true, },			locations = { desc = "", type = "string", split = true, trim = true, nilIfEmpty = true, },			weather = { desc = "", type = "string", split = true, trim = true, nilIfEmpty = true, },		}	}, }

return p