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

Modul:ArmorTable

From Star Citizen Wiki

Modulabhängigkeiten

Modulinfo

Dieses Modul erzeugt eine tabellarische Übersicht aller verfügbaren Rüstungen.


local ArmorTable = {}

local common = require( 'Module:Common' )

local metatable = {}
local methodtable = {}

metatable.__index = methodtable


--- Queries the SMW Store
--- @return table
function methodtable.getSmwData( self )
    -- Cache multiple calls
    if self.smwData ~= nil then
        return self.smwData
    end

    -- name from args or current page
    -- local subType = self.frameArgs[ 'Typ' ] or 'Raumschiff'

    local query = {
        '[[Ist Basisversion::wahr]][[Kategorie:Körperpanzerung]][[Set::+]]',
        '?#-=page',
        '?Set#-=set',
        '?Schadensreduktion#-=dmg_resist',
        '?Temperaturresistenz=temp_resist',
        '?Rüstungsklasse#-=class', '+lang=' .. common.getLocaleForPage(),
        '?Rüstungstyp#-=type', '+lang=' .. common.getLocaleForPage(),
        '?SP=sp',
        '?Hersteller#-=manufacturer',
        '?Spielversion#-=version',
        '?-Name.Basispreis=price',
        'mainlabel=name',
        'sort=name,Rüstungsklasse,Set',
        'order=asc,asc,asc',
        'limit=500',
    }

    local data = mw.smw.ask( query )

    if data == nil or data[ 1 ] == nil then
        return nil
    end
	
	mw.logObject(data[ 1 ] )
    
    self.smwData = data

    return self.smwData
end


--- Sorts the table by Position -> Shop
---
--- @return table
function methodtable.sort( self )
    local sorted = {}

    for _, row in pairs( self.smwData ) do
        if row.type ~= nil and row.set ~= nil then
            if type( sorted[ row.type ] ) ~= 'table' then
                sorted[ row.type ] = {}
            end

            if type( sorted[ row.type ][ row.set ] ) ~= 'table' then
                sorted[ row.type ][ row.set ] = {}
            end

            table.insert( sorted[ row.type ][ row.set ], row )
        end
    end

    return sorted
end


--- Creates the buy table
---
--- @param armor table
--- @return string
function methodtable.createTable(self, items)
    if #items == 0 then
        return ''
    end

    local currentRow = 1

    local table = mw.html.create( 'table' )
                    :attr( 'class', 'wikitable broadtable sortable' )
                    :attr( 'style', 'width: 100%')
                    :tag( 'tr' )
                        :tag( 'th' )
                            :wikitext( 'Name' )
                            :done()
                        :tag( 'th' )
                            :wikitext( 'Schadensreduktion' )
                            :done()
                        :tag( 'th' )
                            :wikitext( 'Temperaturresistenz' )
                            :done()
                        :tag( 'th' )
                            :wikitext( 'Rüstungsklasse' )
                            :done()
                        :tag( 'th' )
                            :wikitext( 'Preis' )
                            :done()
                        :tag( 'th' )
                            :wikitext( 'Hersteller' )
                            :done()
                        :tag( 'th' )
                            :wikitext( 'Spielversion' )
                            :done()
                        :done()
                    :done()

    for _, armor in pairs(items) do
        local trClass = 'row-odd'
        if currentRow % 2 == 0 then
            trClass = 'row-even'
        end
        currentRow = currentRow + 1

		local price = '-'
		if type( armor.price ) == 'table' then
			price = armor.price[ 1 ]
		end

        table:tag( 'tr' )
             :addClass( trClass )
                 :tag( 'td' )
                     :wikitext( string.format( '[[%s]]', armor.page ) )
                     :done()
                 :tag( 'td' )
                    :wikitext( armor.dmg_resist )
                    :done()
                 :tag( 'td' )
                    :wikitext( (armor.temp_resist[1] or '-') .. ' / ' .. (armor.temp_resist[2] or '-') )
                    :done()
                 :tag( 'td' )
                    :wikitext( armor.class )
                    :done()
                 :tag( 'td' )
                    :wikitext( price )
                    :done()
                 :tag( 'td' )
                	:wikitext( string.format( '[[%s]]', armor.manufacturer ) )
                    :done()
                 :tag( 'td' )
                     :wikitext( armor.version )
                    :done()
             :done()
    end

    return table:allDone()
end


--- Outputs the table
---
--- @return string
function methodtable.make( self )
    local data = self:getSmwData()

    if data == nil then
        return '<p class="hatnote">Konnte keine semantischen Daten laden.</p>'
    end

    local sorted = self:sort()
    local out = ''

    for class, sets in common.spairs( sorted ) do
        out = string.format( "%s\n=== [[%s]] ===\n", out, class)

        for set, items in common.spairs(sets) do
            out = string.format( "%s\n==== [[%s]] ====\n%s", out, set, tostring( self:createTable(items) ) )
        end
    end

    return mw.text.trim( out )
end


--- New Instance
--- @return table ArmorTable
function ArmorTable.new( self, frameArgs )
    local instance = {
        args = frameArgs,
    }

    setmetatable( instance, metatable )

    return instance
end

--- Entry for module calls
---
--- @return string
function ArmorTable.fromArgs( frame )
    local args = require( 'Module:Arguments').getArgs( frame )

    local instance = ArmorTable:new( args )

    return instance:make()
end


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