extends Node2D

onready var level_state := get_tree().root.get_child(4).get_node("%LevelState")

func _ready() -> void:
	if(GlobalState.get_savepoint(level_state.levelName) == global_position + Vector2(0,18)):
		$Flag.material.set_shader_param("speed", 0.6)
		$Flag.material.set_shader_param("amplitude", 1)
		$Flag.material.set_shader_param("inclination", 1)
		$Flag.texture_offset = Vector2(0,0)

#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(level_state.levelName) == global_position + Vector2(0,18)):
		$AnimationPlayer.play("rolloutflag")
		$AudioStreamPlayer.play()
		GlobalState.set_savepoint(level_state.levelName, global_position + Vector2(0,18))
