From 9a6a21ecab441d8f8e670655fdbb6bcc0c8a1116 Mon Sep 17 00:00:00 2001 From: dogboydog Date: Mon, 4 Mar 2024 18:50:41 -0500 Subject: [PATCH] fix #38 - work around tools menu items causing errors after rebuilding C# --- CHANGELOG.md | 3 + Samples/SampleEntryPoint.tscn | 17 ++-- YarnSpinner-Godot.csproj | 2 + addons/YarnSpinner-Godot/YarnSpinnerPlugin.cs | 80 +++++++++++-------- addons/YarnSpinner-Godot/plugin.cfg | 2 +- export_presets.cfg | 3 + 6 files changed, 68 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 268c9eb..4b9bcc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [0.2.2] 2024-03-04 +* Fixed an error with Tools menu items for YarnSpinner not working after rebuilding C# code. + ## [0.2.1] 2024-02-13 * Fixed a crash that could result from an attempted workaround of the 'assembly reload failed' error diff --git a/Samples/SampleEntryPoint.tscn b/Samples/SampleEntryPoint.tscn index 86211e7..89fe5cc 100644 --- a/Samples/SampleEntryPoint.tscn +++ b/Samples/SampleEntryPoint.tscn @@ -4,13 +4,18 @@ [ext_resource type="Theme" uid="uid://b2mp0b1wvnu8s" path="res://Samples/sample_default_theme.tres" id="2"] [ext_resource type="Texture2D" uid="uid://pbrr5yyepbx8" path="res://addons/YarnSpinner-Godot/Editor/Icons/YarnSpinnerLogo.png" id="3_bcudv"] -[node name="SampleEntryPoint" type="CanvasLayer" node_paths=PackedStringArray("_spaceButton", "_visualNovelButton", "_markupPaletteButton", "_pausingTypewriterButton", "_roundedViewsButton")] +[node name="SampleEntryPoint" type="CanvasLayer"] script = ExtResource("1") -_spaceButton = NodePath("HBoxContainer/VBoxContainer/Space") -_visualNovelButton = NodePath("HBoxContainer/VBoxContainer2/Visual Novel") -_markupPaletteButton = NodePath("HBoxContainer/VBoxContainer3/MarkupPalette") -_pausingTypewriterButton = NodePath("HBoxContainer/VBoxContainer4/PausingTypewriter") -_roundedViewsButton = NodePath("HBoxContainer/VBoxContainer5/RoundedViews") +_spaceButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Space","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null) + +_visualNovelButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Visual Novel","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null) + +_markupPaletteButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Markup Palette","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null) + +_pausingTypewriterButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Pausing Typewriter","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null) + +_roundedViewsButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Rounded Views","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null) + [node name="ColorRect" type="ColorRect" parent="."] anchors_preset = 15 diff --git a/YarnSpinner-Godot.csproj b/YarnSpinner-Godot.csproj index 33dab90..3a8e473 100644 --- a/YarnSpinner-Godot.csproj +++ b/YarnSpinner-Godot.csproj @@ -7,6 +7,8 @@ + + diff --git a/addons/YarnSpinner-Godot/YarnSpinnerPlugin.cs b/addons/YarnSpinner-Godot/YarnSpinnerPlugin.cs index 42c3891..d82b224 100644 --- a/addons/YarnSpinner-Godot/YarnSpinnerPlugin.cs +++ b/addons/YarnSpinner-Godot/YarnSpinnerPlugin.cs @@ -42,41 +42,57 @@ private struct ToolsMenuItem private Dictionary _idToToolsMenuItem; + /// + /// This dictionary becomes null when rebuilding the C# code of the samples/ + /// your project. To work around this, if we detect the dictionary is null, + /// we will re-initialize it. + /// + private Dictionary IDToToolsMenuItem + { + get + { + if (_idToToolsMenuItem == null) + { + _idToToolsMenuItem = new() + { + [0] = + new ToolsMenuItem() + { + MenuName = "Create Yarn Script", + Handler = CreateYarnScript, + }, + [1] = + new ToolsMenuItem() + { + MenuName = "Create Yarn Project", + Handler = CreateYarnProject, + }, + [2] = + new ToolsMenuItem() + { + MenuName = "Create Markup Palette", + Handler = CreateMarkupPalette, + } + // TODO: actions source generation + // [8] = + // new ToolsMenuItem() + // { + // MenuName = "Update Yarn Commands", + // Handler = ActionSourceCodeGenerator.GenerateYarnActionSourceCode, + // } + // + }; + } + + return _idToToolsMenuItem; + } + } + private PopupMenu _popup; public const string YARN_PROJECT_EXTENSION = ".yarnproject"; public override void _EnterTree() { - _idToToolsMenuItem = new() - { - [0] = - new ToolsMenuItem() - { - MenuName = "Create Yarn Script", - Handler = CreateYarnScript, - }, - [1] = - new ToolsMenuItem() - { - MenuName = "Create Yarn Project", - Handler = CreateYarnProject, - }, - [2] = - new ToolsMenuItem() - { - MenuName = "Create Markup Palette", - Handler = CreateMarkupPalette, - } - // TODO: actions source generation - // [8] = - // new ToolsMenuItem() - // { - // MenuName = "Update Yarn Commands", - // Handler = ActionSourceCodeGenerator.GenerateYarnActionSourceCode, - // } - // - }; - #if !GODOT4_2_OR_GREATER editorInterface = GetEditorInterface(); #endif @@ -116,7 +132,7 @@ public override void _EnterTree() } _popup = new PopupMenu(); - foreach (var entry in _idToToolsMenuItem) + foreach (var entry in IDToToolsMenuItem) { _popup.AddItem(entry.Value.MenuName, entry.Key); } @@ -151,7 +167,7 @@ public override void _ExitTree() /// public void OnPopupIDPressed(long id) { - if (_idToToolsMenuItem.TryGetValue((int) id, out var menuItem)) + if (IDToToolsMenuItem.TryGetValue((int) id, out var menuItem)) { menuItem.Handler(); } diff --git a/addons/YarnSpinner-Godot/plugin.cfg b/addons/YarnSpinner-Godot/plugin.cfg index c8c9eec..75f8ef6 100644 --- a/addons/YarnSpinner-Godot/plugin.cfg +++ b/addons/YarnSpinner-Godot/plugin.cfg @@ -3,5 +3,5 @@ name="YarnSpinner-Godot" description="Yarn language based dialogue system plugin for Godot" author="dogboydog" -version="0.2.0" +version="0.2.2" script="YarnSpinnerPlugin.cs" diff --git a/export_presets.cfg b/export_presets.cfg index a18f591..433291c 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -42,6 +42,7 @@ application/product_name="" application/file_description="" application/copyright="" application/trademarks="" +application/export_angle=0 ssh_remote_deploy/enabled=false ssh_remote_deploy/host="user@host_ip" ssh_remote_deploy/port="22" @@ -61,6 +62,7 @@ Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorActi Remove-Item -Recurse -Force '{temp_dir}'" dotnet/include_scripts_content=false dotnet/include_debug_symbols=true +dotnet/embed_build_outputs=false [preset.1] @@ -103,3 +105,4 @@ kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\") rm -rf \"{temp_dir}\"" dotnet/include_scripts_content=false dotnet/include_debug_symbols=true +dotnet/embed_build_outputs=false