Wir laden dich herzlich auf den Star Citizen Wiki Discord Server ein! Du kannst uns auch auf unserem neuen YouTube-Chanel finden!

Modul:Galactapedia

From Star Citizen Wiki

Modulabhängigkeiten

Modulinfo

Dieses Modul setzt die Vorlage:Galactapedia um. Anweisungen zur Verwendung findest du auf der Vorlagenseite.


local Galactapedia = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable

local objectData = mw.loadData( 'Module:Galactapedia/Data' )

-- Needed Extensions
local common = require( 'Module:Common' )
local localized = require( 'Module:Localized' )
local TNT = require( 'Module:TNT' )

--- Creates the main title
--- @return string
function methodtable.getTitle( self )
    local title = ''

    --[[    if self.args[ 'title' ] ~= nil then
            title = self.args[ 'title' ]
        else
            title = mw.title.getCurrentTitle().subpageText
        end]]

    -- Return the title text for now
    return localized.getMainTitle()
end


--- Entrypoint for {{#seo:}}
--- @return void
function methodtable.setSeoData( self )
    -- Call to {{#seo:}}
    require( 'Module:SEO' ).set(
        'Galactapedia',
        localized.getMainTitle(),
        table.concat({
            localized.getMainTitle(),
            'Galactapedia',
            self.frame:preprocess( '{{SITENAME}}' )
        }, ' - '),
        'replace',
        {
            'Galactapedia',
            'Star Citizen',
            'CIG',
            'Star Citizen Lore',
            'Squadron 42'
        },
        nil,
        self.args[ 'image' ],
        localized.getMainTitle()
    )
end

--- Sets the frame and extracts the args
--- @param frame table
function methodtable.setFrame( self, frame )
    self.frame = frame
    self.args = require( 'Module:Arguments' ).getArgs( frame )
end

--- Get the infobox for the current article
function methodtable.getInfobox( self )
    local tableData = {}

    local box = require( 'Module:Infobox' ).create( {
        bodyClass = 'floatright',
    } )

	local png, _ = mw.ustring.gsub( self.args[ 'image' ], '.jpg', '.png' )
    box:addImage( common.getImage( {
        self.args[ 'image' ],
        png
    } ), {
        [ 'rowClass' ] = 'table-image',
    } )

    box:addTitle( self:getTitle() )

    for _, key in ipairs( objectData.propertyOrder ) do
        if self.args[ key ] ~= nil then
            local data = {
                key = key,
                value = self.args[ key ]
            }

			local added = 0
            for _, value in pairs( common.extractDataFromPrefix( key, self.args ) ) do
            	local setValue
                if objectData.propertyContent[ value ] ~= nil then
                    setValue = objectData.propertyContent[ value ]
                else
                    setValue = value
                end

                added = added + 1
                
                if added == 1 then
                	data.value = setValue
                elseif added == 2 then
        			data.value = {
        				data.value,
        				setValue,
        			}
                elseif added > 2 then
					table.insert( data.value, setValue )
				end
            end

            table.insert( tableData, data )

            self.args[ key ] = nil
        end
    end

    for _, data in ipairs( tableData ) do
        local key = data.key
        local value = data.value
        if type( value ) ~= 'table' then
        	value = { value }
    	end

        if objectData.smwMapData[ key ] ~= nil then
            if key == 'dateS' then
                self.smwData[ objectData.smwMapData[ key ] ] = mw.text.split( table.concat( value ), '-', true )
            else
                self.smwData[ objectData.smwMapData[ key ] ] = value
            end
        end

        local rowData = table.concat( value, '<br>' )
        rowData = mw.text.split( rowData, ', ', true )

		local success, translation = pcall( TNT.format, 'I18n/Module:Galactapedia', key )
		if not success then
			translation = mw.getContentLanguage():ucfirst( key )
		end

        box:addRow( translation, table.concat( rowData, '<br>' ), nil, 'col2' )
    end

	if not mw.title.getCurrentTitle().isSubpage then
    	mw.smw.set( self.smwData )
    end

    if self.args.related ~= nil then
        box:addRow( TNT.format( 'I18n/Module:Galactapedia', 'related_articles' ), self.args.related, nil, 'col-full' )
    end

    box:addRowsFromArgs( self.args, '!' )

    return tostring( box ) .. tostring( table.concat( self.categories ) ) .. tostring( common.generateInterWikiLinks( self:getTitle() ) )
end


--- Entry point for template calls
--- @return string
function Galactapedia.infoBox( frame )
    local instance = Galactapedia:new()
    instance:setFrame( frame )
    instance:setSeoData()

    return instance:getInfobox()
end

--- New Instance
--- Library entrance
function Galactapedia.new( self )
    local instance = {
        frame = nil,
        args = nil,
        categories = {},
        smwData = {
            [ 'Austritt' ]         = nil,
            [ 'Geburtsdatum' ]     = nil,
            [ 'Todesdatum' ]       = nil,
            [ 'Volk' ]             = nil,
            [ 'Hersteller' ]       = nil,
            [ 'Beruf' ]            = nil,
            [ 'Veröffentlichung' ] = nil,
            [ 'Zeitpunkt' ]        = nil,
            [ 'Gründungsdatum' ]   = nil,
            [ 'Ort' ]              = nil,
        }
    }

    setmetatable( instance, metatable )

    return instance
end

return Galactapedia
Cookies help us deliver our services. By using our services, you agree to our use of cookies.