sokoban
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
extends CanvasLayer

onready var animate: AnimationPlayer = $animate
onready var progress = $Container/occluder/Progressbar
onready var tween = $Container/Tween
onready var fade = $fade
var queued = false

const distance = 150

signal startup_complete


func _ready():
	setup_curve(center($Container/occluder), $Container/Path)
	# sets up the curve with the return value from the centering of the occluder


func setup_curve(center, path):
	var curve := Curve2D.new()
	curve.clear_points()

	var top_left = center + Vector2(-distance, -distance)
	var bottom_left = center + Vector2(-distance, distance)
	var top_right = center + Vector2(distance, -distance)
	var bottom_right = center + Vector2(distance, distance)

	for corner in [top_left, top_right, bottom_right, bottom_left, top_left]:
		curve.add_point(corner)

	path.set_curve(curve)


func center(node):
	node.position = $Container.get_viewport_rect().size / 2
	return node.position


func startup():
	Utils._set_disable_inputs(true)
	fade.play("Fadein")
	animate.play("Animate")
	yield(fade, "animation_finished")
	emit_signal("startup_complete")
	increment_progress()


func exit():
	if tween.is_active():
		queued = true
		yield(tween, "tween_all_completed")
	tween_progress(progress.value, 100, Vector2(.1, .5))
	yield(tween, "tween_all_completed")
	fade.play("Fadeout")
	Utils._set_disable_inputs(false)


func _exit_tree():
	Utils._set_disable_inputs(false)


func tween_progress(old: float, new: float, length_range: Vector2):
	tween.interpolate_property(
		progress,
		"value",
		old,
		new,
		rand_range(length_range.x, length_range.y),
		Tween.TRANS_LINEAR,
		Tween.EASE_IN_OUT
	)
	tween.start()


func increment_progress():
	if not tween.is_active() and not queued:
		tween_progress(progress.value, progress.value + round(rand_range(5, 25)), Vector2(1, 2))