Module:DamageType

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

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

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) libU.checkType(1, damage_type, 'string') libU.checkType(2, valBefore, { 'string', 'number'}, true) libU.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.name .. ' Icon.png',				{					size=damage_type.size or '24x24px',					link=damage_type.name,				}			), string.wrapHtml{ ' ', ' ', { class = 'font-initial' } }, string.makeLink(damage_type.link and damage_type.link or damage_type.name, string.wrapHtml{				{					damage_type[isShort and 'nameShort' or 'name']				}, ' ', {					class = 'hsw-gamefont',					style = {						color = damage_type.color					}				}			}), },		' ', {			class = 'txt-nowrap'; }	} end

return p