@tool
extends Node

const Utils = preload("res://utils.gd")
var simulation_started
var tag_group = "TagGroup0"
@onready var UL1_3: BeltConveyorAssembly = $"../UL1_3"
@onready var box_spawner: BoxSpawner = $"../BoxSpawner"


func _enter_tree() -> void:
	SimulationEvents.simulation_started.connect(_simulation_started)
	SimulationEvents.simulation_ended.connect(_simulation_ended)
	

func _simulation_started():
	print("Started !")
	simulation_started = true
	
	OIPComms.register_tag(tag_group, "UL1_3_VFD1.CTRL.STS.Log.LEN", 1)
	for i in range(82):
		var data_tag = "UL1_3_VFD1.CTRL.STS.Log.DATA[" + str(i) + "]"
		OIPComms.register_tag(tag_group, data_tag, 1)
	pass
	
	
func _simulation_ended():
	simulation_started = false
	print("Stopped !")
	

func _physics_process(delta: float) -> void:
	if(!simulation_started):
		return
	
	box_spawner.disable = UL1_3.speed == 0
	print("Log String: ", Utils.read_string(tag_group, "UL1_3_VFD1.CTRL.STS.Log"))
