forked from farfalk/gd-YAFSM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StackPlayerDebugger.gd
50 lines (41 loc) · 1.41 KB
/
StackPlayerDebugger.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
tool
extends Control
const StackPlayer = preload("../StackPlayer.gd")
const StackItem = preload("StackItem.tscn")
onready var Stack = $MarginContainer/Stack
func _get_configuration_warning():
if not (get_parent() is StackPlayer):
return "Debugger must be child of StackPlayer"
return ""
func _ready():
if Engine.editor_hint:
return
get_parent().connect("pushed", self, "_on_StackPlayer_pushed")
get_parent().connect("popped", self, "_on_StackPlayer_popped")
sync_stack()
# Override to handle custom object presentation
func _on_set_label(label, obj):
label.text = obj
func _on_StackPlayer_pushed(to):
var stack_item = StackItem.instance()
_on_set_label(stack_item.get_node("Label"), to)
Stack.add_child(stack_item)
Stack.move_child(stack_item, 0)
func _on_StackPlayer_popped(from):
# Sync whole stack instead of just popping top item, as ResetEventTrigger passed to reset() may be varied
sync_stack()
func sync_stack():
var diff = Stack.get_child_count() - get_parent().stack.size()
for i in abs(diff):
if diff < 0:
var stack_item = StackItem.instance()
Stack.add_child(stack_item)
else:
var child = Stack.get_child(0)
Stack.remove_child(child)
child.queue_free()
var stack = get_parent().stack
for i in stack.size():
var obj = stack[stack.size()-1 - i] # Descending order, to list from bottom to top in VBoxContainer
var child = Stack.get_child(i)
_on_set_label(child.get_node("Label"), obj)