Mobius Final Fantasy Wiki
Advertisement

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

local getArgs = require("Module:Arguments").getArgs

local function round(n)
	return math.floor(n + 0.5)
end

local data = mw.loadData("Module:Component/data")

local p = {}

function p.icon(frame)
	local args = getArgs(frame, {
		wrappers = "Template:Component"
	})
	return p._icon(args)
end
function p._icon(args)
	local key = args[1]
	local entry = data[key:lower()]
	if not entry then return key end
	
	local icon = entry.icon
	local name = entry.name
	local timed = entry.timed
	local size = args.size or args.s
	local w, h
	if size then
		w, h = string.match(size, "(%d*)x?(%d*)px")
	end
	-- default 18x18px
	w = tonumber(w) or tonumber(h) or 18
	h = tonumber(h) or tonumber(w) or 18
	-- component icons use 64x64 icons, so scale accordingly.
	local scaleW = w / 64
	local scaleH = h / 64

	local root = mw.html.create()
	local wrapper = root:tag('span')
		:addClass("component icon")
		:cssText("position:relative;display:inline-block;width:"..round(64*scaleW).."px;height:"..round(64*scaleH).."px;")
		:wikitext("[[File:"..icon.."|"..round(60*scaleW).."x"..round(60*scaleH).."px|top|link=|alt=]]")
	if timed then
		wrapper:tag("span")
			:cssText("position:absolute;bottom:0;right:0;width:"..round(29*scaleW).."px;height:"..round(29*scaleH).."px;")
			:wikitext("[[File:Icon timed component.png|"..round(29*scaleW).."x"..round(29*scaleH).."px|top|link=|alt=]]")
	end
	root:wikitext("[["..name.."]]")
	
	return tostring(root)
end

return p
Advertisement