Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Please sign up or log in to edit the wiki.

Module:Transit

From the Star Citizen Wiki, the fidelity™ encyclopedia
Revision as of 22:50, 17 October 2024 by Alistair3149 (talk | contribs)
Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Transit/doc. Changes can be proposed in the talk page.
Function list
L 13 — t
L 22 — Transit.fromTemplate

Used to show transit line in Star Citizen universe as a badge. The colors are defined in the data.json.


local Transit = {}

local i18n = require( 'Module:i18n' ):new()
local data = mw.loadJsonData( 'Module:Transit/data.json' )

local mArguments


--- Wrapper function for Module:i18n.translate
---
--- @param key string The translation key
--- @return string|nil
local function t( key )
	return i18n:translate( key )
end


--- Helper function for templates invoking the module
---
--- @param frame table
--- @return string
function Transit.fromTemplate( location, name )
    mArguments = require( 'Module:Arguments' )
    local args = mArguments.getArgs( frame )
    local location = args[1]
    local name = args[2]

    if not location and not name then
        return mw.ustring.format( '<span class="error">%s</span>', t( 'message_error_no_text' ) )
    end

    local bg = '#000'
    local color = '#fff'
    for locationName, locationData in pairs( data.locations ) do
        if locationName == location then
            mw.logObject( locationData )
            for lineName, lineData in pairs( locationData.lines ) do
            	if lineName == name then
            		bg = lineData.bg
            		color = lineData.color
            		break
            	end
            end
            break
        end
    end

    return frame:expandTemplate{
        title = 'Badge',
        args = {
            name,
            bg = bg,
            color = color
        }
    }
end


return Transit