Module:Statname

-- local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader')

local string, table, yesno, color = loader.require('String', 'Table', 'Yesno', 'Color')

local aliases, statData = loader.loadData('Statname/Aliases', 'Statname/Data')

local p = {}

function p._getstatdata(statname, noerror) checkType(1, statname, { 'string' }) statname = string.trim(statname:lower):gsub('_', ' ') local dt = statData[aliases[statname] or statname] if not dt then for k, v in pairs(statData) do			if statname == v.name:lower or statname == v.nameSuperShort:lower or statname == v.shortcode:lower or statname == v.nameShort:lower then dt = v			end end end if not noerror then assertTrue(dt, 'bad argument #1 to \'_getstatdata\' (Unknown stat %q)', 2, statname) end return dt end

- -- Template: Stat -- -- Makes a formatted stat with an image - function p._stat(frame) local args = getArgs(frame) local short = args[3] or args["short"] return string.pcall(p.stat, args[1], args[2], yesno(short), short=="ss") end

- -- Template: StatShort -- -- Makes a formatted short stat with an image - function p._statShort(frame) local args = getArgs(frame) return string.pcall(p.stat, args[1], args[2], true) end

- -- function: stat(stat, valBefore, isShort, isSuperShort) -- -- Makes a formatted stat with an image - function p.stat(...) local _stat, valBefore, isShort, isSuperShort = checkArgs({ 'string', { 'string', nilOk=true }, { 'boolean', nilOk=true }, { 'boolean', nilOk=true } }, ...) local tValBefore, stat = _stat:lower:match('^([%-%+]?[%d%.]+%%?)%s*(.+)$') if not stat then stat = _stat else valBefore = tValBefore end stat = stat:lower:gsub('_', ' ') local stat = p._getstatdata(stat) assertTrue(stat, "Invalid stat name %q", 2, _stat) assertTrue(stat.icon, _stat, 2) return string.wrapHtml{ {			valBefore and color.colorText("green", valBefore) .." " or "", string.makeImage(stat.icon, { size=stat.size or "18x18px", link=stat.name }), string.wrapHtml{ " ", 				" ", { 					style={ ["font-family"]="initial"; ['text-shadow']=stat.shadow and "1px 1px 1px black"; }				}			},			string.makeLink(				stat.link and stat.link or stat.name, 				color.colorText(stat.color, isSuperShort and stat.nameSuperShort or (isShort and stat.nameShort or stat.name))			), },		' ', {			style={ ["white-space"]="nowrap"; }		}	} end

- -- function: isStatAlias(s: string) -- -- Checks if a string is a valid stat name or alias. - function p.isStatAlias(s) checkType(1, s, { 'string' }) return not not aliases[s] end

-- For backwards compatabillity p.getStatNameShort = p._statShort p.getStatName = p._stat p._getStatName = p.stat

return p