Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Please sign up or log in to edit the wiki.

Module:Item/WeaponPersonal: Difference between revisions

From the Star Citizen Wiki, the fidelity™ encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 91: Line 91:
title = 'Debug - ' .. modeCount,
title = 'Debug - ' .. modeCount,
content = {
content = {
infobox:renderItem( 'mode name', 'firingmode_' .. mode[ translate( 'SMW_FiringMode' ) ] ),
infobox:renderItem( 'mode type', mode[ translate( 'SMW_FiringMode' ) ] ),
infobox:renderItem( 'mode name', translate( 'firingmode_' .. mode[ translate( 'SMW_FiringMode' ) ] ) ),
infobox:renderItem( 'mode', mw.dumpObject( mode ) )
infobox:renderItem( 'mode', mw.dumpObject( mode ) )
},
},

Revision as of 20:22, 3 April 2024

Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Item/WeaponPersonal/doc. Changes can be proposed in the talk page.
Function list
L 18 — translate
L 26 — p.addSmwProperties
L 43 — p.addSmwAskProperties
L 58 — p.addInfoboxData
L 61 — renderFiringModesSection
L 137 — p.addCategories
L 146 — p.getShortDescription

require( 'strict' )

local p = {}

local MODULE_NAME = 'WeaponPersonal'

local TNT = require( 'Module:Translate' ):new()
local smwCommon = require( 'Module:Common/SMW' )
local data = mw.loadJsonData( 'Module:Item/' .. MODULE_NAME .. '/data.json' )
local config = mw.loadJsonData( 'Module:Item/config.json' )


--- Wrapper function for Module:Translate.translate
---
--- @param key string The translation key
--- @param addSuffix boolean|nil Adds a language suffix if config.smw_multilingual_text is true
--- @return string If the key was not found in the .tab page, the key is returned
local function translate( key, addSuffix, ... )
    return TNT:translate( 'Module:Item/' .. MODULE_NAME .. '/i18n.json', config, key, addSuffix, {...} )
end


--- Adds the properties valid for this item to the SMW Set object
---
--- @param smwSetObject table
function p.addSmwProperties( apiData, frameArgs, smwSetObject )
    smwCommon.addSmwProperties(
        apiData,
        frameArgs,
        smwSetObject,
        translate,
        config,
        data,
        'Item/' .. MODULE_NAME
    )
end


--- Adds all SMW parameters set by this Module to the ASK object
---
--- @param smwAskObject table
--- @return nil
function p.addSmwAskProperties( smwAskObject )
    smwCommon.addSmwAskProperties(
        smwAskObject,
        translate,
        config,
        data
    )
end


--- Adds entries to the infobox
---
--- @param infobox table The Module:InfoboxNeue instance
--- @param smwData table Data from Semantic MediaWiki
--- @return nil
function p.addInfoboxData( infobox, smwData, itemPageIdentifier )
    local tabber = require( 'Module:Tabber' ).renderTabber

    local function renderFiringModesSection()
        local modes = smwCommon.loadSubobjects(
            itemPageIdentifier,
            'SMW_FiringMode',
            {
                'SMW_FiringMode',
                'SMW_FiringRate',
                'SMW_AmmoPerShot',
                'SMW_ProjectilePerShot',
                'SMW_DamagePerSecond'
            },
            translate
        )

        if type( modes ) == 'table' then
            local section = {}
            local modeTabberData = {}
            local modeCount = 1

            for _, mode in ipairs( modes ) do
                modeTabberData[ 'label' .. modeCount ] = translate( 'firingmode_' .. mode[ translate( 'SMW_FiringMode' ) ] )
                section = {
                    infobox:renderItem( translate( 'LBL_DamagePerSecond' ), mode[ translate( 'SMW_DamagePerSecond' ) ] ),
                    infobox:renderItem( translate( 'LBL_FiringRate' ), mode[ translate( 'SMW_FiringRate' ) ] ),
                    infobox:renderItem( translate( 'LBL_ProjectilePerShot' ), mode[ translate( 'SMW_ProjectilePerShot' ) ] ),
                    infobox:renderItem( translate( 'LBL_AmmoPerShot' ), mode[ translate( 'SMW_AmmoPerShot' ) ] )
                }
                modeTabberData[ 'content' .. modeCount ] = infobox:renderSection( { content = section, col = 2 }, true )

                infobox:renderSection( {
                    title = 'Debug - ' .. modeCount,
                    content = {
                        infobox:renderItem( 'mode type', mode[ translate( 'SMW_FiringMode' ) ] ),
                        infobox:renderItem( 'mode name', translate( 'firingmode_' .. mode[ translate( 'SMW_FiringMode' ) ] ) ),
                        infobox:renderItem( 'mode', mw.dumpObject( mode ) )
                    },
                    col = 2
                } )

                modeCount = modeCount + 1
            end

            infobox:renderSection( {
                title = 'Debug - TabberData',
                content = {
                    infobox:renderItem( 'tabberdata', mw.dumpObject( modeTabberData ) )
                },
                col = 2
            } )

            infobox:renderSection( {
                title = translate( 'LBL_Modes' ),
                class = 'infobox__section--tabber',
                content = tabber( modeTabberData ),
                border = false
            }, true )
        end
    end

    infobox:renderSection( {
        content = {
            infobox:renderItem( translate( 'LBL_Ammo' ), smwData[ translate( 'SMW_Ammo' ) ] )
        },
        col = 2
    } )
    renderFiringModesSection()
end


--- Add categories that are set on the page.
--- The categories table should only contain category names, no MW Links, i.e. 'Foo' instead of '[[Category:Foo]]'
---
--- @param categories table The categories table
--- @param frameArgs table Frame arguments from Module:Arguments
--- @param smwData table Data from Semantic MediaWiki
--- @return nil
function p.addCategories( categories, frameArgs, smwData )

end

--- Return the short description for this object
---
--- @param frameArgs table Frame arguments from Module:Arguments
--- @param smwData table Data from Semantic MediaWiki
--- @return string|nil
function p.getShortDescription( frameArgs, smwData )

end


return p