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 p = {}

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

local statData = { ['health']={ name="Health", nameShort="HP", icon="Health icon.png", color="#e73c3c" },	['defense']={ name="Defense", nameShort="Def", icon="Defense icon.png", color="#00d400" },	['effective health']={ name="Effective Health", nameShort="EHP", icon="Health icon.png", color="#e73c3c" },	['strength']={ name="Strength", nameShort="Str", icon="Strength icon.png", color="#e73c3c" },	['speed']={ name="Speed", nameShort="Spd", icon="Speed icon.png", color="#eee", shadow=true, },	['crit chance']={ name="Crit Chance", nameShort="Cr Chnc", icon="Crit chance icon.png", color="#5555ff" },	['crit damage']={ name="Crit Damage", nameShort="Cr Dmg", icon="Crit damage icon.png", color="#5555ff" },	['intelligence']={ name="Intelligence", nameShort="Int", icon="Intelligence icon.png", color="cyan" },	['mana']={ name="Mana", nameShort="Mana", icon="Intelligence icon.png", color="cyan" },	['mana cost']={ name="Mana Cost", nameShort="Mana Cst", icon="Intelligence icon.png", color="cyan" },	['true defense']={ name="True Defense", nameShort="Tru Def", icon="True Defense icon.png", color="white", shadow=true, },	['absorption']={ name="Absorption", nameShort="Absorb", icon="Absorption icon.png", color="#ffaa00" },	['magic find']={ name="Magic Find", nameShort="Mag Fnd", icon="Magic Find icon.png", color="cyan" },	['pet luck']={ name="Pet Luck", nameShort="Pet Lck", icon="Pet Luck icon.png", color="#FF55FF" },	['sea creature chance']={ name="Sea Creature Chance", nameShort="SCC", icon="Sea creature chance icon.png", size="16px", color="#00AAAA" },	['damage']={ name="Damage", nameShort="Dmg", icon="Damage Icon.png", size="16px", color="white", shadow=true },		['bonus attack speed']={ name="Bonus Attack Speed", nameShort="Atk Spd", icon="Bonus Attack Speed icon.png", color="#FDED00" },	['true damage']={ name="True Damage", nameShort="Tru Dmg", icon="True Damage Icon.png", color="white", shadow=true },	['fishing speed']={ name="Fishing Speed", nameShort="Fshng Spd", icon="Fishing Rod.png", color="#49e02b" },	['ability damage']={ name="Ability Damage", nameShort="Ablty Dmg", icon="Ability Damage.png", color="#FF5555" },	['ferocity']={ name="Ferocity", nameShort="Frcty", icon="Ferocity icon.png", color="#FF5555" }, }

- -- 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 string.wrapHtml(valBefore, ' ', { style=table.concat{ "color:", stat.color }}) .." " 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, 				string.wrapHtml{ 					isShort and stat.nameShort or stat.name, 					' ', { 						style=table.concat{ "color:", stat.color },					}				}			), },		' ', {			style={ ["white-space"]="nowrap"; }		}	} end -- For backwards compatabillity p.getStatNameShort = p._statShort p.getStatName = p._stat p._getStatName = p.stat

return p