Modul:Spectrum Dispatch

Aus Star Citizen Wiki

Lua-Fehler in Modul:DependencyList, Zeile 178: Modul:Spectrum Dispatch/Data existiert nicht.

Modulinfo

Dieses Modul setzt mehrere Vorlagen wie z.B. Vorlage:News Update um. Anweisungen zur Verwendung findest du auf der Vorlagenseite.


local SpectrumDispatch = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable

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

-- Needed Extensions
local infobox = require( 'Module:InfoboxNeue' )
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
---
---@return 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

	if not require( 'Module:Localized' ).isLanguagePage() then
		self:setSemanticProperties()
	end

    self:setMainCategory()
end

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

    local box = infobox:new()

    local titleImage = self:getTitleImage()

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

    box:renderHeader( {
    	title = self:getTitle(),
    	subtitle = self:getHeaderTitle()
    } )

	local section = {}

    if ( self.smwData[ 'Episode' ] ) then
        table.insert( section, box:renderItem( 'Episode', self.smwData[ 'Episode' ], nil ) )
    end

    if ( self.smwData[ 'Veröffentlichung' ] ) then
        table.insert( section, box:renderItem( 'Veröffentlichung', self.smwData[ 'Veröffentlichung' ] ) )
    end

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

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

        table.insert( section, box:renderItem( 'Personenliste', table.concat( persons, '<br>' ) ) )
    end

    if ( #self.smwData[ 'Thema' ] > 0 ) then
        table.insert( section, box:renderItem( 'Themenliste', table.concat( self.smwData[ 'Thema' ], '<br>' ) ) )
    end

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

        table.insert( section, box:renderItem( 'Comm-Link', table.concat( commLinkLinks, '<br>' ) ) )
    end

    if ( self.args[ 'source_url_rsi' ] ~= nil ) then
        table.insert( section, box:renderItem( 'RSI', '[' .. self.args[ 'source_url_rsi' ] .. ' RSI]' ) )
    end

    if ( self.args[ 'source_url_translation' ] ~= nil ) then
        table.insert( section, box:renderItem( 'Übersetzung', '[' .. self.args[ 'source_url_translation' ] .. ' Übersetzung]' ) )
    end
    
    box:renderSection( {
    	col = 2,
    	content = section,
    } )

    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.