Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Rarity icon: Difference between revisions

From Sekaipedia
Content added Content deleted
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 11: Line 11:


function p._main(args)
function p._main(args)
local rarity = string.lower(args[1] or '')
local rarity = nil
local size = args['size'] or '30px'
local size = '30px'
local trained = yesno(args['trained'], false)


local icons = data
local icons = data
local rarityNum = tonumber(rarity)
for _, val in ipairs(args) do
if rarity == 'birthday' then
return string.format('[[File:%s|x%s]]', icons['birthday'], size)
if string.find(val, "^[1-5]$") or
string.find(val, "^[1-5] trained$") or
elseif rarityNum and rarityNum >= 1 and rarityNum <= 5 then
string.lower(val) == 'birthday' then
local starIcon = icons['star']
rarity = string.lower(val)
elseif string.find(val, "^%d+px$") then
if trained then
size = val
starIcon = icons['star trained']
end
end
local ret = ''
for i=1,rarityNum do
ret = ret .. string.format('[[File:%s|x%s]] ', starIcon, size)
end
return ret
end
end
return nil
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
end



Latest revision as of 03:56, 22 January 2022

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.