extends Node2D
class_name BaseWidgetNode

var sensor_class: String
var used_sensors: Dictionary = {}

var host_vehicle: VehicleNode

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	Signals.vehicle_added.connect(_on_vehicle_added)
	Signals.requested_host_vehicle.emit(self)

func _process(delta: float):
	if host_vehicle != null:
		return
	Signals.requested_host_vehicle.emit(self)

func _on_vehicle_added(new_vehicle):
	host_vehicle = new_vehicle

func set_host_vehicle(new_vehicle):
	host_vehicle = new_vehicle

func check_valid_sensor(sensor_ip: String, sensor_class: String):
	if host_vehicle == null:
		return false
	if sensor_ip not in host_vehicle.sensor_suites:
		return false
	if sensor_class == null:
		return true
	if sensor_class not in host_vehicle.sensor_classes:
		return false
	if sensor_ip not in host_vehicle.sensor_classes[sensor_class]:
		return false
	return true
