Module:Card stats

From Sekaipedia

Documentation for this module may be created at Module:Card stats/doc

local getArgs = require('Module:Arguments').getArgs
local util    = require('Module:Utilities')
local VariablesLua = mw.ext.VariablesLua

local p = {}

function p.main(frame)
	local args = getArgs(frame)
	
	local rarity = args['rarity'] or VariablesLua.var('rarity')
	
	local minPerformance = args['min performance']
	local minTechnique   = args['min technique']
	local minStamina     = args['min stamina']
	local minPower       = args['min power']

	local maxPerformance = args['max performance']
	local maxTechnique   = args['max technique']
	local maxStamina     = args['max stamina']
	local maxPower       = args['max power']
	
	local maxLevel = '?'
	local maxLevels = {
		['1'] = '20',
		['2'] = '30',
		['3'] = '50',
		['4'] = '60',
		['birthday'] = '60',
		['Birthday'] = '60'
	}
	
	if rarity ~= nil and rarity ~= '' then
		maxLevel = maxLevels[rarity] or '?'
	end

	assert((tonumber(minPower) or 0) == 
		(tonumber(minPerformance) or 0) +
		(tonumber(minTechnique) or 0) +
		(tonumber(minStamina) or 0))
		
	assert((tonumber(maxPower) or 0) == 
		(tonumber(maxPerformance) or 0) +
		(tonumber(maxTechnique) or 0) +
		(tonumber(maxStamina) or 0))

	
	local root = mw.html.create('table')
		:addClass('wikitable')
		:tag('tr')
			:tag('th')
				:attr('height', '30px')
				:done()
			:tag('th')
				:wikitext('Level 1')
				:done()
			:tag('th')
				:wikitext('Level ' .. maxLevel)
				:done()
			:done()
		:tag('tr')
			:tag('th')
				:attr('height', '30px')
				:wikitext('[[File:Icon performance.png|25px|link=]] Performance')
				:done()
			:tag('td')
				:wikitext(util.editIfNil(minPerformance))
				:done()
			:tag('td')
				:wikitext(util.editIfNil(maxPerformance))
				:done()
			:done()
		:tag('tr')
			:tag('th')
				:attr('height', '30px')
				:wikitext('[[File:Icon technique.png|25px|link=]] Technique')
				:done()
			:tag('td')
				:wikitext(util.editIfNil(minTechnique))
				:done()
			:tag('td')
				:wikitext(util.editIfNil(maxTechnique))
				:done()
			:done()
		:tag('tr')
			:tag('th')
				:attr('height', '30px')
				:wikitext('[[File:Icon stamina.png|25px|link=]] Stamina')
				:done()
			:tag('td')
				:wikitext(util.editIfNil(minStamina))
				:done()
			:tag('td')
				:wikitext(util.editIfNil(maxStamina))
				:done()
			:done()
		:tag('tr')
			:tag('th')
				:attr('height', '30px')
				:wikitext('Power')
				:done()
			:tag('td')
				:wikitext(util.editIfNil(minPower))
				:done()
			:tag('td')
				:wikitext(util.editIfNil(maxPower))
				:done()
			:done()
		:done()
	
	return tostring(root)
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.