Module:Vehicle

local vehicle = {}

local metatable = {} local methodtable = {}

metatable.__index = methodtable

local common = require( 'Module:Common' ) local api = require( 'Module:Common/Api' ) local manufacturer = require( 'Module:Manufacturer' )._manufacturer

--- 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' ] = manufacturer( self.frameArgs[ 'manufacturer' ] ).name, [ 'Production state' ] = self.frameArgs[ 'productionstate' ], [ 'Role' ] = self.frameArgs[ 'role' ], [ 'Series' ] = self.frameArgs[ 'series' ], --- 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' ], --- Crew [ 'Minimum crew' ] = self.frameArgs[ 'mincrew' ], [ 'Maximum crew' ] = self.frameArgs[ 'maxcrew' ], --- Cargo [ 'Cargo capacity' ] = self.frameArgs[ 'cargocapacity' ], --- Speed [ 'SCM speed' ] = self.frameArgs[ 'combatspeed' ], [ 'Maximum speed' ] = self.frameArgs[ 'maxspeed' ], --- Dimensions [ 'Entity length' ] = self.frameArgs[ 'length' ], [ 'Entity width' ] = self.frameArgs[ 'width' ], [ 'Entity height' ] = self.frameArgs[ 'height' ], [ 'Retracted length' ] = self.frameArgs[ 'retractedlength' ], [ 'Retracted width' ] = self.frameArgs[ 'retractedwidth' ], [ 'Retracted height' ] = self.frameArgs[ 'retractedheight' ], [ 'Mass' ] = self.frameArgs[ 'mass' ], --- Lore [ 'Lore release date' ] = self.frameArgs[ 'releasedate' ], [ 'Lore retirement date' ] = self.frameArgs[ 'retiredate' ], --- Development [ 'Concept announcement date' ] = self.frameArgs[ 'conceptdate' ], [ 'Concept sale date' ] = self.frameArgs[ 'saledate' ], --- Official sites [ 'Galactapedia URL' ] = self.frameArgs[ 'galactapediaurl' ], [ 'Pledge store URL' ] = self.frameArgs[ 'rsistoreurl' ], [ 'Brochure URL' ] = self.frameArgs[ 'brochureurl' ], [ 'Trailer URL' ] = self.frameArgs[ 'trailerurl' ], [ 'Whitleys Guide URL' ] = self.frameArgs[ 'whitleysguideurl' ], }

-- Set properties with API data if self.apiData ~= nil then -- RSI website data setData[ 'Ship matrix name' ] = self.apiData.name setData[ 'Ship matrix size' ] = self.apiData.size -- Loaner vehicles local loaners = {} if type( self.apiData.loaner ) == 'table' then for _, loaner in pairs( self.apiData.loaner ) do				table.insert( loaners, string.format( '%s', loaner.name ) ) end end if #loaners > 0 then setData[ 'Loaner vehicle' ] = loaners end

-- Flight ready vehicles --- Override template parameter with in-game data if self.apiData.uuid ~= nil then setData[ 'UUID' ] = self.apiData.uuid setData[ 'Class name' ] = self.apiData.class_name setData[ 'Size' ] = self.apiData.size_class setData[ 'Mass' ] = self.apiData.mass setData[ 'Cargo capacity' ] = common.formatNum( self.apiData.cargo_capacity ) setData[ 'Vehicle inventory' ] = common.formatNum( self.apiData.vehicle_inventory ) 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 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