From 390fe570ca5c8877c65f131290d46e9298f2957f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Wed, 26 Feb 2025 12:05:59 -0300 Subject: [PATCH] Fix editor templates The syntax for placeholders has changed. Also the templates are now expected to be in a subfolder for the target class name. Using "Node" so the templates are offered when adding a script to any node in the tree. Fix https://github.com/ephread/inkgd/issues/95 --- addons/inkgd/editor/ink_editor_plugin.gd | 8 +- .../templates/{ => Node}/ink_template.gd | 80 +++++++++---------- .../{ => Node}/ink_template_signals.gd | 78 +++++++++--------- 3 files changed, 83 insertions(+), 83 deletions(-) rename addons/inkgd/editor/templates/{ => Node}/ink_template.gd (50%) rename addons/inkgd/editor/templates/{ => Node}/ink_template_signals.gd (51%) diff --git a/addons/inkgd/editor/ink_editor_plugin.gd b/addons/inkgd/editor/ink_editor_plugin.gd index d0f0acf4..289fe9ee 100644 --- a/addons/inkgd/editor/ink_editor_plugin.gd +++ b/addons/inkgd/editor/ink_editor_plugin.gd @@ -200,11 +200,11 @@ func _add_templates(): # Setup the templates folder for the project var template_dir_path = ProjectSettings.get_setting("editor/script/templates_search_path") if !DirAccess.dir_exists_absolute(template_dir_path): - DirAccess.make_dir_absolute(template_dir_path) + DirAccess.make_dir_recursive_absolute(template_dir_path + "/Node") for template_name in names: - var template_file_path = template_dir_path + "/" + template_name - DirAccess.copy_absolute("res://addons/inkgd/editor/templates/" + template_name, template_file_path) + var template_file_path = template_dir_path + "/Node/" + template_name + DirAccess.copy_absolute("res://addons/inkgd/editor/templates/Node/" + template_name, template_file_path) ## Unregisters the script templates provided by the plugin. @@ -222,7 +222,7 @@ func _remove_templates(): func _get_plugin_templates_names() -> Array: var plugin_template_names = [] - var dir = DirAccess.open("res://addons/inkgd/editor/templates/") + var dir = DirAccess.open("res://addons/inkgd/editor/templates/Node") if dir: dir.list_dir_begin() var temp = dir.get_next() diff --git a/addons/inkgd/editor/templates/ink_template.gd b/addons/inkgd/editor/templates/Node/ink_template.gd similarity index 50% rename from addons/inkgd/editor/templates/ink_template.gd rename to addons/inkgd/editor/templates/Node/ink_template.gd index c2976d86..058f08bf 100644 --- a/addons/inkgd/editor/templates/ink_template.gd +++ b/addons/inkgd/editor/templates/Node/ink_template.gd @@ -1,6 +1,6 @@ # warning-ignore-all:return_value_discarded -extends %BASE% +extends _BASE_ # ############################################################################ # # Imports @@ -21,22 +21,22 @@ var InkPlayer = load("res://addons/inkgd/ink_player.gd") # ############################################################################ # func _ready(): -%TS%# Adds the player to the tree. -%TS%add_child(_ink_player) +_TS_# Adds the player to the tree. +_TS_add_child(_ink_player) -%TS%# Replace the example path with the path to your story. -%TS%# Remove this line if you set 'ink_file' in the inspector. -%TS%_ink_player.ink_file = load("res://path/to/file.ink.json") +_TS_# Replace the example path with the path to your story. +_TS_# Remove this line if you set 'ink_file' in the inspector. +_TS__ink_player.ink_file = load("res://path/to/file.ink.json") -%TS%# It's recommended to load the story in the background. On platforms that -%TS%# don't support threads, the value of this variable is ignored. -%TS%_ink_player.loads_in_background = true +_TS_# It's recommended to load the story in the background. On platforms that +_TS_# don't support threads, the value of this variable is ignored. +_TS__ink_player.loads_in_background = true -%TS%_ink_player.connect("loaded", Callable(self, "_story_loaded")) +_TS__ink_player.connect("loaded", Callable(self, "_story_loaded")) -%TS%# Creates the story. 'loaded' will be emitted once Ink is ready -%TS%# continue the story. -%TS%_ink_player.create_story() +_TS_# Creates the story. 'loaded' will be emitted once Ink is ready +_TS_# continue the story. +_TS__ink_player.create_story() # ############################################################################ # @@ -44,13 +44,13 @@ func _ready(): # ############################################################################ # func _story_loaded(successfully: bool): -%TS%if !successfully: -%TS%%TS%return +_TS_if !successfully: +_TS__TS_return -%TS%# _observe_variables() -%TS%# _bind_externals() +_TS_# _observe_variables() +_TS_# _bind_externals() -%TS%_continue_story() +_TS__continue_story() # ############################################################################ # @@ -58,44 +58,44 @@ func _story_loaded(successfully: bool): # ############################################################################ # func _continue_story(): -%TS%while _ink_player.can_continue: -%TS%%TS%var text = _ink_player.continue_story() -%TS%%TS%# This text is a line of text from the ink story. -%TS%%TS%# Set the text of a Label to this value to display it in your game. -%TS%%TS%print(text) -%TS%if _ink_player.has_choices: -%TS%%TS%# 'current_choices' contains a list of the choices, as strings. -%TS%%TS%for choice in _ink_player.current_choices: -%TS%%TS%%TS%print(choice.text) -%TS%%TS%%TS%print(choice.tags) -%TS%%TS%# '_select_choice' is a function that will take the index of -%TS%%TS%# your selection and continue the story. -%TS%%TS%_select_choice(0) -%TS%else: -%TS%%TS%# This code runs when the story reaches it's end. -%TS%%TS%print("The End") +_TS_while _ink_player.can_continue: +_TS__TS_var text = _ink_player.continue_story() +_TS__TS_# This text is a line of text from the ink story. +_TS__TS_# Set the text of a Label to this value to display it in your game. +_TS__TS_print(text) +_TS_if _ink_player.has_choices: +_TS__TS_# 'current_choices' contains a list of the choices, as strings. +_TS__TS_for choice in _ink_player.current_choices: +_TS__TS__TS_print(choice.text) +_TS__TS__TS_print(choice.tags) +_TS__TS_# '_select_choice' is a function that will take the index of +_TS__TS_# your selection and continue the story. +_TS__TS__select_choice(0) +_TS_else: +_TS__TS_# This code runs when the story reaches it's end. +_TS__TS_print("The End") func _select_choice(index): -%TS%_ink_player.choose_choice_index(index) -%TS%_continue_story() +_TS__ink_player.choose_choice_index(index) +_TS__continue_story() # Uncomment to bind an external function. # # func _bind_externals(): -# %TS%_ink_player.bind_external_function("", self, "_external_function") +# _TS__ink_player.bind_external_function("", self, "_external_function") # # # func _external_function(arg1, arg2): -# %TS%pass +# _TS_pass # Uncomment to observe the variables from your ink story. # You can observe multiple variables by putting adding them in the array. # func _observe_variables(): -# %TS%_ink_player.observe_variables(["var1", "var2"], self, "_variable_changed") +# _TS__ink_player.observe_variables(["var1", "var2"], self, "_variable_changed") # # # func _variable_changed(variable_name, new_value): -# %TS%print("Variable '%s' changed to: %s" %[variable_name, new_value]) +# _TS_print("Variable '%s' changed to: %s" %[variable_name, new_value]) diff --git a/addons/inkgd/editor/templates/ink_template_signals.gd b/addons/inkgd/editor/templates/Node/ink_template_signals.gd similarity index 51% rename from addons/inkgd/editor/templates/ink_template_signals.gd rename to addons/inkgd/editor/templates/Node/ink_template_signals.gd index 37774892..8d6187b3 100644 --- a/addons/inkgd/editor/templates/ink_template_signals.gd +++ b/addons/inkgd/editor/templates/Node/ink_template_signals.gd @@ -1,6 +1,6 @@ # warning-ignore-all:return_value_discarded -extends %BASE% +extends _BASE_ # ############################################################################ # # Imports @@ -22,47 +22,47 @@ var InkPlayer = load("res://addons/inkgd/ink_player.gd") # ############################################################################ # func _ready(): -%TS%# Adds the player to the tree. -%TS%add_child(_ink_player) +_TS_# Adds the player to the tree. +_TS_add_child(_ink_player) -%TS%# Replace the example path with the path to your story. -%TS%# Remove this line if you set 'ink_file' in the inspector. -%TS%_ink_player.ink_file = load("res://path/to/file.ink.json") +_TS_# Replace the example path with the path to your story. +_TS_# Remove this line if you set 'ink_file' in the inspector. +_TS__ink_player.ink_file = load("res://path/to/file.ink.json") -%TS%# It's recommended to load the story in the background. On platforms that -%TS%# don't support threads, the value of this variable is ignored. -%TS%_ink_player.loads_in_background = true +_TS_# It's recommended to load the story in the background. On platforms that +_TS_# don't support threads, the value of this variable is ignored. +_TS__ink_player.loads_in_background = true -%TS%_ink_player.connect("loaded", Callable(self, "_story_loaded")) -%TS%_ink_player.connect("continued", Callable(self, "_continued")) -%TS%_ink_player.connect("prompt_choices", Callable(self, "_prompt_choices")) -%TS%_ink_player.connect("ended", Callable(self, "_ended")) +_TS__ink_player.connect("loaded", Callable(self, "_story_loaded")) +_TS__ink_player.connect("continued", Callable(self, "_continued")) +_TS__ink_player.connect("prompt_choices", Callable(self, "_prompt_choices")) +_TS__ink_player.connect("ended", Callable(self, "_ended")) -%TS%# Creates the story. 'loaded' will be emitted once Ink is ready -%TS%# continue the story. -%TS%_ink_player.create_story() +_TS_# Creates the story. 'loaded' will be emitted once Ink is ready +_TS_# continue the story. +_TS__ink_player.create_story() # ############################################################################ # # Signal Receivers # ############################################################################ # func _story_loaded(successfully: bool): -%TS%if !successfully: -%TS%%TS%return +_TS_if !successfully: +_TS__TS_return -%TS%# _observe_variables() -%TS%# _bind_externals() +_TS_# _observe_variables() +_TS_# _bind_externals() -%TS%# Here, the story is started immediately, but it could be started -%TS%# at a later time. -%TS%_ink_player.continue_story() +_TS_# Here, the story is started immediately, but it could be started +_TS_# at a later time. +_TS__ink_player.continue_story() func _continued(text, tags): -%TS%print(text) -%TS%# Here you could yield for an hypothetical signal, before continuing. -%TS%# await self.event -%TS%_ink_player.continue_story() +_TS_print(text) +_TS_# Here you could yield for an hypothetical signal, before continuing. +_TS_# await self.event +_TS__ink_player.continue_story() # ############################################################################ # @@ -70,38 +70,38 @@ func _continued(text, tags): # ############################################################################ # func _prompt_choices(choices): -%TS%if !choices.is_empty(): -%TS%%TS%print(choices) +_TS_if !choices.is_empty(): +_TS__TS_print(choices) -%TS%%TS%# In a real world scenario, _select_choice' could be -%TS%%TS%# connected to a signal, like 'Button.pressed'. -%TS%%TS%_select_choice(0) +_TS__TS_# In a real world scenario, _select_choice' could be +_TS__TS_# connected to a signal, like 'Button.pressed'. +_TS__TS__select_choice(0) func _ended(): -%TS%print("The End") +_TS_print("The End") func _select_choice(index): -%TS%_ink_player.choose_choice_index(index) -%TS%_ink_player.continue_story() +_TS__ink_player.choose_choice_index(index) +_TS__ink_player.continue_story() # Uncomment to bind an external function. # # func _bind_externals(): -# %TS%_ink_player.bind_external_function("", self, "_external_function") +# _TS__ink_player.bind_external_function("", self, "_external_function") # # # func _external_function(arg1, arg2): -# %TS%pass +# _TS_pass # Uncomment to observe the variables from your ink story. # You can observe multiple variables by putting adding them in the array. # func _observe_variables(): -# %TS%_ink_player.observe_variables(["var1", "var2"], self, "_variable_changed") +# _TS__ink_player.observe_variables(["var1", "var2"], self, "_variable_changed") # # # func _variable_changed(variable_name, new_value): -# %TS%print("Variable '%s' changed to: %s" %[variable_name, new_value]) +# _TS_print("Variable '%s' changed to: %s" %[variable_name, new_value])