TinyAdventure/ui/debug/behaviour.gd

32 lines
1.0 KiB
GDScript

extends MarginContainer
@onready var npc_name_edit: LineEdit = %NPCNameEdit
@onready var behavior_debug_view: BehaviorTreeView = %BehaviorDebugView
var _debug_bt_player:BTPlayer = null
func _process(_delta: float) -> void:
if _debug_bt_player == null:
return
var instance: BTInstance = _debug_bt_player.get_bt_instance()
var data: BehaviorTreeData = BehaviorTreeData.create_from_bt_instance(instance)
behavior_debug_view.update_tree(data)
func _on_search_button_pressed() -> void:
_on_npc_name_edit_text_submitted(npc_name_edit.text)
func _on_npc_name_edit_text_submitted(new_text: String) -> void:
npc_name_edit.release_focus()
var npc_node:NonPlayerCharacter = get_tree().root.find_child(new_text, true, false) as NonPlayerCharacter
if not is_instance_valid(npc_node):
push_error("Cannot show npc behavior: could not find node with name '%s'." % new_text)
return
_debug_bt_player = npc_node.find_child("BTPlayer") as BTPlayer
if _debug_bt_player == null:
behavior_debug_view.clear()
push_error("Cannot show npc behavior: no BTPlayer found.")