FANDOM


--
-- Implements [[Template:Levels formula]]
-- 
local p = {}
 
function p.main(frame)
	local args = frame:getParent().args
	local func = args.form or 'x+1'
	func = func:lower()
	local round = args.round or 0
	local h1 = args.h1 or 'Level'
	local h2 = args.h2 or 'Plus 1'
	local collapsible = args.collapse ~= nil
 
	local to120,max_itr,rowspan,rowspan3,dif,max_level
 
	if args.to120 and args.to120:lower() == 'yes' then
		to120 = true
		max_level = 120
	else
		to120 = false
		max_level = 99
	end
 
	max_itr = math.floor(max_level / 4)
	dif = math.ceil(max_level / 4)
	rowspan = dif + 1
	rowspan3 = max_itr + 1
 
	local function alg(x)
		local ret_form = func:gsub('(%d)x','%1*'..x..'')
				   :gsub('x',x)
		local ret_num = mw.ext.ParserFunctions.expr(ret_form..' round'..round)
		return ret_num
	end
 
	local ret_table = mw.html.create('table')
					:addClass('wikitable')
					:css('text-align','right')
 
	if collapsible then
		ret_table	:addClass('mw-collapsible')
					:addClass('mw-collapsed')
					:tag('tr')
						:tag('th')
							:attr('colspan','11')
							:wikitext(args.title or '')
						:done()
				   :done()
	end
 
	ret_table			:tag('tr')
						:tag('th'):wikitext(h1):done()
						:tag('th'):wikitext(h2):done()
						:tag('th'):attr('rowspan',rowspan):done()
						:tag('th'):wikitext(h1):done()
						:tag('th'):wikitext(h2):done()
						:tag('th'):attr('rowspan',rowspan):done()
						:tag('th'):wikitext(h1):done()
						:tag('th'):wikitext(h2):done()
						:tag('th'):attr('rowspan',rowspan3):done()
						:tag('th'):wikitext(h1):done()
						:tag('th'):wikitext(h2):done()
					:done()
 
 
	local function make_row(builder,x)
		builder:tag('tr')
				:tag('td'):wikitext(x):done()
				:tag('td'):wikitext(alg(x)):done()
				:tag('td'):wikitext(x+dif):done()
				:tag('td'):wikitext(alg(x+dif)):done()
				:tag('td'):wikitext(x+dif*2):done()
				:tag('td'):wikitext(alg(x+dif*2)):done()
				:tag('td'):wikitext(x+dif*3):done()
				:tag('td'):wikitext(alg(x+dif*3)):done()
		:done()
	end
 
	for i=1,max_itr,1 do
		make_row(ret_table,i)
	end
 
	if not to120 then
		ret_table:tag('tr')
			:tag('td'):wikitext(25):done()
			:tag('td'):wikitext(alg(25)):done()
			:tag('td'):wikitext(50):done()
			:tag('td'):wikitext(alg(50)):done()
			:tag('td'):wikitext(75):done()
			:tag('td'):wikitext(alg(75)):done()
			:tag('th'):attr('colspan','3'):done()
	end
 
	return ret_table
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.