extends Node2D

onready var levelState := get_tree().root.get_child(3).get_node("%LevelState")

func _ready() -> void:
	if(GlobalState.get_savepoint(levelState.levelName) == global_position + Vector2(0,18)):
		$AnimationPlayer.play("rolloutflag")

#TODO Animation plays over again on reset
#TODO What should be saved when reaching a savepoint besides the position in the level
func _on_SaveArea_area_entered(area: Area2D) -> void:
	#TODO Spawnheight fixed
	if(!GlobalState.get_savepoint(levelState.levelName) == global_position + Vector2(0,18)):
		$AnimationPlayer.play("rolloutflag")
		GlobalState.set_savepoint(levelState.levelName, global_position + Vector2(0,18))
