Module:Attack speed bar

From Old School Near-Reality Wiki
Revision as of 14:40, 8 November 2022 by Jacmob (talk | contribs) (Created page with "local p = {} local editbutton = require('Module:Edit button') local valid_speeds = { ['1'] = true, ['2'] = true, ['3'] = true, ['4'] = true, ['5'] = true, ['6'] = true, ['7'] = true, ['8'] = true, ['9'] = true, ['10'] = true, ['12'] = true, ['15'] = true, ['random'] = true, ['varies'] = true, ['n/a'] = true, } function p.make_bar(speed) if not speed or speed == '' then return editbutton("'''?''' (edit)") end speed = string.lower(speed) if not va...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Attack speed bar/doc. [edit]
Module:Attack speed bar requires Module:Edit button.
Module:Attack speed bar is required by Module:Infobox Bonuses.
Module:Attack speed bar is required by Module:Infobox Monster.

local p = {}

local editbutton = require('Module:Edit button')

local valid_speeds = {
	['1'] = true,
	['2'] = true,
	['3'] = true,
	['4'] = true,
	['5'] = true,
	['6'] = true,
	['7'] = true,
	['8'] = true,
	['9'] = true,
	['10'] = true,
	['12'] = true,
	['15'] = true,
	['random'] = true,
	['varies'] = true,
	['n/a'] = true,
}

function p.make_bar(speed)
	if not speed or speed == '' then
		return editbutton("'''?''' (edit)")
	end

	speed = string.lower(speed)

	if not valid_speeds[speed] then
		return '<span '..
			'title="The given speed value was invalid" '..
			'style="color:red; font-weight:bold; cursor:help; border-bottom:1px dotted red;">'..
			'ERR</span>'
	end
	if speed == 'n/a' then
		return 'N/A'
	elseif tonumber(speed) ~= nil then
		return '[[File:Monster attack speed ' .. speed  .. '.png|link=Attack speed]]'
	else
		return '[[File:Monster attack speed random.gif|link=Attack speed]]'
	end
end

function p.main(frame)
	local args = frame:getParent().args

	local speed = args[1] or ''
	return p.make_bar(speed)
end

return p