Module:Vehicle

local vehicle = {}

local metatable = {} local methodtable = {}

metatable.__index = methodtable

local common = require( 'Module:Common' )

--- Request Api Data --- Using current subpage name without vehicle type suffix --- @return table function methodtable.getApiDataForCurrentPage( self ) local name = self.frameArgs[ 'name' ] or common.removeTypeSuffix(       mw.title.getCurrentTitle.rootText,        self.vehicleType    )

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

common.checkApiResponse( json, true, false )

self.apiData = json[ 'data' ]

return self.apiData end

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

common.checkSmwResult( self:setBaseSemanticProperties ) end

--- Base Properties that are shared across all Vehicles --- @return table SMW Result function methodtable.setBaseSemanticProperties( self ) -- Api Error, don't set anything if self.apiData == nil then return end

local setData = { [ 'UUID' ] = self.apiData.uuid, [ 'Mass' ] = self.apiData.mass, [ 'Cargo capacity' ] = common.formatNum( self.apiData.cargo_capacity ) }

local result = mw.smw.set( setData )

return result 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 ) local data = self:getApiDataForCurrentPage

self:setSemanticProperties

return data end

--- New Instance function vehicle.new( self, type, apiMethod ) if type == nil then error( 'Required argument "type" missing.' ) end

if apiMethod == nil then error( 'Required argument "apiMethod" missing.' ) end

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

setmetatable( instance, metatable )

return instance end

return vehicle