Module:Cg

--Lua version of. WIP. local p = {}

p.cg = function(f) local args = f.args or f	if f == mw.getCurrentFrame and args[1] == nil then args = f:getParent.args else f = mw.getCurrentFrame end local type = args[1] or args["type"] if type == "cell" then local grids = args[2] if grids ~= nil then local div = mw.html.create("div"):css("left", (args[3] or args["x"]) .. "px"):css("top", (args[4] or args["y"]) .. "px"):css("width", "32px"):css("height", "32px"):css("position", "absolute")

if args["style"] ~= nil then div:css(args["style"]) --TODO: possibily modify templates that use this end

div:addClass("gridItemContainer"):addClass("CraftingGridCell") if args["class"] ~= nil then div:addClass(args["class"]) --TODO: possibily modify templates that use this end

return tostring(div:wikitext(grids)) else return mw.html.create("div") end elseif type == "tank" then local width = args["width"]

local div = mw.html.create("div"):css("display", "inline-block"):css("position", "absolute"):css("left", (args[3] or args["x"]) .. "px"):css("top", (args[4] or args["y"]) .. "px"):css("width", (width or "32") .. "px"):css("height", (args["height"] or "120") .. "px")

if args["style"] ~= nil then div:css(args["style"]) --TODO: possibily modify templates that use this end

div:addClass("gridTankContainer"):addClass("CraftingGridCell")

if args["class"] ~= nil then div:addClass(args["class"]) --TODO: possibily modify templates that use this end

div:attr("data-tank-max", args[5] or "10000"):wikitext(args[2]) if args["nooverlay"] == nil then local div2 = mw.html.create("div"):css("position", "absolute"):css("top", "0"):css("pointer-events", "none"):addClass("tankOverlayImage"):addClass("ignore") local wikitext = "[[File:GUI tank"			if width ~= nil then				wikitext = wikitext .. "_" .. width			end			div:node(div2:wikitext(wikitext .. "_" .. (args["height"] or "120") .. ".png|link=]]")) end return tostring(div) elseif type == "text" then local div = mw.html.create("div"):css("left", (args[5] or args["x"]) .. "px"):css("top", (args[6] or args["y"]) .. "px"):css("position", "absolute"):css("display", "inline-block")

if args["style"] ~= nil then div:css(args["style"]) --TODO: possibily modify templates that use this end

div:addClass("gridTextContainer", "CraftingGridCell")

if args["class"] ~= nil then div:addClass(args["class"]) --TODO: possibily modify templates that use this end return tostring(div:wikitext(args[2] .. args[3] .. args[4])) elseif type == "shapeless" then local span = mw.html.create("span"):css("position", "absolute"):css("cursor", "help"):css("left", (args[2] or args["x"]) .. "px"):css("top", (args[3] or args["y"]) .. "px")

if args["style"] ~= nil then span:css(args["style"]) --TODO: possibily modify templates that use this end

if args["class"] ~= nil then span:addClass(args["class"]) --TODO: possibily modify templates that use this end

return tostring(span:attr("title", "This recipe is shapeless; the inputs may be placed in any arrangement in the crafting grid.")) .. ""	elseif type == "end" then --Not really any way around this (at least without a pure lua solution) return " " elseif type == "image" then local div = mw.html.create("div"):css("left", (args[3] or args["x"]) .. "px"):css("top", (args[4] or args["y"]) .. "px"):css("position", "absolute"):css("display", "inline-block")

if args["style"] ~= nil then div:css(args["style"]) --TODO: possibily modify templates that use this end

div:addClass("CraftingGridCell"):addClass("gridImageContainer")

if args["class"] ~= nil then div:addClass(args["class"]) --TODO: possibily modify templates that use this end return tostring(div:wikitext(args[2])) elseif type == "bg-image" then local div = mw.html.create("div"):css("position", "absolute") local wikitext = "")) elseif type == "progress" then local div = mw.html.create("div"):css("position", "absolute")

if args["reverse"] ~= nil then div:addClass("progress-reverse") else div:addClass("progress") end

local dir = args[5] or args["dir"]

div:css("animation-name", "progress-" .. dir):css("left", (args[3] or args["x"]) .. "px"):css("top", (args[4] or args["y"]) .. "px"):css("position", "absolute"):css("display", "inline-block")

local clip = "rect("		if dir == "up" then			clip = clip .. (args[6] or args["size"] or "0") .. "px auto auto auto"		elseif dir == "right" then			clip = clip .. "auto " + (args[6] or args["size"] or "0") .. "px auto auto"		elseif dir == "down" then			clip = clip .. "auto auto " + (args[6] or args["size"] or "0") .. "px auto"		elseif dir == "left" then			clip = clip .. "auto auto auto " + (args[6] or args["size"] or "0") .. "px"		end		return tostring(div:css("clip", clip .. ")"):wikitext("")) else --Not really any way around this (at least without a pure lua solution) local float = args["float"] local ret = "" if float ~= nil then ret = ret .. ""		end return ret end end

return p