diff --git a/addons/beehave/debug/debugger.gd b/addons/beehave/debug/debugger.gd index 1ccd097f..246ecd2e 100644 --- a/addons/beehave/debug/debugger.gd +++ b/addons/beehave/debug/debugger.gd @@ -2,6 +2,8 @@ extends EditorDebuggerPlugin const DebuggerTab := preload("debugger_tab.gd") +const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd") + var debugger_tab := DebuggerTab.new() var floating_window: Window var session: EditorDebuggerSession diff --git a/addons/beehave/debug/debugger_tab.gd b/addons/beehave/debug/debugger_tab.gd index 64a081b1..c5257cfe 100644 --- a/addons/beehave/debug/debugger_tab.gd +++ b/addons/beehave/debug/debugger_tab.gd @@ -1,6 +1,10 @@ @tool class_name BeehaveDebuggerTab extends PanelContainer + +const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd") + + signal make_floating() const BeehaveGraphEdit := preload("graph_edit.gd") diff --git a/addons/beehave/debug/frames.gd b/addons/beehave/debug/frames.gd index 0fb6d2aa..6e310dbb 100644 --- a/addons/beehave/debug/frames.gd +++ b/addons/beehave/debug/frames.gd @@ -1,6 +1,10 @@ @tool extends RefCounted + +const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd") + + const SUCCESS_COLOR := Color("#009944c8") const NORMAL_COLOR := Color("#15181e") const FAILURE_COLOR := Color("#cf000f80") diff --git a/addons/beehave/debug/global_debugger.gd b/addons/beehave/debug/global_debugger.gd index 27c72c2d..c72382a9 100644 --- a/addons/beehave/debug/global_debugger.gd +++ b/addons/beehave/debug/global_debugger.gd @@ -1,7 +1,7 @@ extends Node var _registered_trees: Dictionary -var _active_tree: BeehaveTree +var _active_tree func _enter_tree() -> void: @@ -20,7 +20,7 @@ func _on_debug_message(message: String, data: Array) -> bool: func _set_active_tree(tree_id: int) -> void: - var tree: BeehaveTree = _registered_trees.get(tree_id, null) + var tree = _registered_trees.get(tree_id, null) if not tree: return @@ -30,9 +30,9 @@ func _set_active_tree(tree_id: int) -> void: _active_tree._can_send_message = true -func register_tree(tree: BeehaveTree) -> void: +func register_tree(tree) -> void: _registered_trees[tree.get_instance_id()] = tree -func unregister_tree(tree: BeehaveTree) -> void: +func unregister_tree(tree) -> void: _registered_trees.erase(tree.get_instance_id()) diff --git a/addons/beehave/debug/graph_node.gd b/addons/beehave/debug/graph_node.gd index a6975722..912fa781 100644 --- a/addons/beehave/debug/graph_node.gd +++ b/addons/beehave/debug/graph_node.gd @@ -1,6 +1,10 @@ @tool extends GraphNode + +const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd") + + const DEFAULT_COLOR := Color("#dad4cb") const PORT_TOP_ICON := preload("icons/port_top.svg") diff --git a/addons/beehave/debug/tree_node.gd b/addons/beehave/debug/tree_node.gd index 6c104d85..81cab813 100644 --- a/addons/beehave/debug/tree_node.gd +++ b/addons/beehave/debug/tree_node.gd @@ -6,6 +6,8 @@ extends RefCounted const SIBLING_DISTANCE: float = 20.0 const LEVEL_DISTANCE: float = 40.0 +const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd") + var x: float var y: float var mod: float diff --git a/addons/beehave/metrics/beehave_global_metrics.gd b/addons/beehave/metrics/beehave_global_metrics.gd index 9a2ba4a5..59720b0a 100644 --- a/addons/beehave/metrics/beehave_global_metrics.gd +++ b/addons/beehave/metrics/beehave_global_metrics.gd @@ -2,7 +2,7 @@ extends Node var _tree_count: int = 0 var _active_tree_count: int = 0 -var _registered_trees: Array[BeehaveTree] = [] +var _registered_trees: Array = [] func _enter_tree() -> void: @@ -10,7 +10,7 @@ func _enter_tree() -> void: Performance.add_custom_monitor("beehave/total_enabled_trees", _get_total_enabled_trees) -func register_tree(tree: BeehaveTree) -> void: +func register_tree(tree) -> void: if _registered_trees.has(tree): return @@ -24,7 +24,7 @@ func register_tree(tree: BeehaveTree) -> void: tree.tree_disabled.connect(_on_tree_disabled) -func unregister_tree(tree: BeehaveTree) -> void: +func unregister_tree(tree) -> void: if not _registered_trees.has(tree): return diff --git a/addons/beehave/nodes/beehave_tree.gd b/addons/beehave/nodes/beehave_tree.gd index 4e0a30ff..fbb9817e 100644 --- a/addons/beehave/nodes/beehave_tree.gd +++ b/addons/beehave/nodes/beehave_tree.gd @@ -88,12 +88,12 @@ signal tree_disabled custom_monitor = b if custom_monitor and _process_time_metric_name != '': Performance.add_custom_monitor(_process_time_metric_name, _get_process_time_metric_value) - BeehaveGlobalMetrics.register_tree(self) + _get_global_metrics().register_tree(self) else: if _process_time_metric_name != '': # Remove tree metric from the engine Performance.remove_custom_monitor(_process_time_metric_name) - BeehaveGlobalMetrics.unregister_tree(self) + _get_global_metrics().unregister_tree(self) BeehaveDebuggerMessages.unregister_tree(get_instance_id()) @@ -138,12 +138,12 @@ func _ready() -> void: # Register custom metric to the engine if custom_monitor and not Engine.is_editor_hint(): Performance.add_custom_monitor(_process_time_metric_name, _get_process_time_metric_value) - BeehaveGlobalMetrics.register_tree(self) + _get_global_metrics().register_tree(self) if Engine.is_editor_hint(): update_configuration_warnings.call_deferred() else: - BeehaveGlobalDebugger.register_tree(self) + _get_global_debugger().register_tree(self) BeehaveDebuggerMessages.register_tree(_get_debugger_data(self)) # Randomize at what frames tick() will happen to avoid stutters @@ -266,7 +266,7 @@ func _exit_tree() -> void: if _process_time_metric_name != '': # Remove tree metric from the engine Performance.remove_custom_monitor(_process_time_metric_name) - BeehaveGlobalMetrics.unregister_tree(self) + _get_global_metrics().unregister_tree(self) BeehaveDebuggerMessages.unregister_tree(get_instance_id()) @@ -291,3 +291,15 @@ func _get_debugger_data(node: Node) -> Dictionary: func get_class_name() -> Array[StringName]: return [&"BeehaveTree"] + + +# required to avoid lifecycle issues on initial load +# due to loading order problems with autoloads +func _get_global_metrics() -> Node: + return get_tree().root.get_node("BeehaveGlobalMetrics") + + +# required to avoid lifecycle issues on initial load +# due to loading order problems with autoloads +func _get_global_debugger() -> Node: + return get_tree().root.get_node("BeehaveGlobalDebugger") diff --git a/addons/beehave/plugin.gd b/addons/beehave/plugin.gd index 71130fce..66601b2d 100644 --- a/addons/beehave/plugin.gd +++ b/addons/beehave/plugin.gd @@ -11,7 +11,6 @@ func _init(): add_autoload_singleton("BeehaveGlobalDebugger", "debug/global_debugger.gd") print("Beehave initialized!") - func _enter_tree() -> void: editor_debugger = BeehaveEditorDebugger.new() frames = preload("debug/frames.gd").new() diff --git a/addons/beehave/utils/utils.gd b/addons/beehave/utils/utils.gd index 32e3a03e..491f78b5 100644 --- a/addons/beehave/utils/utils.gd +++ b/addons/beehave/utils/utils.gd @@ -1,6 +1,4 @@ @tool -class_name BeehaveUtils - static func get_plugin() -> EditorPlugin: var tree: SceneTree = Engine.get_main_loop()