Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:ItemPorts/Vehicle

From the Star Citizen Wiki, the fidelity™ encyclopedia
Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:ItemPorts/Vehicle/doc. Changes can be proposed in the talk page.
Function list
L 17 — t
L 22 — methodtable.setHardpoints
L 53 — p.new
L 64 — p.test

require( 'strict' )

local p = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable

local i18n = require( 'Module:i18n' ):new()


--- Wrapper function for Module:i18n.translate
---
--- @param key string The translation key
--- @return string If the key was not found, the key is returned
local function t( key )
	return i18n:translate( key )
end


function methodtable.setHardpoints( self, hardpoints )
    --mw.logObject( hardpoints, '📡 [ItemPorts/Vehicle] Load hardpoints from API')

    for _, hardpoint in ipairs( hardpoints ) do
        local subobject = {}
        -- Hardpoint
        subobject[ t( 'SMW_ItemPortName' ) ] = hardpoint.name
        subobject[ t( 'SMW_ItemPortMinimumSize' ) ] = hardpoint.min_size
        subobject[ t( 'SMW_ItemPortMaximumSize' ) ] = hardpoint.max_size
        -- Equipped item
        if hardpoint.item then
            subobject[ t( 'SMW_EquippedItemUUID' ) ] = hardpoint.item.uuid
            subobject[ t( 'SMW_EquippedItemSize' ) ] = hardpoint.item.size
            -- This is temporary, we need to figure out a better way to name things
            -- We should keep both the class name and name
            if hardpoint.item.name == '<= PLACEHOLDER =>' and hardpoint.item.class_name then
                subobject[ t( 'SMW_EquippedItemName' ) ] = hardpoint.item.class_name
            else
                subobject[ t( 'SMW_EquippedItemName' ) ] = hardpoint.item.name
            end
        end

        --mw.logObject( subobject, '💾 [ItemPorts/Vehicle] Save hardpoint to SMW' )
        mw.smw.subobject( subobject )
    end
end


--- New Instance
---
--- @return table p
function p.new( self, page )
    local instance = {
        page = page or nil
    }

    setmetatable( instance, metatable )

    return instance
end


function p.test( frame )
    frame = frame or { args = {} }
    local page = frame.args['Name'] or 'b9bc6679-81ad-472b-8b98-866c72fe6a89'
    local json = mw.text.jsonDecode( mw.ext.Apiunto.get_raw( 'v2/vehicles/' .. page, {
        include = {
            'hardpoints',
            'parts'
        },
    } ) )

    local itemports = p:new()
    itemports:setHardpoints( json.data.hardpoints )
end

return p
Heya! We only use cookie to make the site function and save your preferences, nothing else :)