Skylords Reborn
Advertisement

Edit documentation

Description[]

Used by template Ability icon.

See also[]


local p = {}

local function link(args)
	if not args[2] then return 'Name missing' end
	
	local s = string.find(args[2], ' (Promo)', 1, true)
	
	if s then return string.sub(args[2], 1, s) end
	
	return args[2]
end

function p.main(frame)
	local lib = require('Module:Shared')
	local format = lib.format
	local args = lib.getArgs(frame)
	
	local l = link(args)
	local ll = format('[[%s|%s]]', l, args[3] or args[1])
	if args.icononly then ll = '' end
	
	local types = {
		passive = 'Passive',
		active = 'Active',
		godspell = 'Godspell',
		autocast = 'Autocast',
		toggle = 'Toggle',
		blank = 'Blank'
	}

	if args.usetypeicon then
		local get = require('Module:Card/get')
		local exts = {'', ' (Fire)', ' (Frost)', ' (Nature)', ' (Shadow)', ' (Promo)', ' (Lost Souls)', ' (Twilight)', ' (Superpig)'}
		local affs = {string.find(args[2], ' (Promo)', 1, true) and get.affinity(args[2]) or nil, 'Fire', 'Frost', 'Nature', 'Shadow', get.affinity(args[2] .. " (Promo)")}
		local abilities = {}
		local types = {
			passive = 'Passive',
			active = 'Active',
			godspell = 'Godspell',
			autocast = 'Autocast',
			toggle = 'Toggle',
			blank = 'Blank'
		}
		local i = types[tostring(args.usetypeicon)] or nil

		-- iterate over cards
		for k,v in ipairs(exts) do
			-- iterate over abilities
			for _,vv in ipairs(get.abilities(args[2]..v) or {}) do
				if vv.name == args[1] then
					if not (vv.type or i) or i == 'Blank' then return ll end
					if vv.affinity_dependency and affs[k] then
						return format('[[File:Card Icon %s Affinity %s.png|%s|link=%s]] %s',
							i or vv.type, affs[k], args.size or '20px', l, ll)
					else
						return format('[[File:Card Icon %s.png|%s|link=%s]] %s', i or vv.type, args.size or '20px', l, ll)
					end
				end
			end
		end
		-- ability not in data but usetypeicon provided
		if i then return format('[[File:Card Icon %s.png|%s|link=%s]] %s', i, args.size or '20px', l, ll) end
	end

	local cost = ''
	if args.cost then
		local cs = (args.size or '24px'):gsub("px", "")
		cost = format('<span style="position:absolute; line-height:1em; pointer-events:none; right:5px; top:0; color:#EEE; text-shadow:-1px 0 1px #000, 0 1px 1px #000, 1px 0 1px #000, 0 -1px 1px #000;font-size: %spx;">%s</span>', tonumber(cs or 24) / 2, args.cost)
	end

	return format('<span style="display: inline-block; position: relative; white-space: pre;">[[File:%s_%s_Ability_Icon.png|%s|border|link=%s]]&nbsp;%s</span>%s', args[2], args[1], args.size or '20px', l, cost, ll)
end

return p
Advertisement