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

Modul:Spectrum Dispatch

Aus Star Citizen Wiki

Dokumentation unvollständig.


local SpectrumDispatch = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable

-- Data about series name and type
local showData = mw.loadData( 'Module:Spectrum_Dispatch/Data' )

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

--- Write the semantic properties
function methodtable.setSemanticProperties( self )
    local result = mw.smw.set( self.smwData )

    common.checkSmwResult( result )
end

--- Parses the shows type
--- Adds a maintenance category if an invalid type was passed
---
--- @return string
function methodtable.getShowType( self )
    local title = mw.title.getCurrentTitle().text

    for name, type in pairs( showData.name ) do
        if string.match( title, name ) then
            return type
        end
    end

    if ( self.args[ 'show_type' ] ~= nil ) then
        return self.args[ 'show_type' ]
    end

    table.insert( self.categories, '[[Category:Spectrum Artikel mit fehlerhaftem Serientyp]]' )
end

--- Parses the shows name
--- Adds a maintenance category if an invalid name was passed
---
--- @return string
function methodtable.getShowName( self )
    local title = mw.title.getCurrentTitle().text

    for name, _ in pairs( showData.name ) do
        if string.match( title, name ) then
            return name
        end
    end

    if ( self.args[ 'show_name' ] ~= nil ) then
        return self.args[ 'show_name' ]
    end

    table.insert( self.categories, '[[Category:Spectrum Artikel mit fehlerhaftem Seriennamen]]' )
end

--- Adds the main category
function methodtable.setMainCategory( self )
    local cat = ''
    local showType = self.smwData[ 'Serientyp' ]

    if ( self.smwData[ 'Episode' ] ~= nil or showType == 'Time Capsule' or showType == 'News Update' ) then
        cat = self.smwData[ 'Serienname' ]
    else
        cat = self.smwData[ 'Serientyp' ]
    end

    if ( cat ~= nil ) then
        table.insert( self.categories, '[[Category:' .. cat .. ']]' )
    end
end

--- Get the infobox header title
---
--- @return string
function methodtable.getHeaderTitle( self )
    local output = ''

    if ( self.smwData[ 'Serienname' ] ) then
        if ( self.args[ 'show_name' ] == nil ) then
            output = self.smwData[ 'Serienname' ] .. ': '
        end
    end

    output = output .. mw.title.getCurrentTitle().subpageText

    return output
end

--- Infobox title
---
--- @return string
function methodtable.getTitle( self )
    local title = self.smwData[ 'Serientyp' ];

    if ( self.smwData[ 'Serientyp' ] == 'Galactic Guide' ) then
        title = 'Galactic Guide / Portfolio'
    else

    end

    return title
end

--- Tries to retrieve the infobox image
---
--- @return string|boolean Prefixed filename or false
function methodtable.getTitleImage( self )
    local suffix = '_Titelbild'

    local names = {
        self.args[ 'image' ]
    }

    if ( self.smwData[ 'Serienname' ] ~= nil ) then
        table.insert( names, self.smwData[ 'Serienname' ] .. '_' .. mw.title.getCurrentTitle().subpageText .. suffix )
        table.insert( names, self.smwData[ 'Serienname' ] .. suffix )

        if ( self.smwData[ 'Serientyp' ] ~= nil ) then
            table.insert( names, self.smwData[ 'Serientyp' ] .. '_' .. self.smwData[ 'Serienname' ] .. suffix )
        end
    end

    return common.getImage( names )
end

--- Build the display title
--- UGLY, refactor
---
[email protected] string
function methodtable.getPageTitle( self )
    local title = ''

    if ( self.smwData[ 'Serientyp' ] == 'Time Capsule' or self.smwData[ 'Serientyp' ] == 'News Update' ) then
        title = self.smwData[ 'Serienname' ] .. ' - '
        if ( self.smwData[ 'Episode' ]  ~= nil and self.smwData[ 'Serientyp' ] ~= 'Time Capsule' ) then
            title = title .. 'Episode ' .. self.smwData[ 'Episode' ]
        else
            title = title .. mw.title.getCurrentTitle().subpageText
        end
    else
        title = self.smwData[ 'Serienname' ]
        if ( self.smwData[ 'Episode' ]  ~= nil ) then
            title = title .. ' - Episode ' .. self.smwData[ 'Episode' ]
        end
    end

    return title
end

--- Extracts args and sets up the module
---
--- @param frame table - The current frame
function methodtable.init( self, frame )
    self.frame = frame
    self.args = require( 'Module:Arguments' ).getArgs( frame )

    self.smwData[ 'Serientyp' ] = self:getShowType()
    self.smwData[ 'Serienname' ] = self:getShowName()
    self.smwData[ 'Veröffentlichung' ] = self.args[ 'release' ]
    self.smwData[ 'Episode' ] = tonumber( self.args[ 'episode' ] )
    self.smwData[ 'Thema' ] = common.extractDataFromPrefix( 'topic', self.args )
    self.smwData[ 'Besetzung' ] = common.extractDataFromPrefix( 'cast', self.args )
    self.smwData[ 'Quelle' ] = {
        self.args[ 'source_url_rsi' ] or nil,
        self.args[ 'source_url_translation' ] or nil,
    }

    local commLinkIds = common.extractDataFromPrefix( 'comm_link_id', self.args )

    for _, id in pairs( commLinkIds ) do
        table.insert( self.commLinks, 'Comm-Link:' .. id )
    end

    if ( #self.commLinks > 0 ) then
        self.smwData[ 'Comm-Link' ] = self.commLinks
    end

    self:setSemanticProperties()
    self:setMainCategory()
end

--- Builds the infobox
---
--- @return string
function methodtable.getInfobox( self )
    common.setDisplayTitle( self.frame, self:getPageTitle() )

    local box = infobox.create( {
        bodyClass = 'floatright',
    } )

    local titleImage = self:getTitleImage()

    if ( titleImage ~= false ) then
        box:addImage( titleImage, {
            'rahmenlos'
        } )
    else
        table.insert( self.categories, '[[Category:Spectrum Artikel mit fehlendem Titelbild]]' )
    end

    box:addTitle( self:getTitle() )
       :addHeader( self:getHeaderTitle() )

    if ( self.smwData[ 'Episode' ] ) then
        box:addRow( 'Episode', self.smwData[ 'Episode' ], nil, 'col2' )
    end

    if ( self.smwData[ 'Veröffentlichung' ] ) then
        box:addRow( 'Veröffentlichung', self.smwData[ 'Veröffentlichung' ], nil, 'col2' )
    end

    if ( #self.smwData[ 'Besetzung' ] > 0 ) then
        local persons = {}

        for _, v in pairs( self.smwData[ 'Besetzung' ] ) do
            table.insert( persons, '[[' .. v .. ']]' )
        end

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

    if ( #self.smwData[ 'Thema' ] > 0 ) then
        box:addRow( 'Themenliste', table.concat( self.smwData[ 'Thema' ], '<br>' ), nil, 'col2' )
    end

    if ( #self.commLinks > 0 ) then
        local commLinkLinks = {}
        for _, id in pairs( self.commLinks ) do
            table.insert( commLinkLinks, '[[' .. id .. ']]' )
        end

        box:addRow( 'Comm-Link', table.concat( commLinkLinks, '<br>' ), nil, 'col2' )
    end

    if ( self.args[ 'source_url_rsi' ] ~= nil ) then
        box:addRow( 'RSI', '[' .. self.args[ 'source_url_rsi' ] .. ' RSI]', nil, 'col2' )
    end

    if ( self.args[ 'source_url_translation' ] ~= nil ) then
        box:addRow( 'Übersetzung', '[' .. self.args[ 'source_url_translation' ] .. ' Übersetzung]', nil, 'col2' )
    end

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

    return tostring( box ) .. tostring( table.concat( self.categories, '' ) )
end

--- Template entry
function SpectrumDispatch.infoBox( frame )
    local instance = SpectrumDispatch:new()
    instance:init( frame )

    return instance:getInfobox()
end

--- New Instance
function SpectrumDispatch.new( self )
    local instance = {
        frame = {},
        args = {},
        smwData = {
            [ 'Serientyp' ] = nil,
            [ 'Serienname' ] = nil,
            [ 'Veröffentlichung' ] = nil,
            [ 'Episode' ] = nil,
            [ 'Thema' ] = {},
            [ 'Besetzung' ] = {},

        },
        categories = {},
        commLinks = {},
    }

    setmetatable( instance, metatable )

    return instance
end

return SpectrumDispatch
Cookies helfen uns bei der Bereitstellung dieses Wikis. Durch die Nutzung des Star Citizen Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.