Module:Rarity icon

From Sekaipedia

Documentation for this module may be created at Module:Rarity icon/doc

local getArgs = require('Module:Arguments').getArgs
local yesno   = require('Module:Yesno')
local data    = mw.loadData('Module:Rarity icon/data')

local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local rarity = nil
	local size = '30px'

	local icons = data
	
	for _, val in ipairs(args) do
		if string.find(val, "^[1-5]$") or 
			string.find(val, "^[1-5] trained$") or
			string.lower(val) == 'birthday' then
			rarity = string.lower(val)
		elseif string.find(val, "^%d+px$") then
			size = val
		end
	end
	
	if rarity == nil then
		return nil
	end
	
	if rarity == 'birthday' then
		return string.format('[[File:%s|x%s|link=]]', icons['birthday'], size)
	end
	
	local count = tonumber(string.match(rarity, "[1-5]"))
	local trained = string.match(rarity, "trained")
	
	local starIcon = icons['star']
	
	if trained then
		starIcon = icons['star trained']
	end
	
	local ret = {}
	for i=1, count do
		table.insert(ret, string.format('[[File:%s|x%s|link=]]', starIcon, size))
	end
	return table.concat(ret, ' ')	
end

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