Module:Inventory slot/Aliases/Table: Difference between revisions

From Modded Wiki
Jump to navigation Jump to search
No edit summary
m 11 revisions imported
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
local slot = require( [[Module:Inventory slot]] )
local slot = require( [[Module:Inventory slot]] )
local aliases = mw.loadData( [[Module:Inventory slot/Aliases]] )
local aliases = mw.loadData( [[Module:Inventory slot/Aliases]] )
 
local aliasNames = {}
local aliasNames = {}
local aI = 1
local aI = 1
Line 9: Line 9:
-- Skip the banner aliases (except "Any Banner"), as there are so
-- Skip the banner aliases (except "Any Banner"), as there are so
-- many of them it causes the table to be excessively long
-- 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 ' ) then
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
aliasNames[aI] = name
aI = aI + 1
aI = aI + 1
Line 15: Line 20:
end
end
table.sort( aliasNames )
table.sort( aliasNames )
 
local tableRows = {
local tableRows = {
' {| class="wikitable collapsible collapsed"',
' {| class="wikitable collapsible collapsed"',
Line 23: Line 28:
for _, name in ipairs( aliasNames ) do
for _, name in ipairs( aliasNames ) do
local alias = slot.getAlias( aliases[name], {} )
local alias = slot.getAlias( aliases[name], {} )
 
local cell = {}
local cell = {}
for i, frame in ipairs( alias ) do
for i, frame in ipairs( alias ) do
cell[i] = slot.slot{ { frame }, parsed = true }
cell[i] = slot.slot{ { frame }, parsed = true }
end
end
 
local aliasText = mw.html.create()
local aliasText = mw.html.create()
aliasText:tag( 'code' ):wikitext( name )
aliasText:tag( 'code' ):wikitext( name )
if name:find( '^Any ' ) then
if name:find( '^Any ' ) then
aliasText:tag( 'br' ):done()
local altName = name:gsub( '^Any', 'Matching' )
:tag( 'code' ):wikitext( ( name:gsub( '^Any', 'Matching' ) ) )
if aliases[altName] then
aliasText:tag( 'br' ):done()
:tag( 'code' ):wikitext( altName )
end
end
end
 
tableRows[rI] = '|' .. tostring( aliasText ) .. '||' .. table.concat( cell )
tableRows[rI] = '|' .. tostring( aliasText ) .. '||' .. table.concat( cell )
rI = rI + 1
rI = rI + 1
end
end
tableRows[rI] = '|}'
tableRows[rI] = '|}'
 
return table.concat( tableRows, '\n|-\n' )
return table.concat( tableRows, '\n|-\n' )
end
end
return p
return p

Latest revision as of 08:10, 4 July 2024

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