Module:Vehicle

local vehicle = {}

local metatable = {} local methodtable = {}

metatable.__index = methodtable

local common = require( 'Module:Common' ) local api = require( 'Module:Common/Api' )

--- Request Api Data --- Using current subpage name without vehicle type suffix --- @return table or nil function methodtable.getApiDataForCurrentPage( self ) local name = self.frameArgs.uuid or self.name

local json = mw.text.jsonDecode( mw.ext.Apiunto.get_raw( 'v2/vehicles/' .. name, { include = { 'hardpoints', --'components', 'shops', },   } ) )

if api.checkResponseStructure( json, true, false ) == false then return end

self.apiData = json[ 'data' ] self.apiData = api.makeAccessSafe( self.apiData )

return self.apiData end

--- Set Vehicle Semantic Properties function methodtable.setSemanticProperties( self ) if mw.title.getCurrentTitle.isSubpage then return end

common.checkSmwResult( self:setBaseSemanticProperties ) self:setExtraSemanticProperties end

--- Base Properties that are shared across all Vehicles --- @return table SMW Result function methodtable.setBaseSemanticProperties( self ) -- Set properties with Template param local setData = { [ 'Name' ] = self.name, [ 'Manufacturer' ] = require( 'Module:Manufacturer' )._manufacturer( self.frameArgs[ 'manufacturer' ] ).name, [ 'Production state' ] = self.frameArgs[ 'productionstate' ], --- Pledge info [ 'Pledge availability' ] = self.frameArgs[ 'pledgeavailability' ], [ 'Pledge price' ] = self.frameArgs[ 'pledgecost' ], [ 'Original pledge price' ] = self.frameArgs[ 'originalpledgecost' ], [ 'Warbond pledge price' ] = self.frameArgs[ 'warbondcost' ], [ 'Original warbond pledge price' ] = self.frameArgs[ 'originalwarbondcost' ], --- Official sites [ 'Galactapedia URL' ] = self.frameArgs[ 'galactapediaurl' ], [ 'Pledge store URL' ] = self.frameArgs[ 'rsistoreurl' ], }

-- Set properties with API data if self.apiData ~= nil then --- Identifier setData[ 'UUID' ] = self.apiData.uuid setData[ 'Class name' ] = self.apiData.class_name setData[ 'Pledge store name' ] = self.apiData.name --- Stats setData[ 'Mass' ] = self.apiData.mass --- Cargo setData[ 'Cargo capacity' ] = common.formatNum( self.apiData.cargo_capacity ) --- Speed setData[ 'SCM speed' ] = common.formatNum( self.apiData.speed.scm ) setData[ 'Maximum speed' ] = common.formatNum( self.apiData.speed.max ) --- Insurance if self.apiData.insurance ~= nil then setData[ 'Insurance claim time' ] = common.formatNum( self.apiData.insurance.claim_time or 0 ) setData[ 'Insurance expedite time' ] = common.formatNum( self.apiData.insurance.expedite_time or 0 ) setData[ 'Insurance expedite cost' ] = common.formatNum( self.apiData.insurance.expedite_cost or 0 ) end --- Components --- From game data if self.apiData.hardpoints ~= nil and type( self.apiData.hardpoints ) == 'table' and #self.apiData.hardpoints > 0 then local hardpoint = require( 'Module:VehicleHardpoint' ):new( self.frameArgs[ 'name' ] or mw.title.getCurrentTitle.fullText ) hardpoint:setHardPointObjects( self.apiData.hardpoints ) end end

return mw.smw.set( setData ) end

--- Extra Properties that are Vehicle (Type) Specific --- @param apiData table function methodtable.setExtraSemanticProperties( self, apiData )

end

--- Set the frame and load args --- @param frame table function methodtable.setFrame( self, frame ) self.currentFrame = frame self.frameArgs = require( 'Module:Arguments' ).getArgs( frame ) end

--- Save Api Data to SMW store function methodtable.saveApiData( self ) --- Used by getApiDataForCurrentPage and setSemanticProperties self.name = self.frameArgs[ 'name' ] or common.removeTypeSuffix(       mw.title.getCurrentTitle.rootText,        self.vehicleType    ) local data = self:getApiDataForCurrentPage

self:setSemanticProperties

return data end

--- New Instance --- @param type string Term used remove suffix from page title function vehicle.new( self, type ) if type == nil then error( 'Required argument "type" missing.' ) end

local instance = { vehicleType = type, categories = {} }

setmetatable( instance, metatable )

return instance end

return vehicle