From fae77121be89b696eaa8db3239a2764d41039f59 Mon Sep 17 00:00:00 2001 From: Invertex Date: Sat, 27 Jan 2024 02:12:18 -0800 Subject: [PATCH] Squashed commit of the following: commit 17683f83d666812c985cbad1f97068c5295a1641 Author: Jowan-Spooner <42868150+Jowan-Spooner@users.noreply.github.com> Date: Fri Jan 26 18:55:38 2024 +0100 Rename the Other folder to Core (#2047) * Rename the Other folder to Core * Add a small auto-update * Fix unit test commit ce2a73497e63352ef5b905a34bab059a7bfa2a8f Author: Jowan-Spooner <42868150+Jowan-Spooner@users.noreply.github.com> Date: Fri Jan 26 18:55:03 2024 +0100 Allow specifying parent to add layout (#2048) - fixes #2029 commit c33a560e9759b74506ec88e5f166a7d05a140e1f Author: Dabbles in too many things Date: Fri Jan 26 09:54:52 2024 -0800 Avoid null get_tree() call (#2052) get_tree() can return null when the Dialogic view isn't open but this function is being called by an external system. No node tree exists to wait for or manipulate, so errors are spammed. --- .github/workflows/resources/project.godot | 2 +- .../{Other => Core}/DialogicGameHandler.gd | 0 .../{Other => Core}/DialogicResourceUtil.gd | 0 addons/dialogic/{Other => Core}/DialogicUtil.gd | 2 +- .../{Other => Core}/Dialogic_Subsystem.gd | 0 addons/dialogic/{Other => Core}/index_class.gd | 0 .../Editor/Common/update_install_window.gd | 5 +++-- addons/dialogic/Modules/Style/subsystem_styles.gd | 15 ++++++++++----- addons/dialogic/Modules/Text/event_text.gd | 2 +- addons/dialogic/plugin.gd | 7 ++++++- 10 files changed, 22 insertions(+), 11 deletions(-) rename addons/dialogic/{Other => Core}/DialogicGameHandler.gd (100%) rename addons/dialogic/{Other => Core}/DialogicResourceUtil.gd (100%) rename addons/dialogic/{Other => Core}/DialogicUtil.gd (99%) rename addons/dialogic/{Other => Core}/Dialogic_Subsystem.gd (100%) rename addons/dialogic/{Other => Core}/index_class.gd (100%) diff --git a/.github/workflows/resources/project.godot b/.github/workflows/resources/project.godot index 7a40c37f9..dd648de72 100644 --- a/.github/workflows/resources/project.godot +++ b/.github/workflows/resources/project.godot @@ -21,4 +21,4 @@ renderer/rendering_method.mobile="gl_compatibility" [autoload] -Dialogic="*res://addons/dialogic/Other/DialogicGameHandler.gd" +Dialogic="*res://addons/dialogic/Core/DialogicGameHandler.gd" diff --git a/addons/dialogic/Other/DialogicGameHandler.gd b/addons/dialogic/Core/DialogicGameHandler.gd similarity index 100% rename from addons/dialogic/Other/DialogicGameHandler.gd rename to addons/dialogic/Core/DialogicGameHandler.gd diff --git a/addons/dialogic/Other/DialogicResourceUtil.gd b/addons/dialogic/Core/DialogicResourceUtil.gd similarity index 100% rename from addons/dialogic/Other/DialogicResourceUtil.gd rename to addons/dialogic/Core/DialogicResourceUtil.gd diff --git a/addons/dialogic/Other/DialogicUtil.gd b/addons/dialogic/Core/DialogicUtil.gd similarity index 99% rename from addons/dialogic/Other/DialogicUtil.gd rename to addons/dialogic/Core/DialogicUtil.gd index b9b6ab508..568ea70db 100644 --- a/addons/dialogic/Other/DialogicUtil.gd +++ b/addons/dialogic/Core/DialogicUtil.gd @@ -66,7 +66,7 @@ static func get_module_path(name:String, builtin:=true) -> String: static func update_autoload_subsystem_access() -> void: - var script: Script = load("res://addons/dialogic/Other/DialogicGameHandler.gd") + var script: Script = load("res://addons/dialogic/Core/DialogicGameHandler.gd") var new_subsystem_access_list := "#region SUBSYSTEMS\n" diff --git a/addons/dialogic/Other/Dialogic_Subsystem.gd b/addons/dialogic/Core/Dialogic_Subsystem.gd similarity index 100% rename from addons/dialogic/Other/Dialogic_Subsystem.gd rename to addons/dialogic/Core/Dialogic_Subsystem.gd diff --git a/addons/dialogic/Other/index_class.gd b/addons/dialogic/Core/index_class.gd similarity index 100% rename from addons/dialogic/Other/index_class.gd rename to addons/dialogic/Core/index_class.gd diff --git a/addons/dialogic/Editor/Common/update_install_window.gd b/addons/dialogic/Editor/Common/update_install_window.gd index b5f066dad..7cdda8b16 100644 --- a/addons/dialogic/Editor/Common/update_install_window.gd +++ b/addons/dialogic/Editor/Common/update_install_window.gd @@ -106,8 +106,9 @@ func _on_update_manager_downdload_completed(result:int): func _on_resources_reimported(resources:Array) -> void: - await get_tree().process_frame - get_parent().move_to_foreground() + if is_inside_tree(): + await get_tree().process_frame + get_parent().move_to_foreground() func markdown_to_bbcode(text:String) -> String: diff --git a/addons/dialogic/Modules/Style/subsystem_styles.gd b/addons/dialogic/Modules/Style/subsystem_styles.gd index 03da9a659..c5f65c52d 100644 --- a/addons/dialogic/Modules/Style/subsystem_styles.gd +++ b/addons/dialogic/Modules/Style/subsystem_styles.gd @@ -23,7 +23,7 @@ func load_game_state(load_flag:=LoadFlags.FULL_LOAD): #region MAIN METHODS #################################################################################################### -func load_style(style_name:="", is_base_style:=true) -> Node: +func load_style(style_name:="", parent:Node = null, is_base_style:=true) -> Node: var style := DialogicUtil.get_style_by_name(style_name) var signal_info := {'style':style_name} @@ -34,7 +34,6 @@ func load_style(style_name:="", is_base_style:=true) -> Node: dialogic.current_state_info['base_style'] = style_name var previous_layout := get_layout_node() - if is_instance_valid(previous_layout) and previous_layout.has_meta('style'): signal_info['previous'] = previous_layout.get_meta('style').name @@ -55,11 +54,14 @@ func load_style(style_name:="", is_base_style:=true) -> Node: return else: + parent = previous_layout.get_parent() + previous_layout.get_parent().remove_child(previous_layout) previous_layout.queue_free() + # if this is another style: - var new_layout := create_layout(style) + var new_layout := create_layout(style, parent) new_layout.ready.connect(reload_current_info_into_new_style) style_changed.emit(signal_info) @@ -69,7 +71,7 @@ func load_style(style_name:="", is_base_style:=true) -> Node: ## Method that adds a layout scene with all the necessary layers. ## The layout scene will be added to the tree root and returned. -func create_layout(style:DialogicStyle) -> DialogicLayoutBase: +func create_layout(style:DialogicStyle, parent:Node = null) -> DialogicLayoutBase: # Load base scene var base_scene: DialogicLayoutBase @@ -104,7 +106,10 @@ func create_layout(style:DialogicStyle) -> DialogicLayoutBase: base_scene.set_meta('style', style) - dialogic.get_parent().call_deferred("add_child", base_scene) + if parent == null: + parent = dialogic.get_parent() + parent.call_deferred("add_child", base_scene) + dialogic.get_tree().set_meta('dialogic_layout_node', base_scene) return base_scene diff --git a/addons/dialogic/Modules/Text/event_text.gd b/addons/dialogic/Modules/Text/event_text.gd index e9da6a5a6..33734ed84 100644 --- a/addons/dialogic/Modules/Text/event_text.gd +++ b/addons/dialogic/Modules/Text/event_text.gd @@ -59,7 +59,7 @@ func _execute() -> void: if character: if dialogic.has_subsystem('Styles') and character.custom_info.get('style', null): - dialogic.Styles.load_style(character.custom_info.style, false) + dialogic.Styles.load_style(character.custom_info.style, null, false) await dialogic.get_tree().process_frame diff --git a/addons/dialogic/plugin.gd b/addons/dialogic/plugin.gd index 2d3dfdd7a..40de860e2 100644 --- a/addons/dialogic/plugin.gd +++ b/addons/dialogic/plugin.gd @@ -4,7 +4,7 @@ extends EditorPlugin ## Preload the main panel scene const MainPanel := preload("res://addons/dialogic/Editor/editor_main.tscn") const PLUGIN_NAME := "Dialogic" -const PLUGIN_HANDLER_PATH := "res://addons/dialogic/Other/DialogicGameHandler.gd" +const PLUGIN_HANDLER_PATH := "res://addons/dialogic/Core/DialogicGameHandler.gd" const PLUGIN_ICON_PATH := "res://addons/dialogic/Editor/Images/plugin-icon.svg" ## References used by various other scripts to quickly reference these things @@ -40,6 +40,11 @@ func _enter_tree() -> void: get_editor_interface().get_editor_main_screen().add_child(editor_view) _make_visible(false) + # Auto-update the singleton path for alpha users + # TODO remove at some point during beta or later + remove_autoload_singleton(PLUGIN_NAME) + add_autoload_singleton(PLUGIN_NAME, PLUGIN_HANDLER_PATH) + func _exit_tree() -> void: if editor_view: