Module:Statname

-- local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local onmain = require('Module:Mainonly').on_main local string = require('Module:String') local color = require('Module:Color') local p = {}

-- Converts Aliases into ID's local aliases = require('Module:Statname/aliases') local statData = require('Module:Statname/Data')

- -- Template: Stat -- -- Makes a formatted stat with an image - function p._stat(frame) local args = getArgs(frame) return string.pcall(p.stat, args[1], args[2], args[3]) 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) -- -- Makes a formatted stat with an image - function p.stat(_stat, valBefore, isShort) checkType(1, _stat, { 'string' }) checkType(2, valBefore, { 'string' }, true) checkType(3, isShort, { 'boolean' }, true) local valBefore, stat = _stat:lower:match('^([%-%+]?[%d]+%%?)%s*(.+)$') if not stat then stat = _stat end stat = stat:lower:gsub('_', ' ') local stat = statData[aliases[stat] or stat] if not stat then error(string.format("Invalid stat name %q", _stat), 2) end return string.wrapHtml{ {			valBefore and color.colorText(stat.color, 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.name, 				color.colorText(stat.color, isShort and stat.nameShort or stat.name)			), },		' ', {			style={ ["white-space"]="nowrap"; }		}	} end -- For backwards compatabillity p.getStatNameShort = p._statShort p.getStatName = p._stat p._getStatName = p.stat

return p