From 75e3b98f67f24cadeb96d8e5d3baccd6ee70eeb9 Mon Sep 17 00:00:00 2001 From: Rawshark Date: Fri, 24 Jul 2026 12:21:50 +0800 Subject: [PATCH] fix singleton confiict in godot 4.7.1 --- addons/beehave/debug/debugger.gd | 24 +++---- addons/beehave/debug/debugger_tab.gd | 46 +++++++------- addons/beehave/debug/new_frames.gd | 41 +++--------- addons/beehave/debug/new_graph_node.gd | 4 +- addons/beehave/debug/old_frames.gd | 24 ++----- addons/beehave/debug/old_graph_node.gd | 8 +-- addons/beehave/debug/tree_node.gd | 4 +- addons/beehave/nodes/beehave_tree.gd | 18 +++--- .../nodes/composites/simple_parallel.gd | 2 +- addons/beehave/nodes/decorators/repeater.gd | 2 +- addons/beehave/plugin.cfg | 2 +- addons/beehave/plugin.gd | 63 +++++++++++-------- addons/beehave/utils/utils.gd | 28 ++++----- 13 files changed, 116 insertions(+), 150 deletions(-) diff --git a/addons/beehave/debug/debugger.gd b/addons/beehave/debug/debugger.gd index adb67320..73b4ae54 100644 --- a/addons/beehave/debug/debugger.gd +++ b/addons/beehave/debug/debugger.gd @@ -2,13 +2,16 @@ extends EditorDebuggerPlugin const DebuggerTab := preload("debugger_tab.gd") -const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd") - -var debugger_tab := DebuggerTab.new() +# const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd") +var debugger_tab := BeehaveDebuggerTab.new() var floating_window: Window var session: EditorDebuggerSession +func _init(f: RefCounted) -> void: + debugger_tab.frame = f + + func _has_capture(prefix: String) -> bool: return prefix == "beehave" @@ -51,25 +54,18 @@ func _setup_session(session_id: int) -> void: func _on_make_floating() -> void: - var plugin := BeehaveUtils.get_plugin() - if not plugin: - return if floating_window: _on_window_close_requested() return - var border_size := Vector2(4, 4) * BeehaveUtils.get_editor_scale() - var editor_interface: EditorInterface = plugin.get_editor_interface() - var editor_main_screen = editor_interface.get_editor_main_screen() + var border_size := Vector2(4, 4) * EditorInterface.get_editor_scale() + var editor_main_screen = EditorInterface.get_editor_main_screen() debugger_tab.get_parent().remove_child(debugger_tab) floating_window = Window.new() var panel := Panel.new() - panel.add_theme_stylebox_override( - "panel", - editor_interface.get_base_control().get_theme_stylebox("PanelForeground", "EditorStyles") - ) + panel.add_theme_stylebox_override("panel", EditorInterface.get_base_control().get_theme_stylebox("PanelForeground", "EditorStyles")) panel.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) floating_window.add_child(panel) @@ -89,7 +85,7 @@ func _on_make_floating() -> void: floating_window.position = editor_main_screen.global_position floating_window.transient = true floating_window.close_requested.connect(_on_window_close_requested) - editor_interface.get_base_control().add_child(floating_window) + EditorInterface.get_base_control().add_child(floating_window) func _on_window_close_requested() -> void: diff --git a/addons/beehave/debug/debugger_tab.gd b/addons/beehave/debug/debugger_tab.gd index f49eca5a..5812cc7c 100644 --- a/addons/beehave/debug/debugger_tab.gd +++ b/addons/beehave/debug/debugger_tab.gd @@ -2,10 +2,10 @@ class_name BeehaveDebuggerTab extends PanelContainer -const Utils = preload("res://addons/beehave/utils/utils.gd") -const TREE_ICON = preload("../icons/tree.svg") -const OldGraph = preload("old_graph_edit.gd") -const NewGraph = preload("new_graph_edit.gd") +# const Utils = preload("res://addons/beehave/utils/utils.gd") +const TREE_ICON = preload("../icons/tree.svg") +const OldGraph = preload("old_graph_edit.gd") +const NewGraph = preload("new_graph_edit.gd") const Blackboard = preload("new_node_blackboard.gd") signal make_floating @@ -14,7 +14,6 @@ var session: EditorDebuggerSession var first_run = true var active_trees = {} var active_tree_id = -1 - # UI nodes var container: HSplitContainer var item_list: ItemList @@ -22,6 +21,8 @@ var graph_container: HSplitContainer var graph var blackboard_vbox: VBoxContainer var message: Label +static var frame: RefCounted + func _ready() -> void: _build_ui() @@ -62,17 +63,16 @@ func _build_ui() -> void: message = Label.new() message.text = "Run Project for debugging" message.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER - message.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + message.vertical_alignment = VERTICAL_ALIGNMENT_CENTER message.set_anchors_preset(Control.PRESET_CENTER) add_child(message) func _init_graph() -> void: - var frames = Utils.get_frames() if Engine.get_version_info().minor >= 2: - graph = NewGraph.new(frames) + graph = NewGraph.new(frame) else: - graph = OldGraph.new(frames) + graph = OldGraph.new(frame) # Graph on the left, blackboard (index 1) on the right graph.node_selected.connect(_on_graph_node_selected) @@ -87,9 +87,7 @@ func _init_graph() -> void: float_btn.flat = true float_btn.focus_mode = Control.FOCUS_NONE float_btn.icon = get_theme_icon("ExternalLink", "EditorIcons") - float_btn.pressed.connect(func(): - emit_signal("make_floating") - ) + float_btn.pressed.connect(func(): emit_signal("make_floating")) graph.get_menu_container().add_child(float_btn) # "Toggle Panel" button @@ -98,10 +96,11 @@ func _init_graph() -> void: toggle_btn.flat = true toggle_btn.focus_mode = Control.FOCUS_NONE toggle_btn.icon = get_theme_icon("Back", "EditorIcons") - toggle_btn.pressed.connect(func(): - item_list.visible = not item_list.visible - var icon_name = "Back" if item_list.visible else "Forward" - toggle_btn.icon = get_theme_icon(icon_name, "EditorIcons") + toggle_btn.pressed.connect( + func(): + item_list.visible = not item_list.visible + var icon_name = "Back" if item_list.visible else "Forward" + toggle_btn.icon = get_theme_icon(icon_name, "EditorIcons") ) graph.get_menu_container().add_child(toggle_btn) graph.get_menu_container().move_child(toggle_btn, 0) @@ -109,7 +108,7 @@ func _init_graph() -> void: func start() -> void: container.visible = true - message.visible = false + message.visible = false if first_run: first_run = false @@ -117,7 +116,7 @@ func start() -> void: get_tree().create_timer(delay).timeout.connect(_notify_state) else: _notify_state() - + # Auto-detach if enabled in project settings - check every time if ProjectSettings.get_setting("beehave/debugger/start_detached", false): emit_signal("make_floating") @@ -133,7 +132,7 @@ func _notify_state() -> void: func stop() -> void: container.visible = false - message.visible = true + message.visible = true active_trees.clear() item_list.clear() graph.beehave_tree = {} @@ -172,9 +171,10 @@ func _select_item_by_id(id_str: String) -> void: if item_list.get_item_metadata(i) == id_str: item_list.select(i) break - get_tree().create_timer(0.2).timeout.connect(func(): - if item_list.is_inside_tree() and not item_list.get_selected_items().is_empty(): - _on_item_selected(item_list.get_selected_items()[0]) + get_tree().create_timer(0.2).timeout.connect( + func(): + if item_list.is_inside_tree() and not item_list.get_selected_items().is_empty(): + _on_item_selected(item_list.get_selected_items()[0]) ) @@ -201,7 +201,7 @@ func _on_graph_node_selected(node: GraphNode) -> void: for child in blackboard_vbox.get_children(): child.free() blackboard_vbox.show() - blackboard_vbox.add_child(Blackboard.new(Utils.get_frames(), node)) + blackboard_vbox.add_child(Blackboard.new(frame, node)) func _on_graph_node_deselected(node: GraphNode) -> void: diff --git a/addons/beehave/debug/new_frames.gd b/addons/beehave/debug/new_frames.gd index 4b739fdd..6fd65b49 100644 --- a/addons/beehave/debug/new_frames.gd +++ b/addons/beehave/debug/new_frames.gd @@ -1,10 +1,8 @@ @tool extends RefCounted - const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd") - const SUCCESS_COLOR := Color("#07783a") const NORMAL_COLOR := Color("#15181e") const FAILURE_COLOR := Color("#82010b") @@ -22,48 +20,25 @@ var titlebar_running: StyleBoxFlat func _init() -> void: - var plugin := BeehaveUtils.get_plugin() - if not plugin: - return - - - titlebar_normal = ( - plugin - .get_editor_interface() - .get_base_control() - .get_theme_stylebox(&"titlebar", &"GraphNode")\ - .duplicate() - ) + + titlebar_normal = (EditorInterface.get_base_control().get_theme_stylebox(&"titlebar", &"GraphNode").duplicate()) titlebar_success = titlebar_normal.duplicate() titlebar_failure = titlebar_normal.duplicate() titlebar_running = titlebar_normal.duplicate() - + titlebar_success.bg_color = SUCCESS_COLOR titlebar_failure.bg_color = FAILURE_COLOR titlebar_running.bg_color = RUNNING_COLOR - + titlebar_success.border_color = SUCCESS_COLOR titlebar_failure.border_color = FAILURE_COLOR titlebar_running.border_color = RUNNING_COLOR - - - panel_normal = ( - plugin - .get_editor_interface() - .get_base_control() - .get_theme_stylebox(&"panel", &"GraphNode") - .duplicate() - ) - panel_success = ( - plugin - .get_editor_interface() - .get_base_control() - .get_theme_stylebox(&"panel_selected", &"GraphNode") - .duplicate() - ) + + panel_normal = (EditorInterface.get_base_control().get_theme_stylebox(&"panel", &"GraphNode").duplicate()) + panel_success = (EditorInterface.get_base_control().get_theme_stylebox(&"panel_selected", &"GraphNode").duplicate()) panel_failure = panel_success.duplicate() panel_running = panel_success.duplicate() - + panel_success.border_color = SUCCESS_COLOR panel_failure.border_color = FAILURE_COLOR panel_running.border_color = RUNNING_COLOR diff --git a/addons/beehave/debug/new_graph_node.gd b/addons/beehave/debug/new_graph_node.gd index 985054c1..979f3a6b 100644 --- a/addons/beehave/debug/new_graph_node.gd +++ b/addons/beehave/debug/new_graph_node.gd @@ -55,7 +55,7 @@ func _init(frames:RefCounted, horizontal: bool = false) -> void: func _ready() -> void: - custom_minimum_size = Vector2(50, 50) * BeehaveUtils.get_editor_scale() + custom_minimum_size = Vector2(50, 50) * EditorInterface.get_editor_scale() draggable = false add_theme_color_override("close_color", Color.TRANSPARENT) @@ -189,4 +189,4 @@ func _set_stylebox_overrides(panel_stylebox: StyleBox, titlebar_stylebox: StyleB func _on_size_changed(): - add_theme_constant_override("port_offset", 12 * BeehaveUtils.get_editor_scale() if horizontal else round(size.x)) + add_theme_constant_override("port_offset", 12 * EditorInterface.get_editor_scale() if horizontal else round(size.x)) diff --git a/addons/beehave/debug/old_frames.gd b/addons/beehave/debug/old_frames.gd index a9f6aa8f..1d694b33 100644 --- a/addons/beehave/debug/old_frames.gd +++ b/addons/beehave/debug/old_frames.gd @@ -16,29 +16,13 @@ var running: StyleBoxFlat func _init() -> void: - var plugin := BeehaveUtils.get_plugin() - if not plugin: - return - - var editor_scale := BeehaveUtils.get_editor_scale() + var editor_scale := EditorInterface.get_editor_scale() empty = StyleBoxEmpty.new() - normal = ( - plugin - . get_editor_interface() - . get_base_control() - . get_theme_stylebox(&"frame", &"GraphNode") - . duplicate() - ) - - success = ( - plugin - . get_editor_interface() - . get_base_control() - . get_theme_stylebox(&"selected_frame", &"GraphNode") - . duplicate() - ) + normal = (EditorInterface.get_base_control().get_theme_stylebox(&"frame", &"GraphNode").duplicate()) + + success = (EditorInterface.get_base_control().get_theme_stylebox(&"selected_frame", &"GraphNode").duplicate()) failure = success.duplicate() running = success.duplicate() diff --git a/addons/beehave/debug/old_graph_node.gd b/addons/beehave/debug/old_graph_node.gd index 28503b19..200cf876 100644 --- a/addons/beehave/debug/old_graph_node.gd +++ b/addons/beehave/debug/old_graph_node.gd @@ -48,7 +48,7 @@ func _init(frames: RefCounted, horizontal: bool = false) -> void: func _ready() -> void: - custom_minimum_size = Vector2(50, 50) * BeehaveUtils.get_editor_scale() + custom_minimum_size = Vector2(50, 50) * EditorInterface.get_editor_scale() draggable = false add_theme_stylebox_override("frame", frames.empty if frames != null else null) @@ -67,10 +67,10 @@ func _ready() -> void: var vbox_container := VBoxContainer.new() panel.add_child(vbox_container) - var title_size := 24 * BeehaveUtils.get_editor_scale() + var title_size := 24 * EditorInterface.get_editor_scale() var margin_container := MarginContainer.new() margin_container.add_theme_constant_override( - "margin_top", -title_size - 2 * BeehaveUtils.get_editor_scale() + "margin_top", -title_size - 2 * EditorInterface.get_editor_scale() ) margin_container.mouse_filter = Control.MOUSE_FILTER_PASS vbox_container.add_child(margin_container) @@ -162,5 +162,5 @@ func set_output_color(color: Color) -> void: func _on_size_changed(): add_theme_constant_override( - "port_offset", 12 * BeehaveUtils.get_editor_scale() if horizontal else round(size.x / 2.0) + "port_offset", 12 * EditorInterface.get_editor_scale() if horizontal else round(size.x / 2.0) ) diff --git a/addons/beehave/debug/tree_node.gd b/addons/beehave/debug/tree_node.gd index 13779706..1943fc58 100644 --- a/addons/beehave/debug/tree_node.gd +++ b/addons/beehave/debug/tree_node.gd @@ -260,7 +260,7 @@ func _calculate_x(node: TreeNode, offset: int) -> void: sibling = sibling.get_next_sibling() for child in node.children: - _calculate_x(child, max_size + offset + LEVEL_DISTANCE * BeehaveUtils.get_editor_scale()) + _calculate_x(child, max_size + offset + LEVEL_DISTANCE * EditorInterface.get_editor_scale()) func _calculate_y(node: TreeNode, offset: int) -> void: @@ -272,4 +272,4 @@ func _calculate_y(node: TreeNode, offset: int) -> void: sibling = sibling.get_next_sibling() for child in node.children: - _calculate_y(child, max_size + offset + LEVEL_DISTANCE * BeehaveUtils.get_editor_scale()) + _calculate_y(child, max_size + offset + LEVEL_DISTANCE * EditorInterface.get_editor_scale()) diff --git a/addons/beehave/nodes/beehave_tree.gd b/addons/beehave/nodes/beehave_tree.gd index d73caaf2..f3d81e74 100644 --- a/addons/beehave/nodes/beehave_tree.gd +++ b/addons/beehave/nodes/beehave_tree.gd @@ -33,8 +33,10 @@ signal tree_disabled @export_node_path var actor_node_path: NodePath: set(anp): actor_node_path = anp - if is_inside_tree(): - _resolve_actor() + if actor_node_path != null and str(actor_node_path) != "..": + actor = get_node(actor_node_path.get_as_property_path()) + else: + actor = get_parent() if Engine.is_editor_hint(): update_configuration_warnings() @@ -112,7 +114,10 @@ func _ready() -> void: process_thread = ProcessThread.PHYSICS if not actor: - _resolve_actor() + if actor_node_path: + actor = get_node(actor_node_path) + else: + actor = get_parent() if not blackboard: # invoke setter to auto-initialise the blackboard. @@ -139,13 +144,6 @@ func _ready() -> void: BeehaveDebuggerMessages.register_tree(_get_debugger_data(self)) -func _resolve_actor() -> void: - if actor_node_path.is_empty(): - actor = get_parent() - else: - actor = get_node_or_null(actor_node_path) - - func _on_scene_tree_node_added_removed(node: Node, is_added: bool) -> void: if Engine.is_editor_hint(): return diff --git a/addons/beehave/nodes/composites/simple_parallel.gd b/addons/beehave/nodes/composites/simple_parallel.gd index 13407548..7f174959 100644 --- a/addons/beehave/nodes/composites/simple_parallel.gd +++ b/addons/beehave/nodes/composites/simple_parallel.gd @@ -33,7 +33,7 @@ func _get_configuration_warnings() -> PackedStringArray: return warnings -func tick(actor: Node, blackboard: Blackboard) -> int: +func tick(actor, blackboard: Blackboard): for c in get_children(): var node_index: int = c.get_index() if node_index == 0 and not main_task_finished: diff --git a/addons/beehave/nodes/decorators/repeater.gd b/addons/beehave/nodes/decorators/repeater.gd index 5e86b635..1cf43fad 100644 --- a/addons/beehave/nodes/decorators/repeater.gd +++ b/addons/beehave/nodes/decorators/repeater.gd @@ -10,7 +10,7 @@ class_name RepeaterDecorator extends Decorator var current_count: int = 0 -func before_run(actor: Node, blackboard: Blackboard) -> void: +func before_run(actor: Node, blackboard: Blackboard): current_count = 0 diff --git a/addons/beehave/plugin.cfg b/addons/beehave/plugin.cfg index 9443090d..2cd67a94 100644 --- a/addons/beehave/plugin.cfg +++ b/addons/beehave/plugin.cfg @@ -3,5 +3,5 @@ name="Beehave" description="🐝 Behavior Tree addon for Godot Engine" author="bitbrain" -version="2.9.3-dev" +version="2.9.2" script="plugin.gd" diff --git a/addons/beehave/plugin.gd b/addons/beehave/plugin.gd index 2ae33a2f..c3be2b74 100644 --- a/addons/beehave/plugin.gd +++ b/addons/beehave/plugin.gd @@ -2,44 +2,57 @@ extends EditorPlugin const BeehaveEditorDebugger := preload("debug/debugger.gd") -var editor_debugger: BeehaveEditorDebugger -var frames: RefCounted var _custom_types: Array[StringName] = [] +const METRIC_NAME := "BeehaveGlobalMetrics" +const DEBUGGER_NAME := "BeehaveGlobalDebugger" +# var frames: RefCounted -func _init(): - name = "BeehavePlugin" - add_autoload_singleton("BeehaveGlobalMetrics", "metrics/beehave_global_metrics.gd") - add_autoload_singleton("BeehaveGlobalDebugger", "debug/global_debugger.gd") - - # Add project settings - if not ProjectSettings.has_setting("beehave/debugger/start_detached"): - ProjectSettings.set_setting("beehave/debugger/start_detached", false) - ProjectSettings.set_initial_value("beehave/debugger/start_detached", false) - ProjectSettings.add_property_info({ - "name": "beehave/debugger/start_detached", - "type": TYPE_BOOL, - "hint": PROPERTY_HINT_NONE, - "hint_string": "If enabled, the debugger will start in a separate window" - }) - ProjectSettings.save() - - print("Beehave initialized!") +func _enable_plugin() -> void: + add_autoload_singleton(METRIC_NAME, "metrics/beehave_global_metrics.gd") + add_autoload_singleton(DEBUGGER_NAME, "debug/global_debugger.gd") + # EditorInterface.restart_editor() -func _enter_tree() -> void: - editor_debugger = BeehaveEditorDebugger.new() + +var editor_debugger: BeehaveEditorDebugger + + +func _add_debugger(): + var f if Engine.get_version_info().minor >= 2: - frames = preload("debug/new_frames.gd").new() + f = preload("debug/new_frames.gd").new() else: - frames = preload("debug/old_frames.gd").new() + f = preload("debug/old_frames.gd").new() + editor_debugger = BeehaveEditorDebugger.new(f) add_debugger_plugin(editor_debugger) + + +func _remove_debugger(): + if editor_debugger != null: + remove_debugger_plugin(editor_debugger) + + +func _enter_tree() -> void: _register_custom_types() + if not ProjectSettings.has_setting("beehave/debugger/start_detached"): + ProjectSettings.set_setting("beehave/debugger/start_detached", false) + ProjectSettings.set_initial_value("beehave/debugger/start_detached", false) + ProjectSettings.add_property_info( + { + "name": "beehave/debugger/start_detached", + "type": TYPE_BOOL, + "hint": PROPERTY_HINT_NONE, + "hint_string": "If enabled, the debugger will start in a separate window" + } + ) + print("Beehave initialized!") + _add_debugger() func _exit_tree() -> void: _unregister_custom_types() - remove_debugger_plugin(editor_debugger) + _remove_debugger() func _register_custom_types() -> void: diff --git a/addons/beehave/utils/utils.gd b/addons/beehave/utils/utils.gd index 5f51ce78..c5daa41f 100644 --- a/addons/beehave/utils/utils.gd +++ b/addons/beehave/utils/utils.gd @@ -1,21 +1,21 @@ @tool -static func get_plugin() -> EditorPlugin: - var tree: SceneTree = Engine.get_main_loop() - return tree.get_root().get_child(0).get_node_or_null("BeehavePlugin") +# static func get_plugin() -> EditorPlugin: +# var tree: SceneTree = Engine.get_main_loop() +# return tree.get_root().get_child(0).get_node_or_null("BeehavePlugin") -static func get_editor_scale() -> float: - var plugin := get_plugin() - if plugin: - return plugin.get_editor_interface().get_editor_scale() - return 1.0 +# static func get_editor_scale() -> float: +# var plugin := get_plugin() +# if plugin: +# return plugin.get_editor_interface().get_editor_scale() +# return 1.0 -static func get_frames() -> RefCounted: - var plugin := get_plugin() - if plugin: - return plugin.frames - push_error("Can't find Beehave Plugin") - return null +# static func get_frames() -> RefCounted: +# var plugin := get_plugin() +# if plugin: +# return plugin.frames +# push_error("Can't find Beehave Plugin") +# return null