Module:DamageType

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

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

local data, aliases = loader.loadData('DamageType/Data', 'DamageType/Aliases') local p = {}

function p.getDamageType(frame) local args = getArgs(frame) local damage_type = args[1] local valBefore = args[2] local isShort = yesno(args["short"]) return p._getDamageType(damage_type, valBefore, isShort) end

function p.getDamageTypeShort(frame) local args = getArgs(frame) local damage_type = args[1] local valBefore = args[2] return p._getDamageType(damage_type, valBefore, true) end

function p._getDamageType(damage_type, valBefore, isShort) checkType(1, damage_type, 'string') checkType(2, valBefore, { 'string', 'number'}, true) checkType(3, isShort, 'boolean', true) local damage_type = damage_type:match('^(%w+)') damage_type = damage_type:lower damage_type = damage_type:lower:gsub('_', ' ') damage_type = aliases[damage_type] or damage_type local damage_type = data[damage_type] if not damage_type then return string.error("Invalid damage type %q", damage_type) end return string.wrapHtml{ {			valBefore and color.colorText("green", valBefore)..' ' or '', string.makeImage(				damage_type.icon,				{					size=damage_type.size or "24x24px",					link=damage_type.name,				}			), string.wrapHtml{' ', " ", {style='font-family:initial;';}}, string.makeLink(damage_type.link and damage_type.link or damage_type.name, string.wrapHtml{				{					damage_type[isShort and 'nameShort' or 'name']				}, ' ', {					style={						color=damage_type.color					}				}			}), },		' ', {			style="whitespace: no-wrap;"; }	} end

return p