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

From Modded Wiki
Jump to navigation Jump to search
Combine Any/Matching alias rows
Fix module
Line 1: Line 1:
local p = {}
local p = {}
p.table = function()
p.table = function()
local slot = require( [[Module:Inventory slot]] ).slot
local slot = require( [[Module:Inventory slot]] )
local aliases = mw.loadData( [[Module:Inventory slot/Aliases]] )
local aliases = mw.loadData( [[Module:Inventory slot/Aliases]] )
local keys = {}
local aliasNames = {}
for i in pairs( aliases ) do
local aI = 1
for name in pairs( aliases ) do
-- 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 i == 'Any Banner' or not i:find( ' Banner$' ) and not i:find( '^Matching ' ) then
if name == 'Any Banner' or not name:find( ' Banner$' ) and not name:find( '^Matching ' ) then
table.insert( keys, i )
aliasNames[aI] = name
aI = aI + 1
end
end
end
end
table.sort( keys )
table.sort( aliasNames )
local tableRows = {
local tableRows = {
' {| class="wikitable collapsible collapsed"',
' {| class="wikitable collapsible collapsed"',
'! Alias !! class="collapse-button" | Output'
'! Alias !! Output'
}
}
for _, key in ipairs( keys ) do
local rI = #tableRows
local alias = aliases[key]
for _, name in ipairs( aliasNames ) do
local alias = slot.getAlias( aliases[name], {} )
local displayCell = {}
local cell = {}
for name in mw.text.gsplit( alias, '%s*;%s*' ) do
for i, frame in ipairs( alias ) do
-- Aliases are disabled in output for accuracy
cell[i] = slot.slot{ { frame }, parsed = true }
-- (as sub-aliases aren't meant to work) and performance
table.insert( displayCell, slot{ name, noalias = true } )
end
end
local aliasText = mw.html.create()
local aliasText = mw.html.create()
aliasText:tag( 'code' ):wikitext( key )
aliasText:tag( 'code' ):wikitext( name )
if key:find( '^Any ' ) then
if name:find( '^Any ' ) then
aliasText:tag( 'br' ):done()
aliasText:tag( 'br' ):done()
:tag( 'code' ):wikitext( ( key:gsub( '^Any', 'Matching' ) ) )
:tag( 'code' ):wikitext( ( name:gsub( '^Any', 'Matching' ) ) )
end
end
table.insert( tableRows, '|' .. tostring( aliasText ) .. '||' .. table.concat( displayCell ) )
tableRows[rI] = '|' .. tostring( aliasText ) .. '||' .. table.concat( cell )
rI = rI + 1
end
end
table.insert( tableRows, '|}' )
tableRows[rI] = '|}'
return table.concat( tableRows, '\n|-\n' )
return table.concat( tableRows, '\n|-\n' )
end
end
return p
return p

Revision as of 10:55, 6 December 2016

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 ' ) then
			aliasNames[aI] = name
			aI = aI + 1
		end
	end
	table.sort( aliasNames )
	
	local tableRows = {
		' {| class="wikitable collapsible collapsed"',
		'! Alias !! Output'
	}
	local rI = #tableRows
	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
			aliasText:tag( 'br' ):done()
				:tag( 'code' ):wikitext( ( name:gsub( '^Any', 'Matching' ) ) )
		end
		
		tableRows[rI] = '|' .. tostring( aliasText ) .. '||' .. table.concat( cell )
		rI = rI + 1
	end
	tableRows[rI] = '|}'
	
	return table.concat( tableRows, '\n|-\n' )
end
return p