Modul:CharArmorComponents: Unterschied zwischen den Versionen

Aus Steel Beasts Wiki
imported>FoXFTW
KKeine Bearbeitungszusammenfassung
 
K (1 Version importiert)
 

Aktuelle Version vom 3. September 2023, 08:02 Uhr

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

local CharArmorComponents = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable


local localized = require( 'Module:Localized' )


--- Request armor set and class from the current page
--- @param title string
--- @return string|nil
function CharArmorComponents.getPageData( title )
    local query = {
        '[[' .. title .. ']]',
        '?Set#-=set', '+lang=de',
        '?Basisversion UUID#-=base_uuid',
        '?UUID#-=uuid',
        'mainlabel=-'
    }

    local result = mw.smw.ask( query )
    local set, uuid, base_uuid

    if result ~= nil and result[ 1 ] ~= nil then
        set = result[ 1 ].set or nil
        base_uuid = result[ 1 ].base_uuid or nil
        uuid = result[ 1 ].uuid or nil
    end

    return set, uuid, base_uuid
end


--- Creates the query for components
--- @return string
function CharArmorComponents.makeComponentsQuery( frame )
    local args = require( 'Module:Arguments' ).getArgs( frame )

    -- name from args or current page
    local name = args[ 1 ] or args[ 'Name' ] or localized.getMainTitle()
    local set, _, _ = CharArmorComponents.getPageData( name )

    local restrictions = {
        '[[Name::~~"' .. name .. '"]]',
        '[[Ist Basisversion::Wahr]]',
        '[[:+]]',
    }

    if type( set ) == 'string' then
        table.insert( restrictions, '[[Set::' .. set .. ']]')
    else
    	return ''
    end

	local query = {
	    '{{#ask:',
	    table.concat( restrictions ),
	    '|?Rüstungsklasse=Komponente',
	    '|+lang=de',
	    '|?Name',
	    '|format=broadtable',
	    '|limit=5',
	    '|offset=0',
	    '|link=all',
	    '|sort=',
	    '|order=asc',
	    '|headers=plain',
	    '|mainlabel=-',
	    '|class=sortable wikitable smwtable',
	    '|transpose=1',
	    '|intro=<nowiki/>',
	    '== Rüstungskomponenten ==',
	    '<div class="flex-wrapper">',
	    '|outro=<nowiki/>',
	    '</div>',
	    '}}',
	}

	return frame:preprocess( table.concat( query, "\n" ) )
end


--- Creates the query for variants
--- @return string
function CharArmorComponents.makeVariantsQuery( frame )
    local args = require( 'Module:Arguments' ).getArgs( frame )

    -- name from args or current page
    local name = args[ 1 ] or args[ 'Name' ] or localized.getMainTitle()
    local set, uuid, base_uuid = CharArmorComponents.getPageData( name )

    local restrictions = {
        '[[:+]]',
        '[[Hat Unterobjekt::+]]',
    }

    if set == nil and uuid == nil and base_uuid == nil then
    	return ''
	end

    if base_uuid ~= nil then
    	table.insert(
    		restrictions,
    		'<q>[[Basisversion UUID::' .. base_uuid .. ']]||[[UUID::' .. base_uuid .. ']]</q>'
		)
    elseif uuid ~= nil then
		table.insert( restrictions, '[[Basisversion UUID::' .. uuid .. ']]')
	else
        table.insert( restrictions, '[[Name::~' .. name .. '%"]]' )
	end

    if type( set ) == 'string' then
        table.insert( restrictions, '[[Set::' .. set .. ']]')
    end

	local query = {
	    '{{#ask:',
	    table.concat( restrictions ),
	    '|format=ul',
	    '|limit=15',
	    '|offset=0',
	    '|link=all',
	    '|order=asc',
	    '|class=ul-col-3',
	    '|searchlabel=… weitere Versionen',
	    '|intro=<nowiki/>',
	    '== Versionen ==',
	    'Dieses Item existiert in folgenden Varianten:',
	    '}}',
	}

	return frame:preprocess( table.concat( query, "\n" ) )
end


return CharArmorComponents