extends CutScene
var _dialog_bubble = load("res://src/CutScenes/DialogBubble/DialogBubble.tscn")
var _old_man_dialog = [
	{
		"text": "Hi there young one!",
		"callback": null
	},
	{
		"text": "You do look stupid enough\nfor my challenge...",
		"callback": null
	},
	{
		"text": "You see that tree over there?",
		"callback": null
	},
	]
var _old_man_dialog2 = [
	{
		"text": "Oh, yeah - not there...",
		"callback": null
	},
	{
		"text": "Forgive me, never thought you would really take a look",
		"callback": null
	},
	{
		"text": "Never mind Bro. See the path ahead? There is a tree in that cave.",
		"callback": null
	},
	]

func start_scene(camera:CameraGame = null):
	_started = true;
	_main_camera_ref = camera
	position = camera.get_global_transform().get_origin()
	_camera = camera.duplicate()
	add_child(_camera)
	_main_camera_ref.current = false
	_camera.current = true
	
	$AnimationPlayer.play("start")
	yield($AnimationPlayer, "animation_finished")
	
	yield(get_tree().create_timer(.5), "timeout")
	
	
	# Dialog 1
	$AnimationPlayer.play("old_dude_slide_in")
	yield($AnimationPlayer, "animation_finished")
	
	var dialog_bubble:DialogBubble = _dialog_bubble.instance()
	dialog_bubble.dialog = _old_man_dialog
	$Overlay.add_child(dialog_bubble)
	dialog_bubble.start_dialog()
	yield(dialog_bubble, "dialog_finished")

	$AnimationPlayer.play("old_dude_slide_out")
	yield($AnimationPlayer, "animation_finished")
	
	# pan Camera
	$Tween.interpolate_property(_camera, "position", _camera.position, Vector2( _camera.position.x - 400, _camera.position.y), 2)
	$Tween.start()
	yield($Tween, "tween_completed")
	
	# wait a bit to get a "haha" timing
	yield(get_tree().create_timer(2), "timeout")
	
	#pan back
	$Tween.interpolate_property(_camera, "position", _camera.position, _camera.get_parent().position, 2, Tween.TRANS_BOUNCE, Tween.EASE_OUT)
	$Tween.start()
	yield($Tween, "tween_completed")
	camera.get_parent().boost(Vector2(0,-100))
	# Dialog 2
	$AnimationPlayer.play("old_dude_slide_in")
	yield($AnimationPlayer, "animation_finished")
	
	dialog_bubble = _dialog_bubble.instance()
	dialog_bubble.dialog = _old_man_dialog2
	$Overlay.add_child(dialog_bubble)
	dialog_bubble.start_dialog()
	yield(dialog_bubble, "dialog_finished")

	$AnimationPlayer.play("old_dude_slide_out")
	yield($AnimationPlayer, "animation_finished")
	
	#
	
	
	_on_scene_exited()
	pass
	
# func _input(event: InputEvent) -> void:
# 	if not _started: return
# 	if Input.is_action_just_pressed("jump"):
# 		if allow_skip: _on_scene_exited()

	
func _on_scene_exited():
	$Tween.interpolate_property(_camera, "position", _camera.position, _camera.get_parent().position, 2, Tween.TRANS_BOUNCE, Tween.EASE_OUT)
	$Tween.start()
	yield($Tween, "tween_completed")
	_main_camera_ref.current = true
	$AnimationPlayer.play_backwards("start")
	yield($AnimationPlayer, "animation_finished")
	end_scene()
