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) if not noerror then assertTrue(type(statname) == 'string', '`statname` must be a string') end 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: Statname -- -- Makes a formatted stat with an image - function p._stat(frame) local args = getArgs(frame) local short = args[3] or args['short'] return p.stat({		stat = args[1],		valBefore = args[2],		isShort = yesno(short),		isSuperShort = short == 'ss',		asChar = args.char,		isCram = args.cram,		imgSize = args.imgsize,	}) end

- -- Template: StatnameShort -- -- Makes a formatted short stat with an image - function p._statShort(frame) local args = getArgs(frame) return p.stat({		stat = args[1],		valBefore = args[2],		isShort = true,		isSuperShort = false,		asChar = args.char,		isCram = args.cram,		imgSize = args.imgsize,	}) end

- -- Template: StatnameSuperShort -- -- Makes a formatted super short stat with an image - function p._statSuperShort(frame) local args = getArgs(frame) return p.stat({		stat = args[1],		valBefore = args[2],		isShort = true,		isSuperShort = true,		asChar = args.char,		isCram = args.cram,		imgSize = args.imgsize,	}) end

- -- function: stat(stat, valBefore, isShort, isSuperShort) -- -- Makes a formatted stat with an image - function p.stat(...) local _stat, valBefore, isShort, isSuperShort, asChar, isCram, imgSize if type(({...})[1]) == 'table' then local u = ({...})[1] _stat, valBefore, isShort, isSuperShort, asChar, isCram, imgSize = u.stat or u[1], u.valBefore, u.isShort, u.isSuperShort, u.asChar, u.isCram, u.imgSize else _stat, valBefore, isShort, isSuperShort, asChar, isCram, imgSize = ... end assertTrue(_stat and (_stat.lower == string.lower), '`stat` must be a string', 2) local tValBefore, stat = _stat:lower:match('^([%-%+]?[%d%.]+%%?)%s*(.+)$') if not stat then stat = _stat else valBefore = tValBefore end stat = p._getstatdata(stat:lower:gsub('_', ' ')) assertTrue(stat, 'Invalid stat name %q', 2, _stat) local icon = stat.name .. ' Stat Icon.png' return string.wrapHtml{ {			valBefore and color.colorText('green', valBefore) .. ' ' or '', stat.prefix and string.makeLink(stat.prefixName, color.colorText(stat.prefixColor, isSuperShort and stat.prefixNameSuperShort or isShort and stat.prefixNameShort or stat.prefixName)) .. ' ' or '', asChar and string.wrapHtml(stat.character, 'span', { style = 'color:' .. color.getColor(stat.color) }) or string.makeImage(icon, { size = imgSize or stat.size or 'x15px', link = stat.name, class = 'staticon' }), string.wrapHtml{ ' ',				' ', {					class = 'font-initial ' .. (stat.shadow and 'article-stat-shadow' or '') }			},			string.makeLink(				stat.link or stat.name, 				string.wrapHtml{					isSuperShort and stat.nameSuperShort or (isShort and stat.nameShort or stat.name),					" ", {						class = 'hsw-gamefont' .. (isCram and ' cram' or ''),						style = {							color = color.getColor(stat.color);						},					},				}			), },		' ', {			class = 'txt-nowrap' }	} end

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

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

return p