Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register trees in debugger tab again when added back to scene #344

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions addons/beehave/nodes/beehave_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ var _can_send_message: bool = false


func _ready() -> void:
get_tree().node_added.connect(_on_scene_tree_node_added_removed.bind(true))
get_tree().node_removed.connect(_on_scene_tree_node_added_removed.bind(false))
var connect_scene_tree_signal = func(signal_name: String, is_added: bool):
if not get_tree().is_connected(signal_name, _on_scene_tree_node_added_removed.bind(is_added)):
get_tree().connect(signal_name, _on_scene_tree_node_added_removed.bind(is_added))
connect_scene_tree_signal.call("node_added", true)
connect_scene_tree_signal.call("node_removed", false)

if not process_thread:
process_thread = ProcessThread.PHYSICS
Expand Down Expand Up @@ -156,7 +159,9 @@ func _on_scene_tree_node_added_removed(node: Node, is_added: bool) -> void:
)
else:
sgnal.connect(
func() -> void: BeehaveDebuggerMessages.unregister_tree(get_instance_id())
func() -> void:
BeehaveDebuggerMessages.unregister_tree(get_instance_id())
request_ready()
)


Expand Down
16 changes: 15 additions & 1 deletion examples/beehave_test_scene.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
extends Node2D

@onready var sprite := $ColorChangingSprite
@onready var another_sprite := $AnotherSprite
@onready var tree := %BeehaveTree
@onready var condition_label := %ConditionLabel
@onready var action_label := %ActionLabel


func _process(delta:float) -> void:
if Input.is_action_pressed("ui_left"):
sprite.position.x -= 200 * delta
Expand All @@ -28,3 +28,17 @@ func _process(delta:float) -> void:
action_label.text = str(tree.get_running_action(), " -> RUNNING")
else:
action_label.text = "no running action"

# The following are used to verify if the beehave trees show up or get
# removed from the debug panel when various scene operations occur.
if Input.is_action_just_pressed("ui_text_delete") and another_sprite.is_inside_tree():
another_sprite.get_parent().remove_child(another_sprite)

if Input.is_action_just_pressed("ui_accept") and not another_sprite.is_inside_tree():
add_child(another_sprite)

if Input.is_action_just_pressed("ui_undo"):
get_tree().reload_current_scene()

if Input.is_action_just_pressed("ui_cut"):
another_sprite.reparent(get_node("Background"))
Loading