Module:Multiblock 2

local p = {}

p.multiblock = function(f) local args = f.args or f   if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end local alpha = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'} structure = {} local height = 0 for i, letter in ipairs(alpha) do if args[letter .. "A1"] ~= nil then --Good, another row structure[letter] = {} for i, j in ipairs(alpha) do if args[letter .. j .. 1] ~= nil then structure[letter][j] = {} for i = 1, 10 do --10 purely as a maximum, a 10x10 multiblock is way larger than would normally be sensible if args[letter .. j .. i] ~= nil then structure[letter][j][i] = args[letter .. j .. i]      					end end end end else if i ~= 1 then --mw.log("Ended at " .. alpha[i-1]) <- That's the height height = i-1 break --End of multiblock bits else return "Shorted" --Just give up ;)      		end       	end    end    --mw.logObject(structure)    local size = 0    if tableSize(structure) > 0 then    	for i, letter in ipairs(alpha) do    		if structure["A"][letter] ~= nil then --Relying on the fact that A is the right size, could also check the whole thing for uniformity    			local s = tableSize(structure["A"][letter])    			if (s > size) then    				size = s    			end			else				break			end		end	else		mw.log("A useless set of args was sent :|")		return "Shorted"	end	--mw.log("The size was " .. size)	 --There's no chance of this going wrong at all. EVERYTHING .	local test = {}	test[2] = (((size-1)*64)+32)	test[3] = (height*100)+15	local page = " " .. f:expandTemplate{title="Cg", args=test}	--local option = {{0},{-1,1},{-2,0,2},{-1,1},{0}} --temp solution until I'm more creative	for i, outter in ipairs(structure) do		local thing = stucture[outter]		for j, inner in ipairs(thing) do			local thinger = structure[outter][inner]			for k, num in ipairs(thinger) do				page = page .. f:expandTemplate{title="Cg", args={"cell", structure[outer][inner][num], 32*(math.ceil(size/2)+option[j][k]), 21+(16*(k-1)), class="craftingGridNoBg"}}			end		end	end--

page = page .. f:expandTemplate{title="Cg", args={"cell", structure["A"]["A"][1], 32*(math.ceil(size/2)+0), 21+(16*0), class="craftingGridNoBg"}} --Hmmm, hardcoding? Nahhhhhhh, just testing. page = page .. f:expandTemplate{title="Cg", args={"cell", structure["A"]["B"][1], 32*(math.ceil(size/2)-1), 21+(16*1), class="craftingGridNoBg"}} page = page .. f:expandTemplate{title="Cg", args={"cell", structure["A"]["B"][2], 32*(math.ceil(size/2)+1), 21+(16*1), class="craftingGridNoBg"}} page = page .. f:expandTemplate{title="Cg", args={"cell", structure["A"]["C"][1], 32*(math.ceil(size/2)-2), 21+(16*2), class="craftingGridNoBg"}} page = page .. f:expandTemplate{title="Cg", args={"cell", structure["A"]["C"][2], 32*(math.ceil(size/2)+0), 21+(16*2), class="craftingGridNoBg"}} page = page .. f:expandTemplate{title="Cg", args={"cell", structure["A"]["C"][3], 32*(math.ceil(size/2)+2), 21+(16*2), class="craftingGridNoBg"}} page = page .. f:expandTemplate{title="Cg", args={"cell", structure["A"]["B"][2], 32*(math.ceil(size/2)+1), 21+(16*3), class="craftingGridNoBg"}} page = page .. f:expandTemplate{title="Cg", args={"cell", structure["A"]["B"][1], 32*(math.ceil(size/2)-1), 21+(16*3), class="craftingGridNoBg"}} page = page .. f:expandTemplate{title="Cg", args={"cell", structure["A"]["A"][1], 32*(math.ceil(size/2)+0), 21+(16*4), class="craftingGridNoBg"}}

page = page .. f:expandTemplate{title="Cg", args={"end"}} return page .. "      " .. processTable(object, f) .. " " end

local function tableSize(T) --Stupid Lua even needing this local count = 0 for _ in pairs(T) do 		count = count + 1 end return count end

local function processTable(object, f) --p.table = function(object, f)	local doneTable = {} local doneObj = {} local ct = {}

local function _moveIn(object, indent, expandTable) local tp = type(object) --if tp == "number" or tp == "nil" or tp == "boolean" then			return tostring(object) --Let's just resume only strings (or tables) will come in		else--if tp == "string" then --Down to a Gc			--return f:expandTemplate{title="Cg", args={"cell", structure["A"]["A"][1], 32*(math.ceil(size/2)+0), 21+(16*4), class="craftingGridNoBg"}} return string.format("%q", object) elseif tp == "table" then if not doneObj[object] then local s = tostring(object) if s == "table" then ct[tp] = (ct[tp] or 0) + 1 doneObj[object] = "table#" .. ct[tp] else doneObj[object] = s					doneTable[object] = true end end if doneTable[object] or not expandTable then return doneObj[object] end doneTable[object] = true local ret = {doneObj[object], " {\n"} local doneKeys = {} for key, value in ipairs(object) do				doneKeys[key] = true ret[#ret + 1] = string.rep(" ", indent + 2) ret[#ret + 1] = _moveIn(value, indent + 2, true) ret[#ret + 1] = ",\n" end local keys = {} for key in pairs(object) do				if not doneKeys[key] then keys[#keys + 1] = key end end

for i = 1, #keys do				local key = keys[i] ret[#ret + 1] = string.rep(" ", indent + 2) ret[#ret + 1] = '[' ret[#ret + 1] = _moveIn(key, indent + 3, false) ret[#ret + 1] = '] = ' ret[#ret + 1] = _moveIn(object[key], indent + 2, true) ret[#ret + 1] = ",\n" end ret[#ret + 1] = string.rep(" ", indent) ret[#ret + 1] = '}' return table.concat(ret) else if not doneObj[object] then ct[tp] = (ct[tp] or 0) + 1 doneObj[object] = tostring(object) .. '#' .. ct[tp] end return doneObj[object] end end return _moveIn(object, 0, true) end

return p