FANDOM


-- <nowiki>
 
local p = {}
 
local _defaults = function(s,d) if not s or not s:find('%S') then return d else return s end end
 
local default_params = {
	requirements = true,
	class = true,
	slot = true,
	degrades = true,
	mainDamage = true,
	mainAccuracy = true,
	offDamage = true,
	offAccuracy = true,
	style = true,
	armour = true,
	life = true,
	prayer = true,
	strength = true,
	ranged = true,
	magic = true,
	aspeed = true,
	image = true,
	caption = true,
	['image2'] = true,
	['caption2'] = true
}
 
function p.main(frame)
	local multi = string.lower(frame:getParent().args.multi or '') == 'yes'
	if multi then
		return p.multi(frame)
	else
		return p.single(frame)
	end
end
 
function p.multi(frame)
	local infobox_params = {}
	local args = frame:getParent().args
	local all_args = {}
	all_args.universal = {}
	for i, v in ipairs(frame.args) do
		if default_params[v] then
			table.insert(infobox_params,v)
		end
	end
 
	local ret = {}
	local max_i = 0
	local pagename = args['%PAGE%'] or ''
	for i=1,20 do
		if not args['version'..i] then
			break
		else
			all_args['item_s_'..i] = { version_name = args['version'..i] }
			max_i = i
		end
	end
	if max_i == 0 then
		return ''
	end
	all_args.max_value_i = max_i
	for _, v in ipairs(infobox_params) do
		all_args.universal['_'..v..'_'] = _defaults(args[v],'')
		for i=1,max_i do
			all_args['item_s_'..i]['_'..v..'_'] = args[v..'_'..i] or args[v..i]
		end
	end
	for i=1,all_args.max_value_i do
		local rowi = {}
		if i>1 then
			table.insert(rowi,'|-')
			table.insert(rowi,'| [['..pagename..']]')
		end
		for _, v in ipairs(infobox_params) do
			local param_x = all_args['item_s_'..i]['_'..v..'_'] or all_args.universal['_'..v..'_']
			if param_x:find('%$%d+') then
				local p_n = param_x:match('%$(%d+)')
				param_x = all_args['item_s_'..p_n]['_'..v..'_'] or all_args.universal[v]
			end
			table.insert(rowi,'|'..param_x)
		end
		table.insert(rowi,'|')
		rowi = table.concat(rowi,'\n')
		table.insert(ret,rowi)
	end
	return table.concat(ret,'\n')
end
 
function p.single(frame)
	local infobox_params = {}
	local args = frame:getParent().args
	for i, v in ipairs(frame.args) do
		if default_params[v] then
			table.insert(infobox_params,v)
		end
	end
 
	local ret = {}
	local pagename = args['%PAGE%'] or ''
	for _, v in ipairs(infobox_params) do
		table.insert(ret,'|'.._defaults(args[v],''))
	end
	return table.concat(ret,'\n')
end
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.