Module:Ability rotation

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Ability rotation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Ability rotation/doc. [edit]
Module:Ability rotation's function main is invoked by Template:Ability rotation.
Module:Ability rotation requires Module:Paramtest.
Module:Ability rotation loads data from Module:Abilities/data.
Module:Ability rotation loads data from Module:Spells/data.
Function list
L 13 — p.main
L 17 — p._main

local hc = require('Module:Paramtest').has_content
local p = {}
local lang = mw.getContentLanguage()
local abilities = mw.loadData('Module:Abilities/data')
local spells = mw.loadData('Module:Spells/data')

local sep = ' ▸ '
local sep2 = ' *, *'

local manualOverrides = {
}

function p.main(frame)
	return p._main(frame:getParent().args)
end

function p._main(args)
	if hc(args.sep) then
		sep = ' '..args.sep..' '
	end
	local ret = {}
	for i,v in ipairs(args) do
		v = mw.text.trim(v)
		if v:sub(0,1) == '@' then
			table.insert(ret, mw.text.trim(string.sub(v,2)))
		else
			local subret = {}
			for j in mw.text.gsplit(v, sep2) do
				j = mw.text.trim(j)
				local jlow = j:lower()
				local img, link = '',''
				if manualOverrides[j:lower()] then
					j = manualOverrides[jlow]
					if type(j) == 'table' then
						link, img = unpack(j)
					else
						img, link = j,j
					end
				elseif abilities[jlow] then
					j = abilities[jlow]
					img = j.image or j.link
					link = j.link
				elseif spells[jlow] then
					j = spells[jlow]
					img = j.image or j.link
					link = j.link
				elseif j:find(' %(6%)') or j:find('potion') then
					j = j:gsub(' %(6%)', '')
					j = lang:ucfirst(j)
					img = j .. ' (6)'
					link = j
				else
					j = lang:ucfirst(j)
					img, link = j, j
				end
				table.insert(subret, string.format('[[File:%s.png|link=%s|30x30px|frameless]]', img, link))
			end
			table.insert(ret, table.concat(subret, ' '))
		end
	end
	local class = 'ability-rotation'
	if hc(args.noclass) then
		class = ''
	end
	return string.format('<div class="%s">%s</div>', class, table.concat(ret, sep))
end

return p