class_name PilotUseCase extends RefCounted const VehicleCommand = preload("res://game/application/vehicle/vehicle_command.gd") const VehicleCommandResult = preload( "res://game/application/vehicle/vehicle_command_result.gd" ) const VehicleMotionPort = preload("res://game/application/interfaces/vehicle_motion_port.gd") var _motion_port: VehicleMotionPort var _last_sequence := -1 func _init(motion_port: VehicleMotionPort) -> void: _motion_port = motion_port func execute(command: VehicleCommand) -> VehicleCommandResult: if command == null: return VehicleCommandResult.new(false, -1, "vehicle command is missing") var error: String = command.validation_error() if not error.is_empty(): return VehicleCommandResult.new(false, command.sequence, error) if command.sequence != _last_sequence + 1: return VehicleCommandResult.new( false, command.sequence, "vehicle command sequence is not consecutive" ) _motion_port.apply_command(command) _last_sequence = command.sequence return VehicleCommandResult.new(true, command.sequence)