Module:Location/Components/GameTabsTable
Appearance
This documentation is transcluded from Module:Location/Components/GameTabsTable/doc.
Implements Template:GameTabsLocations.
require( 'strict' )
local locationTable = require( 'Module:Location/Components/Table' )
local gameTabs = require( 'Module:GameTabs' )
local games = require( 'Module:GameData' ).getGames()
local p = {}
--- Process wikitext args and group them by game.
---
--- @param args table
--- @return table
local function processArgs( args )
local data = {}
for _, game in ipairs( games ) do
local gameId = game.id
local locations = {}
for i = 1, locationTable.MAX_WIKITEXT_LOCATIONS do
local name = args[gameId .. '_name' .. i]
local link = args[gameId .. '_link' .. i]
local rate = args[gameId .. '_rate' .. i]
local note = args[gameId .. '_note' .. i]
if name then
table.insert( locations, {
name = name,
link = link,
rate = rate,
note = note
} )
end
end
if #locations > 0 then
data[gameId] = locations
end
end
return data
end
--- Get the wikitext for a game tab.
---
--- @param gameData table
--- @return string
local function getGameTabWikitext( gameData )
local html = mw.html.create( 'div' )
html:addClass( 't-tabbedCard-table-container' )
:wikitext( locationTable._main( gameData ) )
return tostring( html )
end
--- Wikitext entry point for the module.
---
--- @param frame mw.frame
--- @return string
function p.main( frame )
local getArgs = require( 'Module:Arguments' ).getArgs
return p._main( processArgs( getArgs( frame ) ) )
end
--- Lua entry point for the module.
---
--- @param data table
--- @return string
function p._main( data )
local gameTabsArgs = gameTabs.mapGameArgs( data, function ( locationsData, game )
return getGameTabWikitext( locationsData )
end )
gameTabsArgs.noPadding = true
return gameTabs._main( gameTabsArgs )
end
return p