Module:Sandbox/MonkeysHK/5

-- Initially taken from: https://hypixel-skyblock.fandom.com/wiki/Module:UI/Core

local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local invslot = require('Module:Inventory slot')

local p = {}

local backslashSubstitute = function(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 backslashSubstituteStrict = function (s) -- substitute all '\ ' s = s:gsub('\\\\', '\254'):gsub('\\(.)', '%1'):gsub('\254', '\\\\') return s end local makeGotoClass = function (id) return (id and id ~= 'none') and 'goto-' .. id:gsub('^goto%-', '') end local function defaultSlot(x, y, rows, cols, fillMode) if fillMode == 'border' then if x == 1 or x == rows or y == 1 or y == cols then return 'Blank' else return '' end elseif fillMode == 'filled' then return 'Blank' else return '' end end local function setSlot(row, info) local tp = type(info) if tp == 'string' and info:match('.-') then row:tag('td'):wikitext(info) elseif tp == 'table' then row:tag('td'):wikitext(invslot.slot( tp )) elseif tp == 'string' then row:tag('td'):wikitext(invslot.slot{ tp }) end end - -- p.interface - function p.interface(frame) local args = getArgs(frame) return p._interface(args) end function p._interface(args) local rows, cols = math.min(tonumber(args.rows) or 6, 26), math.min(tonumber(args.cols) or 9, 26) -- local randomColor = colorData.MCColors[random.number{16}] -- for april fools only local wt = mw.html.create('table') :attr{ class='mcui mcui-Chest pixel-image' .. (args.inline and '' or ' mcui-centered') } if args.header then wt:tag('tr'):attr{ class = 'mcui-header noselect' } :tag('td'):wikitext(backslashSubstituteStrict(args.header)) end for x = 1, rows, 1 do		local row = wt:tag('tr'):addClass('mcui-row') for y = 1, cols, 1 do local slot = args[string.char(64 + x) .. y] or defaultSlot(x, y, rows, cols, args.fill_mode) setSlot(row, yValue) end end return args.id		and tostring(mw.html.create('div')			:node(wt)			:attr{ 				id = 'ui-' .. args.id, 				class = 'mcui-tab-content', 				style = yesno(args.hide) and 'display: none;' or nil,			}		:done) or tostring(wt) end

return p