Module:Infobox Weapon Group

From RuneRealm Wiki
Jump to navigation Jump to search

-- Module for [[Template:Weapon group]]

local p = {}

local infobox = require('Module:Infobox')

-- Format attack speed
function attackspeedarg(arg)
	if not infobox.isDefined(arg) then
		return nil
	end

	local lowarg = string.lower(arg)
	local numarg = tonumber(arg)
	
	if lowarg == 'no' or lowarg == 'n/a' then
		return 'N/A'
	elseif lowarg == 'varies' or lowarg == 'random' then
		return '<span title="Weapons in this group have a variable attack speed." style="cursor:help; border-bottom:1px dotted;">Variable</span>'
	end
	
	if numarg ~= nil then
		return string.format('%s %s (%.1f seconds)', numarg, (numarg > 1) and 'ticks' or 'tick', numarg * 0.6)
	end	
end

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

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

	ret:defineLinks({ hide = true })

	ret:create()
	ret:cleanParams()

	ret:defineName('Infobox Weapon Group')

	ret:addRow{
		{ tag = 'argh', content = 'name', class='infobox-header', colspan = '20' }
	}
	ret:pad(20)
	ret:addRow{
		{ tag = 'argd', content = 'images', class='infobox-image', colspan = '20' }
	}
	ret:pad(20)
	ret:addRow{
		{ tag = 'th', content = 'Primary [[Attack type|type]]', colspan = '7' },
		{ tag = 'argd', content = 'primary', colspan = '13' }
	}

	ret:addRow{
		{ tag = 'th', content = 'Secondary [[Attack type|type]]', colspan = '7' },
		{ tag = 'argd', content = 'secondary', colspan = '13' }
	}

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

	ret:pad(20)
	ret:addRow{
		{ tag = 'th', content = '[[Monster attack speed|Attack speed]]', class = 'infobox-subheader', colspan = '20' }
	}
	ret:pad(20)
	ret:addRow{
		{ tag = 'argd', content = 'speed', colspan = '20', class = 'infobox-full-width-content' }
	}
	ret:pad(20)

	return ret:tostring()
end

return p