Module:Sandbox/Fewfre/perf

-- -- Taken from: https://minecraft.gamepedia.com/Module:UI local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader')

local table, string, _, uiText, yesno, inventorySlot, crafting = loader.require('Table', 'String', 'LibraryUtil', 'UIText', 'Yesno', 'Module:Sandbox/Fewfre', 'Crafting') local rarityAliases = loader.loadData('RarityTier/Aliases') local util_vars = require('Module:VariablesLuaUtil') local aliasesCache = require('Module:Cache').slotAliasesCache

local slot = inventorySlot.slot local parseFrameText = inventorySlot.parseFrameText local formatUIText = uiText._main local curTitle = mw.title.getCurrentTitle

local p = {}

local addSlot = crafting.addSlot

local function backslashSubstitute(s) -- substitute every '\ ' but those that have special meaning for tooltips generation, e.g. '\&' s = s:gsub('\\\\', '\254'):gsub('\\([^&/])', '%1'):gsub('\254', '\\\\') return s end local function backslashSubstituteStrict(s) -- substitute all '\ ' s = s:gsub('\\\\', '\254'):gsub('\\(.)', '%1'):gsub('\254', '\\\\') return s end

-- Crafting table function p.craftingTable( frame ) local args = getArgs(frame) local body = mw.html.create('span'):addClass('mcui mcui-Crafting_Table pixel-image') local recipe = crafting.parseRecipe(args) local grid = crafting._craftingGrid(recipe) body:node(grid) local arrow = body:tag('span'):addClass('mcui-arrow'):tag('br'):done if args.arrow or  ~=  then arrow:css(			'background-image',			''		) end body:tag('span') :addClass('mcui-output') :wikitext(addSlot(recipe, 'Output', 'O', 'invslot-large')) local shapeless = args.shapeless or '' local fixed = args.fixed or '' if shapeless ~=  or fixed ~=  then local icon = body:tag('span') :addClass('mcui-icons') :tag('span') :tag('br') :done if shapeless ~= '' then icon:addClass('mcui-shapeless') :attr('title',					'This recipe is shapeless, the inputs may be placed in any arrangement in the crafting grid.'				) elseif fixed ~= '' then local notFixed = args.notfixed or '' local exceptFixed = '' if notFixed ~= '' then exceptFixed = '; except for ' .. notFixed .. ', which can go anywhere' end icon:addClass('mcui-fixed') :attr('title',					'This recipe is fixed, the input arrangement may not be moved or mirrored in the crafting grid' .. exceptFixed .. '.'				) end end if curTitle.namespace == 0 and (args.A1 or args.A2 or args.A3 or args.B1 or args.B2 or args.B3 or args.C1 or args.C2 or args.C3) then return tostring(mw.html.create('div'):node(body)) .. ''	end return tostring(mw.html.create('div'):node(body)) end

-- Furnace function p.furnace( frame ) local args = getArgs(frame) local body = mw.html.create('span'):addClass('mcui mcui-Furnace pixel-image') local input = body:tag('span'):addClass('mcui-input') input:wikitext(addSlot(args, 'Input', 'I')) local fuel = input:tag('span'):addClass('mcui-fuel'):tag('br'):done local fuelImg = args.FuelUsage or '' local burning = args.Input or  ~=  and args.Fuel or  ~=  if not burning then fuel:addClass('mcui-inactive') if fuelImg ~= '' then fuelImg = fuelImg .. ' (in-active)' end end if fuelImg ~= '' then fuel:css(			'background-image',			''		) end input:wikitext(addSlot(args, 'Fuel', 'F')) local arrow = body:tag('span'):addClass('mcui-arrow'):tag('br'):done local arrowImg = args.Progress or '' if not burning or (args.Output or ) ==  then arrow:addClass('mcui-inactive') if arrowImg ~= '' then arrowImg = arrowImg .. ' (in-active)' end end if arrowImg ~= '' then arrow:css(			'background-image',			''		) end body :tag('span') :addClass('mcui-output') :wikitext(addSlot(args, 'Output', 'O', 'invslot-large')) return tostring(mw.html.create('div'):node(body)) end

-- Brewing Stand function p.brewingStand( frame ) local args = getArgs(frame) local body = mw.html.create('span'):addClass('mcui mcui-Brewing_Stand pixel-image') local input = body:tag('span'):addClass('mcui-input') input:tag('span'):addClass('mcui-bubbling'):tag('br') input:wikitext(addSlot(args, 'Input', 'I')) input:tag('span'):addClass('mcui-arrow'):tag('br') if (args.Input or ) ==  or		((args.Output1 or ) ==  and (args.Output2 or ) ==  and (args.Output3 or ) == ) then input:addClass('mcui-inactive') end body:tag('span'):addClass('mcui-paths'):tag('br') local output = body:tag('span'):addClass('mcui-output') for i = 1, 3 do output:wikitext(addSlot(args, 'Output' .. i, 'O' .. i, 'mcui-output' .. i)) end return tostring(mw.html.create('div'):node(body)) end

-- Melody function p.noteSequence(f) local args = getArgs(f) local sequence = args[1] return p._noteSequence(sequence) end

function p._noteSequence(sequence) local function simpleSlot(frames) frames = parseFrameText(frames, nil, false, {aliases = '', default = nil}) local function simpleMakeItem(name) return mw.html.create('span'):addClass('invslot-item invslot-item-image'):wikitext(''):done end local body = mw.html.create('span'):addClass('invslot animated') local activeFrame = 1 for i, frame in ipairs(frames) do			local item if frame[1] then item = body:tag('span'):addClass('animated-subframe') local subActiveFrame = 1 --FC-frame.randomise and random(#frame) or 1 for sI, sFrame in ipairs(frame) do					local sItem = simpleMakeItem(sFrame.name) item:node(sItem) if sI == subActiveFrame then sItem:addClass('animated-active') else sItem:addClass('hidden') end end else item = simpleMakeItem(frame.name) body:node(item) end if i == activeFrame and animated then item:addClass('animated-active') elseif animated then item:addClass('hidden') end end return mw.getCurrentFrame:preprocess(tostring(body)) end local colors = { "Red", "Yellow", "Lime", "Green", "Purple", "Blue", "Light_Blue" }	local slots = {} for x = 1,7,1 do		slots[x] = {} for y = 1,6,1 do			if y == 5 then slots[x][y] = sequence:gsub('['..x..']', 'Block_of_Quartz;') else slots[x][y] = sequence:gsub('['..x..']', colors[x]..'_Wool;') end if y == 5 then slots[x][y] = slots[x][y]:gsub('[%d%s]', colors[x]..'_Stained_Clay;') else slots[x][y] = slots[x][y]:gsub('[%d%s]', colors[x]..'_Stained_Glass_Pane;') end if y == 5 then for z = 1,y,1 do						slots[x][y] = colors[x]..'_Stained_Clay;'..slots[x][y] end for z = 1,12-y,1 do						slots[x][y] = slots[x][y]..colors[x]..'_Stained_Clay;' end else for z = 1,y,1 do						slots[x][y] = colors[x]..'_Stained_Glass_Pane;'..slots[x][y] end for z = 1,12-y,1 do						slots[x][y] = slots[x][y]..colors[x]..'_Stained_Glass_Pane;' end end slots[x][y] = slots[x][y]:gsub('[_]', ' ') end end local table = mw.html.create('table'):addClass('mcui mcui-Crafting_Table pixel-image'):css({margin='0 auto', display='table', cursor='not-allowed'}) for y = 1,6,1 do		local row = table:tag("tr"):addClass('mcui-row') row:tag("td"):wikitext(simpleSlot('Gray Stained Glass Pane')):done for x = 1,7,1 do			row:tag("td"):wikitext(simpleSlot(slots[x][y])):done end row:tag("td"):wikitext(simpleSlot('Gray Stained Glass Pane')):done row:done end table:done return tostring(table) end

- -- function: createBlankUI(topText: string, id?: string, goBack?: table, hide?: boolean, fill?: boolean, rows?: number, cols?: number) -- -- Creates a new Blank UI. - local function createBlankUI(topText, id, goBack, hide, fill, rows, cols, noarrow, noclose, arrow_, close_) local Methods = {} goBack = goBack or {} rows, cols = tonumber(rows) or 6, tonumber(cols) or 9 fill, noarrow, noclose = yesno(fill, true), yesno(noarrow, false), yesno(noclose, false) local arrowX, arrowY, closeX, closeY -	-- function: createBlankUI:constructor -- 	-- Constructor function for the methods provided. Creates the actual UI. -	function Methods:constructor self.slots = {} self.custom = {} self.wt = mw.html.create('table') :attr{ class="mcui mcui-Crafting_Table pixel-image" } :css{ ['margin'] = '0 auto'; ['display'] = 'table'; }			:tag('tr') :css{ ['position'] = 'absolute'; ['margin-top'] = '-4px'; }				:tag('td') :attr{ colspan=cols, class='text-zoom-independent noselect', ['data-font-size']=14 } :css{ ['font-family'] = 'minecraft'; ['color'] = '#2B2D2F'; ['font-size'] = '14px'; }					:wikitext(backslashSubstituteStrict(topText)) :done :done if arrow_ then if yesno(arrow_) or arrow_:match("[Nn]one") then noarrow = true else if arrow_:match('^%d+%s*,%s*%d+$') then arrowX, arrowY = arrow_:match('^(%d+)%s*,%s*(%d+)$') end end end arrowX = tonumber(arrowX) or rows arrowY = tonumber(arrowY) or 4 if close_ then if yesno(close_) or close_:match("[Nn]one") then noclose = true else if close_:match('^%d+%s*,%s*%d+$') then closeX, closeY = close_:match('^(%d+)%s*,%s*(%d+)$') end end end closeX = tonumber(closeX) or rows closeY = tonumber(closeY) or 5 for x = 1, rows, 1 do			self.slots[x] = {} self.custom[x] = {} for y = 1, cols, 1 do				if not noarrow and x == arrowX and y == arrowY then self:setSlot(x, y, { 						'Go Back', 						text=goBack.text,						link=goBack.link or 'none',						title='&aGo Back',						class=goBack.id and 'goto-'..goBack.id:gsub('^goto%-', ''),					}) elseif not noclose and x == closeX and y == closeY then self:setSlot(x, y, { 'Close' }) else if not fill then self:setEmptySlot(x, y)					else self:setBlankSlot(x, y)					end end end end end -	-- function: createBlankUI:setSlot(x: number, y: number, args: table, isCustom?: boolean) -- 	-- Sets a slot according to the `x` and `y` parameters provided, with the arguments -- to the parser as `args`. -	function Methods:setSlot(x, y, args, isCustom) checkType(1, x, 'number') checkType(2, y, 'number') checkType(3, args, { 'table', 'string' }) local tp = type(args) if tp == 'table' or (tp == 'string' and args:match('.-')) then self.slots[x] = self.slots[x] or {} self.custom[x] = self.custom[x] or {} self.slots[x][y] = args self.custom[x][y] = not not isCustom elseif tp == 'string' then assertTrue(self.slots[x] and self.slots[x][y], 'slot in posistion (%d, %d) does not exist', 2, x, y)[args] = isCustom end return self end -	-- function: createBlankUI:getSlot(x: number, y: number, prop?: string) -- 	-- Gets a slot according to the `x` and `y` parameters provided, with an option parameter -- of `prop` to get a particular slot property. -	function Methods:getSlot(x, y, prop) if prop then return assertTrue(self.slots[x] and self.slots[x][y], 'slot in posistion (%d, %d) does not exist', 2, x, y)[prop] else return self.slots[x][y] end end -	-- function: createBlankUI:hasSlot(x: number, y: number) -- 	-- Checks if the UI has a specific slot based on `x` and `y`. -	function Methods:hasSlot(x, y)		return not not self.slots[x][y] end -	-- function: createBlankUI:isEmptySlot(x: number, y: number) -- 	-- Checks if a slot based on `x` and `y` is not blank. -	function Methods:isEmptySlot(x, y)		return self.slots[x][y] and self.slots[x][y] ~= '' and self.slots[x][y] ~= "Blank" end -	-- function: createBlankUI:setBlankSlot(x: number, y: number) -- 	-- Sets a blank slot according to the `x` and `y` parameters provided. -	function Methods:setBlankSlot(x, y)		return self:setSlot(x, y, { 'Blank' }) end -	-- function: createBlankUI:setEmptySlot(x: number, y: number) -- 	-- Sets a empty slot according to the `x` and `y` parameters provided. -	function Methods:setEmptySlot(x, y)		return self:setSlot(x, y, { "" }) end -	-- function: createBlankUI:__tostring -- 	-- __tostring metamethod for the class. Parses the `slots` to an acual string. -	function Methods:__tostring for x, xValue in ipairs(self.slots) do			local row = self.wt:tag('tr') :addClass('mcui-row') :css{ ['margin-top'] = x == 1 and '24px' or nil }			for y, yValue in ipairs(xValue) do				row:tag('td') :wikitext(backslashSubstitute(self.custom[x][y] and yValue or slot(yValue))) :done end row:done end return id			and tostring(mw.html.create('div')				:node(self.wt)				:attr{ 					id=id and 'ui-'..id:gsub('^ui%-', ''), 					class=id and "sbw-ui-tab-content", 					style=yesno(hide) and "display: none;" or nil,				} 			:done) or tostring(self.wt) end return table.makeClass(Methods) end p.createBlankUI = createBlankUI

- -- Template: Collection UI -- -- Creates a main collection UI for a given item - function p.collectionUI(frame) return p._collectionUI(table.deepCopy(getArgs(frame))) end

- -- _collectionUI Helper functions - local recipeAliases = { ['r'] = 'recipe', ['recipe'] = 'recipe', ['recipes'] = 'recipes', ['rs'] = 'recipes', ['rec'] = 'recipe', ['recs'] = 'recipes', ['recip'] = 'recipe', ['recips'] = 'recipes', ['res'] = 'recipes', ['re'] = 'recipe', ['up'] = 'upgrade', ['upg'] = 'upgrade', ['u'] = 'upgrade', ['upgr'] = 'upgrade', ['upgra'] = 'upgrade', ['upgrad'] = 'upgrade', ['upgrade'] = 'upgrade', }

-- 1/3 local variateStart = { -- { regex to match, subst } { '[Ee]xperience', '&8+' }, } -- 2/3 local function specialCaseColors(s) local matches = { ['[Mm]inion'] = 'blue', -- ['Enchanted Book'] = 'blue', ['[Uu]pgrade'] = 'green', ['[Cc]oming [Ss]oon'] = 'red', }

for k, v in pairs(matches) do		if s:match(k) then return uiText.getColorCode(v) end end if tonumber(s) then return uiText.getColorCode('dark_aqua') end end -- 3/3 local variateEnd = { -- { regex to match, subst } { {'[Nn]one', '[Uu]pgrade'}, '' }, { '[Cc][Oo][Mm][Ii][Nn][Gg] [Ss][Oo][Oo][Nn]', ' &8(&4COMING SOON&8)' }, { '[Dd]warven [Ff]orge [Rr]ecipe', ' &6Dwarven Forge Recipe' }, { '[Mm]inion', ' &rRecipes' } }

local function getStartEnd(_type, expressions) for _,v in ipairs(expressions) do		for _,_exp in ipairs(type(v[1]) == 'table' and v[1] or {v[1]}) do			if not not _type:match(_exp) then return v[2] end end end end

local function injectParamsBoolean(callStr, args) for param, value in pairs(args) do		if value then value = tostring(yesno(value)) callStr, n = callStr:gsub("|%s*"..param.."%s*=.-%f[|}]","|"..param.."="..value.."\n") if n == 0 then callStr = callStr:sub(0,callStr:len-2) .. "|"..param.."="..value.."}}" end end end return callStr end

local function injectParamsString(callStr, args) for param, value in pairs(args) do		if value then callStr, n = callStr:gsub("|%s*"..param.."%s*=.-%f[|}]","|"..param.."="..value.."\n") if n == 0 then callStr = callStr:sub(0,callStr:len-2) .. "|"..param.."="..value.."}}" end end end return callStr end

local function parseCollectionData(ui, rewards, collection) local rows = 1 local firstRowPositions = { { {5, 3} },		{ {4, 3}, {6, 3} },		{ {4, 3}, {5, 3}, {6, 3} },		{ {3, 3}, {4, 3}, {6, 3}, {7, 3} },		{ {3, 3}, {4, 3}, {5, 3}, {6, 3}, {7, 3} },		{ {2, 3}, {3, 3}, {4, 3}, {6, 3}, {7, 3}, {8, 3} },		{ {2, 3}, {3, 3}, {4, 3}, {5, 3}, {6, 3}, {7, 3}, {8, 3} },		{ {1, 3}, {2, 3}, {3, 3}, {4, 3}, {6, 3}, {7, 3}, {8, 3}, {9, 3} },	}	local total = #rewards for i, v in ipairs(rewards) do		local x		local y		if i > 21 then break; end

if total <= 8 then local pos = firstRowPositions[total][i] x, y = pos[2], pos[1] else x = 2+rows y = i%9 y = y == 0 and 9 or y		end if i%9 == 0 and i > 0 then rows = rows+1 end ui:setSlot(x, y, {			i == 1 and "Yellow Stained Glass Pane,"..i or 'Red Stained Glass Pane,'..i,			link = 'none',			title = table.concat{ i == 1 and '&e' or '&c', collection, ' ', string._toRoman(i) },			class = v._goto and 'goto-'..v._goto,			text = formatUIText(string.dedent			&7Progress: &e0&6%%			&f%s &e0&6/&e%s&7			%s:			%s			&eClick to view rewards!			):format( ('-'):rep(20), string._formatShortNum(string._toNumber(v.amount)), #v > 1 and '&7Rewards' or '&7Reward', table.concat(table.map(v, function(val) local s = val[1] local start_ = val.type and getStartEnd(val.type, variateStart) local end_ = val.type and getStartEnd(val.type, variateEnd) return table.concat{ start_ or '', -- 1/3 val.rarity..s, -- 2/3 end_ or ' &r'..(val.type or '&rRecipe'), -- 3/3 }				end), '/') )		})	end end

local function parseTextList(s) local rewards = {} local count = 0 for i, v in ipairs(string.split((s:gsub('\\,', '\255')), '\n')) do		local _type v = string.methods(v):_trim if v:getValue ~= '' then if v:charAt(1) == "*" then if v:charAt(2) == "*" then _type = 'item' else _type = 'amount' end end if _type == 'amount' then local amount, _goto = unpack(string.split(v:sub(2), "%s*,%s*")) count = count+1 rewards[count] = {} rewards[count].amount = amount rewards[count]._goto = _goto and _goto:gsub('^goto%-', '') elseif _type == 'item' then local item, type, rarity = unpack(string.split(v:sub(3), '%s*,%s*')) item = item or v:sub(3) rarity = (rarity and rarity ~= "") and uiText.getFormatting(rarity) local tooltip = aliasesCache:get(item) local tooltipRarity = tooltip and tooltip.title and tooltip.title:match('^&([a-z0-9])') table.push(rewards[count], { 					item, 					rarity = '&'..(rarity or tooltipRarity or specialCaseColors(item) or 'f'),					type=(type and type ~= "") and string.ucfirst(recipeAliases[type:lower] or type)				}) end end end return rewards end - -- function: _collectionUI(args: table|frame) -- -- Invoked by. - function p._collectionUI(args) checkType(1, args, { 'table' }) assertTrue(args[1], 'No collection specified', 2) assertTrue(args[2], 'No collection rewards specified', 2) local slots = {} local collection = args[1] and args[1]:gsub('[Ee][Nn][Cc][Hh][Aa]?[Nn]?[Tt]?[Ee]?[Dd]? ?', ):gsub('[Bb][Ll][Oo][Cc][Kk] ?[Oo]?[Ff]? ?', ) local title = mw.title.getCurrentTitle local ui = createBlankUI(collection and collection..' Collection' or title.rootText, args['id'], { 		text=(args['return_text'] or args['goback']),		link=(args['return_text'] or args['goback']) and (args['return_text'] or args['goback']):gsub('%s*[Cc]ollection', ''),		id=args['return_id'],	}, args['hide']) ui:setSlot(1, 5, {		args.title or collection,		link='none', 		title='&e'..collection..' Collection',		text=formatUIText(string.dedent		&7View all your %s Collection 		&7progress and rewards!		&7Total Collected: &e0		:format(collection))	}) ui:setSlot(6, 4, 'link', '') parseCollectionData(ui, parseTextList(args[2]), collection) -- pipeline(ui, table.dump, 0, error) return (tostring(ui):gsub('\255', ',')) end

- -- Template: Collection Rewards UI -- -- Creates a collection Rewards UI. - function p.collectionRewardsUI(frame) local args = getArgs(frame) return p._collectionRewardsUI(table.deepCopy(args)) end - -- function: _collectionRewardsUI(args) -- -- Invoked by - function p._collectionRewardsUI(args) checkType(1, args, { 'table' }) local collection = args[1] and args[1]:gsub('[Ee][Nn][Cc][Hh][Aa]?[Nn]?[Tt]?[Ee]?[Dd]? ?', ):gsub('[Bb][Ll][Oo][Cc][Kk] ?[Oo]?[Ff]? ?', ) local ui = createBlankUI(collection..' '..string._toRoman(args[2] or 1)..' Rewards', args['id'], {		text=collection..' Collection',		link=args['return_text'] and args['return_text']:gsub('%s*[Cc]ollection', ''),		id=args['return_id'],	}, args['hide']) local rewards = {} local items = table.filter(string.split(args[3], '\n'), function(v)		return string.trim(v) ~= ''	end) local amount = #items local posistions = { -- X/Y posistion entries for slot amounts 1-9 { {3, 5} },		{ {3, 4}, {3, 6} },		{ {3, 3}, {3, 5}, {3, 7} },		{ {3, 2}, {3, 4}, {3, 6}, {3, 8} },		{ 			{2, 2}, {2, 4}, {2, 6}, {2, 8},			{4, 5},		},		{ 			{2, 2}, {2, 4}, {2, 6}, {2, 8},			{5, 4}, {5, 6},		},		{ 			{2, 2}, {2, 4}, {2, 6}, {2, 8},			{3, 3}, {3, 5}, {3, 7},		},		{ 			{2, 2}, {2, 4}, {2, 6}, {2, 8},			{4, 2}, {4, 4}, {4, 6}, {4, 8},		},		{ 			{2, 4}, {2, 5}, {2, 6},			{3, 4}, {3, 5}, {3, 6},			{4, 4}, {4, 5}, {4, 6},		},		{ 			{2, 4}, {2, 5}, {2, 6}, {2, 7},			{3, 4}, {3, 5}, {3, 6},			{4, 4}, {4, 5}, {4, 6},		},		{ 			{2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7},			{3, 4}, {3, 5}, {3, 6},			{4, 4}, {4, 5}, {4, 6},		},	}	for i, line in ipairs(items) do		local item, id, title, desc = pipeline(line, string.trim, 2, string.sub, '%s*,%s*', string.unpackedSplit) local tooltip = aliasesCache:get(item) local itemText = desc or (tooltip and tooltip.text) local itemTitle = title or (tooltip and tooltip.title) local function addItem(x, y)			ui:setSlot(x, y, {				item, text=itemText and itemText..'//&eClick to view recipe!', 				title=itemTitle, class= id and 'goto-'..id:gsub('^goto%-', ),				link= id and 'none' or 			}) end addItem(unpack(posistions[amount][i])) end return tostring(ui) end

- -- Template: UIPage -- -- Imports (transclude) another UI page with custom options on its first UI. - function p.uipage(frame) local args = getArgs(frame) local page = args['page'] or args[1]

return frame:preprocess(p._uipage(page, args)) end

function p._uipage(page, args) local return_id = args['return_id'] local extPageTitle = mw.title.new(page, 0)

if not extPageTitle.exists then error('Specified page does not exist, page: '..page) end local extPageContent = extPageTitle:getContent local ls = string.matchAll(extPageContent,"%b{}") local finalStr = "" local firstUI = true if ls.n < 1 then return "" end for i = 1, ls.n, 1 do		local callStr = ls[i][1] local x, y = callStr:find("{{UI|") local x1, y1, subpage, subparams = callStr:find("{{UIPage|(.-)%f[|}](.-)}}") if x == 1 then if firstUI then -- first UI on page, apply all the custom settings to this UI				callStr = injectParamsBoolean(callStr, {hide=yesno(args['hide'],true), fill=args['fill'], 					rows=args['rows'], cols=args['cols'], 					noarrow=args['noarrow'], noclose=args['noclose']}) callStr = injectParamsString(callStr, {id=args['id'], goback=(args['return_text'] or args['goback']),					goback_link=args['goback_link'], return_id=args['return_id'], arrow=(args['arrow'] or args['arrow_']), close_=(args['close'] or args['close_'])}) firstUI = false end finalStr = finalStr .. callStr elseif x1 == 1 then subparams = subparams and subparams:gsub('^[|%s]*(.-)[|%s]*$','%1') or '' local subargs = {} for _, param in ipairs(string.split(subparams,'|')) do				if param:match('=') then param = string.split(param, '=') subargs[param[1]] = param[2] else -- no positional arguments for UIPage at the moment end end finalStr = finalStr .. p._uipage(subpage, subargs) end end return finalStr end

- -- Template: UI -- -- Creates a UI. - function p.ui(frame) local args = getArgs(frame, { removeBlanks=false })

local ui = createBlankUI(args[1], args['id'], {		text=(args['return_text'] or args['goback_text'] or args['return'] or args['goback']),		link=(args['return_link'] or args['goback_link']),		id=(args['return_id'] or args['goback_id']),	}, yesno(args['hide'], false), args['fill'], args['rows'], args['cols'], args['noarrow'], args['noclose'], (args['arrow'] or args['arrow_']), (args['close'] or args['close_'])) local x, y, rowCount = 1, 1, 1 local maxRows, maxCols = tonumber(args['rows']) or 6, tonumber(args['cols']) or 9 local fill = yesno(args['fill'], true) local defaultnolink = yesno((args['defaultnolink'] or args['dnl']), false) local function decodeCommas(...) local t = { ... }		for i, v in ipairs(t) do			t[i] = t[i]:gsub('\255', ',') end return unpack(t) end

local function setSlot(v, x, y)		local isCustom = v:match('<%a-(.-)>(.-)') v = v:gsub('\\,', '\255') local val, id, title, text = decodeCommas(string.unpackedSplit(v, '%s*,%s*')) local _val = val local val, num = val:match('^%s*(.+)%s*[;]%s*(%d+)%s*$') val = val or _val local link_specify if not id or id == "" then id = nil else local _id = id			id, link_specify = id:match('^%s*(.+)%s*[;]%s*(.+)%s*$') id = id or _id end -- [IMPORTANT] Transform newlines into `/` if text and text:match("\n") then text = text:gsub("\n", "/") end ui:setSlot(x, y, isCustom and v or {			val..(num and ', '..num or ),			class = (id and id ~= 'none') and 'goto-'..id:gsub('^goto%-', ),			link = (id and id ~= 'none') and 'none' or (link_specify or (defaultnolink and 'none' or'')),			title = title,			text = text,		}, isCustom) end for i, v in ipairs(args) do		if i > 1 then if x > 6 then break; end if v:match('^%-$') then for y2 = y, maxCols do					if fill then ui:setBlankSlot(x, y2) else ui:setSlot(x, y2, '') end end x = x+1 y = 1 elseif y > maxCols then y = 1 x = x+1 else setSlot(v, x, y)				y = y+1 end end end for k, v in pairs(args) do		local k = tostring(k) if k:match('^%d+%s*,%s*%d+$') then local x, y = k:match('^(%d+)%s*,%s*(%d+)$') setSlot(v, tonumber(x), tonumber(y)) elseif k:match('^row%s*([1-6])%s*$') then local x = k:match('^row%s*([1-6])$') local endParams = v:match('%s*;%s*([%d%s,]-)%s*$') v = v:gsub('%s*;%s*([%d%s,]-)%s*$', '') endParams = endParams and string.split(endParams, '%s*,%s*') or {1, maxCols} if #endParams > 2 then for dummy, y in pairs(endParams) do					setSlot(v:gsub('%$n', y):gsub('\\%$n', '$n'), tonumber(x), tonumber(y)) end else for y = tonumber(endParams[1] or 1), tonumber(endParams[2] or maxCols), 1 do					setSlot(v:gsub('%$n', y):gsub('\\%$n', '$n'), tonumber(x), tonumber(y)) end end elseif k:match('^colu?m?n?%s*([1-9])%s*$') then local y = k:match('^colu?m?n?%s*([1-9])%s*$') local endParams = v:match('%s*;%s*([%d%s,]-)%s*$') v = v:gsub('%s*;%s*([%d%s,]-)%s*$', '') endParams = endParams and string.split(endParams, '%s*,%s*') or {1, maxRows} if #endParams > 2 then for dummy, x in pairs(endParams) do					setSlot(v:gsub('%$n', x):gsub('\\%$n', '$n'), tonumber(x), tonumber(y)) end else for x = tonumber(endParams[1] or 1), tonumber(endParams[2] or maxRows), 1 do					setSlot(v:gsub('%$n', x):gsub('\\%$n', '$n'), tonumber(x), tonumber(y)) end end end end return tostring(ui) end p.slot = slot

function p.forgingTable( frame ) local args = getArgs(frame) local body = mw.html.create('span'):addClass('mcui mcui-Forging_Table pixel-image') -- CUSTOM: changing grid to use " -- 	} -- end

-- local customLibUtil = require('Module:LibraryUtil') -- local libraryUtil = require( 'libraryUtil' )

-- local COUNT = 500000 -- function testPerformance(name, func) -- 	mw.log("TEST: "..name) -- 	local start = os.clock -- 	func -- 	mw.log(" done - "..(os.clock - start)) -- end

-- function checkTypeSingle(name, argIdx, arg, allowedType, nilOk) -- 	local argType = type(arg) --  if argType == allowedType or (nilOk and arg == nil) then --    return arg --  end --  -- else invalid --  ({ checkType=error }).checkType(string.format("bad argument #%d to '%s' (%s expected, got %s)", argIdx, name, expectTypes, argType), 3) -- end

-- function checkTypeListOnly(name, argIdx, arg, allowedList) -- 	local argType = type(arg) --  for i=1, #allowedList do --     if allowedList[i] == argType then --      return arg --    end --  end

--  ({ checkType=error }).checkType(string.format("bad argument #%d to '%s' (%s expected, got %s)", argIdx, name, table.concat(expectTypes, '/'), argType), 3) -- end

-- -- local p = {}

-- function p.test -- 	testPerformance("checkTypeLight-single", function -- 		local arg = {"foo"} -- 		for i=COUNT,1,-1 do -- 			checkTypeLight("foo", 1, arg, "table", true) -- 		end -- 	end) -- 	testPerformance("libraryUtil.checkType", function -- 		local arg = {"foo"} -- 		for i=COUNT,1,-1 do -- 			libraryUtil.checkType("foo", 1, arg, "table", true) -- 		end -- 	end)

-- 	testPerformance("checkTypeSingle", function -- 		local arg = {"foo"} -- 		for i=COUNT,1,-1 do -- 			checkTypeSingle("foo", 1, arg, "table", true) -- 		end -- 	end) -- 	testPerformance("checkTypeLight-multi", function -- 		local arg = {"foo"} -- 		for i=COUNT,1,-1 do -- 			checkTypeLight("foo", 1, arg, { "string", "table", 'nil' }) -- 		end -- 	end) -- 	testPerformance("libraryUtil.checkTypeMulti", function -- 		local arg = {"foo"} -- 		for i=COUNT,1,-1 do -- 			libraryUtil.checkTypeMulti("foo", 1, arg, { "string", "table", 'nil' }) -- 		end -- 	end)

-- 	testPerformance("checkTypeListOnly", function -- 		local arg = {"foo"} -- 		for i=COUNT,1,-1 do -- 			checkTypeListOnly("foo", 1, arg, { "string", "table", 'nil' }) -- 		end -- 	end) -- end

-- function p.loadDataTest -- 	local COUNT = 500000 -- 	testPerformance("manual-cache", function -- 		local data = nil -- 		for i=COUNT,1,-1 do -- 			if not data then -- 				data = mw.loadData('Module:Item/ApiAliases') -- 			end -- 		end -- 	end) -- 	testPerformance("default-cache", function -- 		local data = nil -- 		for i=COUNT,1,-1 do -- 			data = mw.loadData('Module:Item/ApiAliases') -- 		end -- 	end) -- end

-- local foo1 = nil -- function p.frameMemoryTest -- 	foo1 = foo1 or 1 -- 	foo2 = foo2 or 1 -- foo2 not local, so remembored globally -- 	foo1 = foo1+1 -- 	foo2 = foo2+1 -- 	return foo1.."-"..foo2 -- end

-- return p