extends Node2D

## Tween Demo: Playground for testing transition curves and parallel/sequential logic

var start_pos = Vector2(50, 150)
var end_pos = Vector2(350, 150)

# A custom variable we will tween!
var score_variable: int = 0:
	set(value):
		score_variable = value
		$VariableLabel.text = "Score: %d" % score_variable

func _ready():
	reset_sprite()
	
	$BtnLinear.pressed.connect(_on_linear)
	$BtnBounce.pressed.connect(_on_bounce)
	$BtnSequential.pressed.connect(_on_sequential)
	$BtnParallel.pressed.connect(_on_parallel)
	$BtnVariable.pressed.connect(_on_variable)
	$BtnReset.pressed.connect(reset_sprite)

func reset_sprite():
	$Sprite2D.position = start_pos
	$Sprite2D.scale = Vector2(1, 1)
	$Sprite2D.modulate.a = 1.0
	score_variable = 0

func _on_linear():
	reset_sprite()
	var tween = create_tween()
	# Default is TRANS_LINEAR, EASE_IN_OUT
	tween.tween_property($Sprite2D, "position", end_pos, 1.0)

func _on_bounce():
	reset_sprite()
	var tween = create_tween()
	tween.tween_property($Sprite2D, "position", end_pos, 1.0)\
		.set_trans(Tween.TRANS_BOUNCE)\
		.set_ease(Tween.EASE_OUT)

func _on_sequential():
	reset_sprite()
	var tween = create_tween()
	# Step 1: Move
	tween.tween_property($Sprite2D, "position", end_pos, 1.0)\
		.set_trans(Tween.TRANS_SINE)
	# Step 2: Fade out (waits for Step 1 to finish)
	tween.tween_property($Sprite2D, "modulate:a", 0.0, 1.0)

func _on_parallel():
	reset_sprite()
	var tween = create_tween()
	tween.set_parallel(true) # Everything below happens at the same time
	
	tween.tween_property($Sprite2D, "position", end_pos, 1.0)\
		.set_trans(Tween.TRANS_SINE)
	
	tween.tween_property($Sprite2D, "modulate:a", 0.0, 1.0)

func _on_variable():
	reset_sprite()
	var tween = create_tween()
	# We are tweening the "score_variable" property on THIS script (self)
	# The setter function automatically updates the label!
	tween.tween_property(self, "score_variable", 1000, 2.0)\
		.set_trans(Tween.TRANS_EXPO)\
		.set_ease(Tween.EASE_OUT)
