Module:Ranged weapon group

-- Module for Template:Ranged 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 = 'ammunition', func = 'has_content' }, { name = 'twohanded', 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 = 'Ammunition', colspan = '7' }, { tag = 'argd', content = 'ammunition', colspan = '13' } }

ret:addRow{ { tag = 'th', content = 'Two handed?', colspan = '7' }, { tag = 'argd', content = 'twohanded', colspan = '13' } }

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