Module:Variable

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

local Color = require("Module:Color") local utilsArg = require("Module:UtilsArg") local utilsMarkup = require("Module:UtilsMarkup") local utilsTable = require("Module:UtilsTable")

local enum = utilsTable.keys(Data.variables) enum.reference = "Template:Variable"

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates.Variable) local categories = err and err.categoryText or "" if err and err.args.var then return "", categories end

local varConfig = Data.variables[args.var] or {} local tooltip = varConfig.tooltip or "" local default = varConfig.default local placeholder = varConfig.placeholder or args.var local color = varConfig.color

local display = varConfig.default or "["..placeholder.."]" local content = utilsMarkup.tooltip(display, tooltip) if color then content = Color.color(color, content) end

return content, categories end

function p.ListVariables(frame) local DataTable = require("Module:Data Table") local Franchise = require("Module:Franchise") local utilsString = require("Module:UtilsString")

local columns = {"Game [Rowspan]", "Variable [Description]", "Output [Description]", "Description [Description]"} local rows = {} for varName, varConfig in pairs(Data.variables) do		local varParts = utilsString.split(varName, " ") local gameCode = varParts[1] local gameVarName = table.concat(utilsTable.tail(varParts), " ") local game = Franchise.link(gameCode) local input = "" local output = frame:preprocess(input) input = " "

local row = {game, input, output, varConfig.doc or " "} row.game = Franchise.canonOrder(gameCode) row.name = gameVarName table.insert(rows, row) end rows = utilsTable.sortBy(rows, {"game", "name"}) local dataTable = DataTable.printTable(rows, {		columns = columns	}) return dataTable end

p.Data = p.ListVariables -- Reuse function for Module:Variable/Data/Documentation

function p.Schemas return { Data = { type = "record", required = true, properties = { {					name = "variables", required = true, type = "map", keyPlaceholder = "varName", keys = { type = "string" }, values = { type = "record", properties = { {								name = "default", type = "string", desc = "A default value for the variable, if applicable. If specified, the value will be used instead of a placeholder.", },							{								name = "placeholder", type = "string", desc = "A placeholder to display for the variable. Overriden by the  property if present.", },							{								name = "color", type = "string", desc = "A Template:Color color name, if the variable is always displayed using that color in-game.", },							{								name = "tooltip", required = true, type = "string", desc = "A tooltip explaining the possible values for a variable. In general, avoid explaining what the variable is for as that is usually obvious from context.", },							{								name = "doc", type = "string", desc = "An explanation of what the variable is and what contexts it's used in. Used for template documentation.", },						},					},				},			},		}	} end

p.Templates = { ["Variable"] = { description = "Used to indicate a variable in game transcripts", params = { [1] = {				name = "var", type = "string", desc = "A variable name.", enum = enum, },		},	}, }

return p