Module:Weapon group

-- Module for Template:Weapon group

local p = {}

local infobox = require('Module:Infobox') local attack_speed_bar = require('Module:Attack speed bar').make_bar

local valid_speeds = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '12', '15', 'random', 'varies' }

-- Main function called with invokes function p.main(frame) local args = frame:getParent.args local ret = infobox.new(args)

ret:defineParams{ { name = 'images', func = 'has_content' }, { name = 'primary', func = 'has_content' }, { name = 'secondary', func = 'has_content' }, { name = 'tertiary', func = 'has_content' }, { name = 'speed', func = speedarg }, }

ret:defineLinks( { links={{ 'Template:%s/FAQ', 'FAQ' },			{ 'Template:%s/doc', 'doc' }} })

ret:create ret:cleanParams

ret:defineName('Weapon group') ret:addClass('rsw-infobox infobox-weapon-group')

ret:addRow{ { tag = 'argd', content = 'images', class='infobox-image', colspan = '20' } }

ret:addRow{ { tag = 'th', content = 'Primary type', colspan = '7' }, { tag = 'argd', content = 'primary', colspan = '13' } } ret:addRow{ { tag = 'th', content = 'Secondary type', colspan = '7' }, { tag = 'argd', content = 'secondary', colspan = '13' } }

if ret:paramDefined('tertiary') then ret:addRow{ { tag = 'th', content = 'Tertiary type', colspan = '7' }, { tag = 'argd', content = 'tertiary', colspan = '13' } } end

ret:addRow{ { tag = 'th', content = 'Attack speed', class = 'infobox-subheader', colspan = '20' } }

ret:addRow{ { tag = 'argd', content = 'speed', colspan = '20', class = 'infobox-full-width-content' } }

return ret:tostring end

-- Return a speed bar image if given valid speed function speedarg(arg) if not infobox.isDefined(arg) then return nil end

local arg = string.lower(arg) for i, valid_speed in ipairs(valid_speeds) do		if arg == valid_speed then return tostring(attack_speed_bar(arg)) end end

return badarg('attack speed', "should be a valid number or 'random'.") end

-- red ERR span with title hover for explanation function badarg(argname, argmessage) return ''.. 'ERR ' end

return p