Modul:Volk

Aus Steel Beasts Wiki
Version vom 3. Juli 2023, 15:05 Uhr von sc>SpaceEnergy
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

Die Dokumentation für dieses Modul kann unter Modul:Volk/Doku erstellt werden

local Volk = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable

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

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

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

    return title
end

-- Adds the main category
function methodtable.setMainCategory( self )
    table.insert( self.categories, '[[Category:Volk]]' )
end

--
function methodtable.getSystemCounts( self )
    if self.args.code == nil then
        return ''
    end

    local starsystem = require( 'Module:Sternensystem' )

    local code = self.args.code
    if code == 'Xi\'an' then
        code = 'Xi\'An'
    end

    local query = {
        '[[Kontrolle::' .. code .. ']][[Kategorie:Sternensystem]]',
        '?#-=page',
        'mainlabel=-',
    }

    local systems = mw.smw.ask( query )

    local controlled = 0
    if systems ~= nil and systems[ 1 ] ~= nil then
        controlled = table.maxn( systems )
    end

    local smwQueryLink = mw.getCurrentFrame():preprocess( '{{#ask: [[Kontrolle::' .. code .. ']][[Kategorie:Sternensystem]]|format=ul|limit=0|searchlabel=Systeme|class=ul-col-3}}')

    local line = starsystem.getAffiliationLines( code ) .. ' ' .. controlled .. ' ' .. smwQueryLink

    query = {
        '[[Kontrolle::Unclaimed]][[Kategorie:Sternensystem]]',
        '?#-=page',
        'mainlabel=-',
    }

    systems = mw.smw.ask( query )

    controlled = 0
    if systems ~= nil and systems[ 1 ] ~= nil then
        controlled = table.maxn( systems )
    end

    smwQueryLink = mw.getCurrentFrame():preprocess( '{{#ask: [[Kontrolle::Unclaimed]][[Kategorie:Sternensystem]]|format=ul|limit=0|searchlabel=Systeme|class=ul-col-3}}')

    line = line .. '<br>' .. starsystem.getAffiliationLines( 'UNCLAIMED' ) .. ' ' .. controlled .. ' ' .. smwQueryLink

    return line
end


-- Public functions
--
function methodtable.getInfobox( self )
    local box = infobox:new()

    local titleImage = common.getImage( self.args[ 'image' ] or self.args[ 'Bild' ] )
    box:renderImage( titleImage )

    if titleImage == false then
        table.insert( self.categories, '[[Category:Volk mit fehlendem Bild]]' )
    end

    box:renderHeader( self:getTitle() )
    box:renderSection( {
    	content = {
    		box:renderItem( { label = 'Heimatplanet', data = self.args.homeworld } ),
    		box:renderItem( { label = 'Erstkontakt', data = self.args.first_contact } ),
    		box:renderItem( { label = 'Religion', data = self.args.religion } ),
    		box:renderItem( { label = 'Souverän', data = self.args.sovereign } ),
    		box:renderItem( { label = 'Regierungsform', data = self.args.government } ),
    		box:renderItem( { label = 'Währung', data = self.args.currency } ),
    		box:renderItem( { label = 'Territorien', data = self:getSystemCounts() } ),    		
    	}
    } )

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

--- Entrypoint for {{#seo:}}
--- @return void
function methodtable.setSeoData( self )
    -- Call to {{#seo:}}
    mw.ext.seo.set{
        author = self.frame:preprocess( '{{SERVER}}/Benutzer:{{urlencode:{{REVISIONUSER}}|WIKI}}' ),
        section = 'Universum',
        url = tostring( mw.uri.fullUrl( mw.title.getCurrentTitle().text ) ),
        title = table.concat({
            mw.title.getCurrentTitle().subpageText,
            'Volk',
            self.frame:preprocess( '{{SITENAME}}' )
        }, ' - '),
        title_mode = 'replace',
        locale = 'de_DE',
        type = 'article',
    }
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


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

    return instance:getInfobox()
end


--- New Instance
--- Library entrance
function Volk.new( self )
    local instance = {
        frame = nil,
        args = nil,
        categories = {},
    }

    setmetatable( instance, metatable )

    return instance
end

return Volk