Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Inventory slot/Aliases/Table

From Mine in Abyss
Revision as of 03:36, 6 November 2023 by minecraft>Unavailablehoax (There are a few Any X aliases without an Matching alias which get erroneously paired with a non-existent Matching X aliases, and crucially a few Matching aliases without an Any alias, which means they never get displayed. This edit fixes that)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Inventory slot/Aliases/Table/doc

local p = {}
p.table = function()
	local slot = require( [[Module:Inventory slot]] )
	local aliases = mw.loadData( [[Module:Inventory slot/Aliases]] )

	local aliasNames = {}
	local aI = 1
	for name in pairs( aliases ) do
		-- Skip the banner aliases (except "Any Banner"), as there are so
		-- many of them it causes the table to be excessively long
		if
			name == 'Any Banner' or
			not name:find( ' Banner$' ) and
			not name:find( '^Matching ' ) or
			not aliases[name:gsub( '^Matching', 'Any' )]
		then
			aliasNames[aI] = name
			aI = aI + 1
		end
	end
	table.sort( aliasNames )

	local tableRows = {
		' {| class="wikitable collapsible collapsed"',
		'! Alias !! Output'
	}
	local rI = #tableRows + 1
	for _, name in ipairs( aliasNames ) do
		local alias = slot.getAlias( aliases[name], {} )

		local cell = {}
		for i, frame in ipairs( alias ) do
			cell[i] = slot.slot{ { frame }, parsed = true }
		end

		local aliasText = mw.html.create()
		aliasText:tag( 'code' ):wikitext( name )
		if name:find( '^Any ' ) then
			local altName = name:gsub( '^Any', 'Matching' )
			if aliases[altName] then
				aliasText:tag( 'br' ):done()
					:tag( 'code' ):wikitext( altName )
			end
		end

		tableRows[rI] = '|' .. tostring( aliasText ) .. '||' .. table.concat( cell )
		rI = rI + 1
	end
	tableRows[rI] = '|}'

	return table.concat( tableRows, '\n|-\n' )
end
return p