Jump to content

Module:GameTabs

From Creopedia

This documentation is transcluded from Module:GameTabs/doc.

Implements Template:GameTabs.

Supported games are defined at Module:GameData.


require( 'strict' )

local tabbedCard = require( 'Module:TabbedCard' )
local games = require( 'Module:GameData' ).getGames()

local p = {}

--- Get the games data
---
--- @return table
function p.getGames()
	return games
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( getArgs( frame ) )
end

--- Lua entry point for the module
---
--- @param args table
--- @return string
function p._main( args )
	local tabbedCardData = {
		noPadding = args.noPadding,
		tabber = {}
	}

	local frame = mw.getCurrentFrame()

	for _, game in ipairs( games ) do
		if args[ game.id ] then
			table.insert( tabbedCardData.tabber, {
				label = game.name,
				content = frame:preprocess( args[ game.id ] )
			} )
		end
	end

	return tabbedCard._main( tabbedCardData )
end

--- Iterate over game-specific arguments and apply a mapper function
---
--- @param args table The arguments table
--- @param mapper function A function that takes the argument value and the game object
--- @return table
function p.mapGameArgs( args, mapper )
	local result = {}
	for _, game in ipairs( games ) do
		if args[game.id] then
			result[game.id] = mapper( args[game.id], game )
		end
	end
	return result
end

return p