extends Node2D

@onready var player = get_parent()
@onready var sprite = player.find_child("Sprite")
@export var tracking = false
var active = false
@export var finished = false

@export var saved = []

#func _ready():
	#await get_tree().create_timer(30).timeout
	#finished = true

func track():
	saved.append(gen.getCurrentActions())

func _physics_process(_delta):
	if tracking:
		track()
	
	if finished:
		print("TIME!!!!")
		var dict = {"actions": [], "data": {}}
		
		for frameNumb in len(saved):
			var frame = saved[frameNumb]
			for action in frame:
				if not action in dict.actions:
					dict.actions.append(action)
				var actID = dict.actions.find(action)
				if not frameNumb in dict.data:
					dict.data[frameNumb] = {}
				dict.data[frameNumb][actID] = frame[action]
		
		dict.data[saved.size() - 1] = {}
		
		var packed = PackedDataContainer.new()
		packed.pack(dict)
		ResourceSaver.save(packed, "ghostRecording.res")
		
		queue_free()
