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

Modul:SystemEntity

From Star Citizen Wiki

Modulabhängigkeiten

Modulinfo

Dieses Modul ist ein Grundmodul für Systementitäten eines Sternensystems. Es erzeugt Infoboxen.

Mithilfe dieses Moduls können z.B. Points of Interest innerhalb des Wikis angezeigt werden.


local SystemEntity = require( 'Module:CelestialObject' ):new( 'Entität' )

-- Extensions
local common = require( 'Module:Common' )
local infobox = require( 'Module:Infobox' )
local system = require( 'Module:Sternensystem' )

--- Template arguments to subobject data
--- @return table
local function getEntityData( args )
    return {
        [ 'Quantum Beacon' ]               = args[ 'Quantum Beacon' ]               or nil,
        [ 'Rechtsraum' ]                   = args[ 'Rechtsraum' ]                   or nil,
        [ 'Waffenfreie Zone' ]             = args[ 'Waffenfreie Zone' ]             or nil,
        [ 'Überwachte Zone' ]              = args[ 'Überwachte Zone' ]              or nil,
        [ 'ATC' ]                          = args[ 'ATC' ]                          or nil,
        [ 'Anzahl Landeplattformen' ]      = args[ 'Anzahl Landeplattformen' ]      or nil,
        [ 'Anzahl Hangar' ]                = args[ 'Anzahl Hangar' ]                or nil,
        [ 'Anzahl Garagen' ]               = args[ 'Anzahl Garagen' ]               or nil,
        [ 'Anzahl Bodenfahrzeugkonsolen' ] = args[ 'Anzahl Bodenfahrzeugkonsolen' ] or nil,
        [ 'Anzahl Raumschiffkonsolen' ]    = args[ 'Anzahl Raumschiffkonsolen' ]    or nil,
        [ 'Temperatur Schattenseite' ]     = args[ 'Temperatur Schattenseite' ]     or nil,
        [ 'Temperatur Sonnenseite' ]       = args[ 'Temperatur Sonnenseite' ]       or nil,
        [ 'Anzahl Händler' ]               = args[ 'Anzahl Händler' ]               or nil,
        [ 'Handelsterminals' ]             = args[ 'Handelsterminals' ]             or nil,
        [ 'Anzahl Paketstationen' ]        = args[ 'Anzahl Paketstationen' ]        or nil,
        [ 'Raffineriestationen' ]          = args[ 'Raffineriestationen' ]          or nil,
    }
end

--- Adds the entities system as a header to the infobox
--- @param self table - The SystemEntity self
--- @param box table - The infobox
function SystemEntity.addSystemHeader( self, box )
    if self.parentObjectData == nil or self.parentObjectData.page == nil then
        return
    end

    local parentPage = ''

    local ask = {
        '[[ID::' .. self.celestialObjectData.system_id .. '|+depth=0]]',
        '?#-=page',
        '?Starmap Code=code',
    }

    ask.mainlabel = '-'
    ask.limit = 1
    ask.sort = 'Starmap Code'
    ask.order = 'asc'

    ask = mw.smw.ask( ask )
    if ask ~= nil and ask[ 1 ] ~= nil then
        parentPage = ask[ 1 ].page
    else
        parentPage = mw.text.split( self.parentObjectData.page, '#', true )[ 1 ]
    end

    box:addHeader( '[[' .. parentPage .. '|' .. parentPage .. ' System]]', 'single' )
end

--- Get POIs or Personalities on this object
--- @param searchTypes string|table List of 'Typ' attributes
--- @return table
function SystemEntity.getChildObjects( self, searchTypes )
    if type( searchTypes ) ~= 'table' then
        searchTypes = {
            searchTypes
        }
    end

    local selector = {
        '[[Elternid::' .. self.celestialObjectData.id .. ']]',
    }

    local conditions = {}
    for _, searchType in pairs( searchTypes ) do
        table.insert( conditions, '[[Typ::' .. searchType .. ']]' )
    end

    table.insert( selector, '<q>' .. table.concat( conditions, '||' ) .. '</q>' )

    local query = {
        table.concat( selector ),
        '?Bezeichnung',
    }

    query.mainlabel = '-'

    local data = mw.smw.ask( query )

    return data
end

--- Creates the infobox
--- TODO Refactor, this is largely copied from CelestialObject
function SystemEntity.makeInfoBox( self )
    if self.celestialObjectData == nil or self.celestialObjectData.page == nil or self.hideBox == true then
        -- Faulty SMW data
        return ''
    end

    local box = infobox.create( {
        bodyClass = 'floatright',
        allowReplace = true,
        removeEmpty = true,
        emptyString = '-',
        placeholderImage = 'Platzhalter Starmap.webp',
    } )

    -- Image
    box:addImage( common.getImage( self.frameArgs['image'] ), {
        [ 'alternativtext' ] = self.pageName .. ' ' .. self.objectType,
        'rahmenlos',
        '350px'
    } )

    local boxTitle = mw.title.getCurrentTitle().subpageText
    if boxTitle ~= self.pageName then
        boxTitle = self.pageName
    end

    box:addTitle( common.removeTypeSuffix( boxTitle, self.typeSuffixes ) )

    self:addSystemHeader( box )

    box:addHeader( 'Astronomische Daten' )

    if self.parentObjectData.type ~= nil and self.parentObjectData.planet_count == nil then
        local orbits = self.parentObjectData.designation

        if self.parentObjectData.type == 'STAR' then
            orbits = orbits .. ' (Stern)'
        end
        
        if self.parentObjectData.name ~= nil then
        	orbits = orbits .. '|' .. orbits .. ': ' .. self.parentObjectData.name
    	end

        box:addRow( self:getPositionLabel( self.celestialObjectData.type ), '[[' .. orbits .. ']]', nil, 'col2' )
    end

    box:addRow( 'Navigationspunkt', common.booleanToText(self.celestialObjectData[ 'Quantum Beacon' ]) or '-', nil, 'col2' )

       :addHeader( 'Recht' )
       :addRow( 'Kontrolle', system.getAffiliationLines( self.celestialObjectData.affiliation ) or '-', nil, 'col2' )
       :addRow( 'Rechtsraum', self.celestialObjectData[ 'Rechtsraum' ] or '-', nil, 'col2' )
       :addRow( 'Waffenfreie Zone', common.booleanToText(self.celestialObjectData[ 'Waffenfreie Zone' ]) or '', nil, 'col2' )
       :addRow( 'Überwachte Zone', common.booleanToText(self.celestialObjectData[ 'Überwachte Zone' ]) or '', nil, 'col2' )

    local atc = self.celestialObjectData[ 'ATC' ]
    if atc ~= nil then
        atc = common.booleanToText( self.celestialObjectData[ 'ATC' ] )
    end

    box
       :addHeader( 'Mobilität' )
       :addRow( 'Lande- und Startkontrolle', atc or '-', nil, 'col2' )
       :addRow( 'Landeplattformen', self.celestialObjectData[ 'Anzahl Landeplattformen' ] or '-', nil, 'col2' )
       :addRow( 'Hangar', self.celestialObjectData[ 'Anzahl Hangar' ] or '-', nil, 'col2' )
       :addRow( 'Garagen', self.celestialObjectData[ 'Anzahl Garagen' ] or '-', nil, 'col2' )
       :addRow( 'Bodenfahrzeugkonsolen', self.celestialObjectData[ 'Anzahl Bodenfahrzeugkonsolen' ] or '-', nil, 'col2' )
       :addRow( 'Raumschiffkonsolen', self.celestialObjectData[ 'Anzahl Raumschiffkonsolen' ] or '-', nil, 'col2' )

    local habitable = self.celestialObjectData.habitable
    if habitable ~= nil then
        habitable = common.booleanToText( self.celestialObjectData.habitable )
    end

    local temperature = '-'
    if self.celestialObjectData[ 'Temperatur Schattenseite' ] ~= self.celestialObjectData[ 'Temperatur Sonnenseite' ] then
        temperature = (self.celestialObjectData[ 'Temperatur Schattenseite' ] or '-') .. ' / ' .. (self.celestialObjectData[ 'Temperatur Sonnenseite' ] or '-')
    end

    box
       :addHeader( 'Umgebung' )
       :addRow( 'Habitabel', habitable or '-', nil, 'col2' )
       :addRow( 'Temperatur', temperature, nil, 'col2' )


       :addHeader( 'Wirtschaft' )
       :addRow( 'Händler', self.celestialObjectData[ 'Anzahl Händler' ] or '-', nil, 'col2' )
       :addRow( 'Paketstation', self.celestialObjectData[ 'Anzahl Paketstation' ] or '-', nil, 'col2' )
       :addRow( 'Ein- und Verkauf von Handelsware', self.celestialObjectData[ 'Handelsterminals' ] or '-', nil, 'col-full' )
       :addRow( 'Raffineriestationen', self.celestialObjectData[ 'Raffineriestationen' ] or '-', nil, 'col-full' )


    -- TODO: REFACTOR
    if self.celestialObjectData[ 'Anzahl Landeplattformen' ] ~= nil then
        self:addCategory( 'Landezone' )
    end

    -- TODO: REFACTOR
    if self.celestialObjectData[ 'Anzahl Händler' ] ~= nil or self.celestialObjectData[ 'Handelsterminals' ] ~= nil then
        self:addCategory( 'Handelsplatz' )
    end

    local personalities = self:getChildObjects( 'PERSON' )
    local pois = self:getChildObjects( {
        'POI',
        'STRUCTURE',
        'LANDINGZONE'
    } )

    if personalities ~= nil or pois ~= nil then
        box:addHeader( 'Personen und POIs' )
    end

    if personalities ~= nil then
        local list = {}

        for _, personality in pairs( personalities ) do
            table.insert( list, '[[' .. personality[ 'Bezeichnung' ] .. ']]' )
        end

        box:addRow( 'Persönlichkeiten', table.concat( list , '<br>'), nil, 'col2' )
    end

    if pois ~= nil then
        local list = {}

        for _, personality in pairs( pois ) do
            table.insert( list, '[[' .. personality[ 'Bezeichnung' ] .. ']]' )
        end

        box:addRow( 'Sehenswürdigkeiten', table.concat( list, '<br>'), nil, 'col2' )
    end

    if self.currentFrame ~= nil then
        box:addRowsFromArgs( require( 'Module:Arguments' ).getArgs( self.currentFrame ), '!' )
    end

    return tostring( box ) .. tostring( common.generateInterWikiLinks( self.pageName ) )
end

--- Overwrites CelestialObject method
function SystemEntity.addManual( self, args, typeOverride )
    if args[ 'Starmap Code' ] == nil or mw.title.getCurrentTitle().isSubpage then
        return
    end

    if args[ 'Infobox' ] == 'Nein' then
        self.hideBox = true
    end

    local celestialObjectData = self:getSubObjectData( args )
    local entityData = getEntityData( args )

    local subObject = {}

    for key, value in pairs( celestialObjectData ) do
        if value ~= nil then
            subObject[ key ] = value
        end
    end

    for key, value in pairs( entityData ) do
        if value ~= nil then
            if key == 'Temperatur Sonnenseite' or key == 'Temperatur Schattenseite' then
                value = mw.text.trim( value, 'CFK° ' )
                value = value .. ' °C'
            end

            subObject[ key ] = value
        end
    end

    if typeOverride ~= nil then
        subObject[ 'Typ' ] = typeOverride
    end

    subObject[ 'Typ' ] = mw.text.trim( mw.ustring.upper( subObject[ 'Typ' ] ) ) .. '@en'

    mw.smw.subobject( subObject )
end

--- For direct invocation
function SystemEntity.newFromFrame( frame )
    local objectType = frame:getParent().args[ 'Kategorie' ] or frame.args[ 'type' ] or 'Entität'
    
    if frame:getParent().args[ 'Typ' ] ~= nil then
    	local mappedType = SystemEntity.reverseMapType( frame:getParent().args[ 'Typ' ] )
    	if mappedType ~= nil then
    		objectType = mappedType
    	end
	end

    local instance = SystemEntity:new( objectType )

    return instance:run( frame )
end

--- New Instance
function SystemEntity.new( self, objectType )
    local instance = {}

    setmetatable( instance, self )
    self.__index = self

    if objectType == nil then
        error( 'Required argument "objectType" missing.' )
    end

    instance.objectType = objectType
    self.objectType = objectType

    table.insert( instance.typeSuffixes, objectType )

    return instance
end

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