Skip to content

Commit ba8ee17

Browse files
authored
Merge pull request #379 from Maaack/add-update-autoload-paths-option
Add update autoload paths option
2 parents 172861f + 5990b50 commit ba8ee17

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

addons/maaacks_game_template/docs/NewProject.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ These instructions assume starting with the entire contents of the project folde
1010
2. In the `Setup Wizard` window next to "Delete Example Files", click `Run`.
1111
3. In the next window, select `Yes` to continue with removing the example files.
1212

13-
2. Set a default theme.
13+
2. Update autoload file paths.
14+
1. Go to `Project > Tools > Run Maaack's Game Template Setup...`.
15+
2. In the `Setup Wizard` window next to "Update Autoload Paths", click `Run`.
16+
17+
3. Set a default theme.
1418
1. Go to `Project > Tools > Run Maaack's Game Template Setup...`.
1519
2. In the `Setup Wizard` window next to "Set the Default Theme", click `Run`.
1620
3. In the next window, select the desired theme from the preview and select `Yes` to set it as the project's default theme.

addons/maaacks_game_template/installer/setup_wizard.gd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ extends AcceptDialog
1212
@onready var copy_button : Button = %CopyButton
1313
@onready var delete_check_box : CheckBox = %DeleteCheckBox
1414
@onready var delete_button : Button = %DeleteButton
15+
@onready var update_paths_check_box : CheckBox = %UpdatePathsCheckBox
16+
@onready var update_paths_button : Button = %UpdatePathsButton
1517
@onready var set_main_scene_check_box : CheckBox = %SetMainSceneCheckBox
1618
@onready var set_main_scene_button : Button = %SetMainSceneButton
1719
@onready var set_default_theme_check_box : CheckBox = %SetDefaultThemeCheckBox
@@ -65,6 +67,10 @@ func _refresh_copy_and_delete_examples() -> void:
6567
else:
6668
delete_check_box.button_pressed = true
6769

70+
func _refresh_update_autoload_paths() -> void:
71+
update_paths_check_box.button_pressed = MaaacksGameTemplatePlugin.instance.are_autoload_paths_updated()
72+
update_paths_button.disabled = false
73+
6874
func _refresh_main_scene() -> void:
6975
if MaaacksGameTemplatePlugin.instance.is_main_scene_set():
7076
set_main_scene_check_box.button_pressed = true
@@ -88,6 +94,7 @@ func _refresh_options():
8894
_refresh_plugin_details()
8995
_open_check_plugin_version()
9096
_refresh_copy_and_delete_examples()
97+
_refresh_update_autoload_paths()
9198
_refresh_main_scene()
9299
_refresh_default_theme()
93100
_refresh_input_prompts()
@@ -112,6 +119,13 @@ func _on_delete_button_pressed():
112119
tree_exited.connect(func(): MaaacksGameTemplatePlugin.instance.open_delete_examples_short_confirmation_dialog())
113120
queue_free()
114121

122+
func _on_update_paths_button_pressed():
123+
MaaacksGameTemplatePlugin.instance.update_autoload_paths(MaaacksGameTemplatePlugin.get_copy_path())
124+
_refresh_update_autoload_paths()
125+
update_paths_button.disabled = true
126+
await get_tree().create_timer(1.0).timeout
127+
update_paths_button.disabled = false
128+
115129
func _on_set_main_scene_button_pressed():
116130
tree_exited.connect(func(): MaaacksGameTemplatePlugin.instance.open_main_scene_confirmation_dialog(MaaacksGameTemplatePlugin.get_copy_path()))
117131
queue_free()

addons/maaacks_game_template/installer/setup_wizard.tscn

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[ext_resource type="Script" uid="uid://coq26stqrim51" path="res://addons/maaacks_game_template/installer/setup_wizard.gd" id="1_jck5m"]
44

55
[node name="SetupWizardDialog" type="AcceptDialog"]
6+
oversampling_override = 1.0
67
title = "Setup Wizard"
78
initial_position = 2
89
size = Vector2i(576, 540)
@@ -93,6 +94,23 @@ layout_mode = 2
9394
disabled = true
9495
text = "Run"
9596

97+
[node name="UpdatePathsLabel" type="Label" parent="VBoxContainer/StepsContainer"]
98+
layout_mode = 2
99+
size_flags_horizontal = 3
100+
text = "Update Autoload Paths"
101+
102+
[node name="UpdatePathsCheckBox" type="CheckBox" parent="VBoxContainer/StepsContainer"]
103+
unique_name_in_owner = true
104+
layout_mode = 2
105+
disabled = true
106+
107+
[node name="UpdatePathsButton" type="Button" parent="VBoxContainer/StepsContainer"]
108+
unique_name_in_owner = true
109+
custom_minimum_size = Vector2(100, 0)
110+
layout_mode = 2
111+
disabled = true
112+
text = "Run"
113+
96114
[node name="SetMainSceneLabel" type="Label" parent="VBoxContainer/StepsContainer"]
97115
layout_mode = 2
98116
size_flags_horizontal = 3
@@ -147,6 +165,7 @@ text = "Run"
147165
[connection signal="pressed" from="VBoxContainer/StepsContainer/UpdateButton" to="." method="_on_update_button_pressed"]
148166
[connection signal="pressed" from="VBoxContainer/StepsContainer/CopyButton" to="." method="_on_copy_button_pressed"]
149167
[connection signal="pressed" from="VBoxContainer/StepsContainer/DeleteButton" to="." method="_on_delete_button_pressed"]
168+
[connection signal="pressed" from="VBoxContainer/StepsContainer/UpdatePathsButton" to="." method="_on_update_paths_button_pressed"]
150169
[connection signal="pressed" from="VBoxContainer/StepsContainer/SetMainSceneButton" to="." method="_on_set_main_scene_button_pressed"]
151170
[connection signal="pressed" from="VBoxContainer/StepsContainer/SetDefaultThemeButton" to="." method="_on_set_default_theme_button_pressed"]
152171
[connection signal="pressed" from="VBoxContainer/StepsContainer/AddInputIconsButton" to="." method="_on_add_input_icons_button_pressed"]

addons/maaacks_game_template/maaacks_game_template.gd

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ static func get_plugin_examples_path() -> String:
4242
static func get_app_config_path() -> String:
4343
return get_plugin_path() + APP_CONFIG_RELATIVE_PATH
4444

45+
static func get_scene_loader_path() -> String:
46+
return get_plugin_path() + SCENE_LOADER_RELATIVE_PATH
47+
4548
static func get_copy_path() -> String:
4649
var copy_path = ProjectSettings.get_setting(PROJECT_SETTINGS_PATH + "copy_path", get_plugin_examples_path())
4750
if not copy_path.ends_with("/"):
@@ -192,18 +195,18 @@ func _update_app_config_paths(target_path : String) -> void:
192195
]
193196
for prefix in prefixes:
194197
prefix += " = \""
195-
var target_string = prefix + get_plugin_examples_path()
198+
var target_string = prefix + get_plugin_examples_path()
196199
var replacing_string = prefix + target_path
197200
file_text = file_text.replace(target_string, replacing_string)
198201
var file = FileAccess.open(file_path, FileAccess.WRITE)
199202
file.store_string(file_text)
200203
file.close()
201204

202205
func _update_scene_loader_path(target_path : String) -> void:
203-
var file_path : String = get_plugin_path() + SCENE_LOADER_RELATIVE_PATH
206+
var file_path : String = get_scene_loader_path()
204207
var file_text : String = FileAccess.get_file_as_string(file_path)
205208
var prefix : String = "loading_screen_path = \""
206-
var target_string = prefix + get_plugin_path() + "base/"
209+
var target_string = prefix + get_plugin_path() + "base/"
207210
var replacing_string = prefix + target_path
208211
file_text = file_text.replace(target_string, replacing_string)
209212
var file = FileAccess.open(file_path, FileAccess.WRITE)
@@ -219,11 +222,29 @@ func _add_translations() -> void:
219222
translations.append(translation_path)
220223
ProjectSettings.set_setting("internationalization/locale/translations", translations)
221224

225+
func _is_app_config_path_updated(target_path) -> bool:
226+
var file_text : String = FileAccess.get_file_as_string(get_app_config_path())
227+
var target_string = "main_menu_scene_path = \"" + get_plugin_examples_path()
228+
return !file_text.contains(target_string)
229+
230+
func _is_scene_loader_path_updated(target_path) -> bool:
231+
var file_text : String = FileAccess.get_file_as_string(get_scene_loader_path())
232+
var target_string = "loading_screen_path = \"" + get_plugin_path() + "base/"
233+
return !file_text.contains(target_string)
234+
235+
func are_autoload_paths_updated() -> bool:
236+
var copy_path := get_copy_path()
237+
if copy_path == get_plugin_examples_path(): return false
238+
return _is_app_config_path_updated(copy_path) and _is_scene_loader_path_updated(copy_path)
239+
240+
func update_autoload_paths(target_path : String) -> void:
241+
_update_app_config_paths(target_path)
242+
_update_scene_loader_path(target_path)
243+
222244
func _on_completed_copy_to_directory(target_path : String) -> void:
223245
ProjectSettings.set_setting(PROJECT_SETTINGS_PATH + "copy_path", target_path)
224246
ProjectSettings.save()
225-
_update_app_config_paths(target_path)
226-
_update_scene_loader_path(target_path)
247+
update_autoload_paths(target_path)
227248
_copy_override_file()
228249
_open_play_opening_confirmation_dialog(target_path)
229250

0 commit comments

Comments
 (0)