-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStatesDefiner.gd
55 lines (44 loc) · 1.2 KB
/
StatesDefiner.gd
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
extends Node
class_name StatesDefiner
static var state :String
var visible_objects :Array
@onready var tween: Tween = null
func _ready():
var s :String = SaveData.save_handler.get_value("player_state", "first_room")
update_state(s, false)
func set_visible_objects():
pass
func update_state(set_to: String, transition := true):
SaveData.save_handler.save_value("player_state", set_to)
if set_to == StatesDefiner.state:
return
StatesDefiner.state = set_to
set_visible_objects()
if not tween == null:
tween.stop()
tween.kill()
tween = create_tween()
tween.set_parallel(true)
var tweened := false
for child in get_tree().get_nodes_in_group("World")[0].get_children():
if not child is Node2D:
continue
if child in visible_objects:
child.visible = true
if transition:
tween.tween_property(child, "modulate:a", 1.0, 0.5)
tweened = true
else:
child.modulate.a = 1.0
else:
if transition:
tween.tween_property(child, "modulate:a", 0.0, 0.5)
tween.tween_property(child, "visible", false, 1.0)
tweened = true
else:
child.modulate.a = 0.0
child.visible = false
if not tweened:
tween.kill()
func _on_area_transitioned(to: String) -> void:
update_state(to)