extends Node3D
class_name SensorSpawner

@export var sensor_scene: PackedScene
var vehicle: VehicleNode

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	vehicle = get_parent()
	SensorSignals.new_sensor_connected.connect(_on_new_sensor_connected)

func _on_new_sensor_connected(sensor_ip: String, provider_data: Array) -> void:
	var sensor_suite = sensor_scene.instantiate()
	sensor_suite.ip_address = sensor_ip
	vehicle.sensor_suites[sensor_ip] = sensor_suite
	if provider_data[0]:
		sensor_suite.provides_pnt = true
		sensor_suite.create_pnt()
		sensor_suite.create_sats()
	if provider_data[1]:
		sensor_suite.provides_accel = true
		sensor_suite.create_accel()
	if provider_data[2]:
		sensor_suite.provides_gyro = true
		sensor_suite.create_gyro()
	if provider_data[3]:
		sensor_suite.provides_mag = true
		sensor_suite.create_mag()
	add_child(sensor_suite)
	vehicle.add_sensor_node(sensor_suite)
