Skip to content

Commit 0946765

Browse files
authored
Merge pull request #406 from Maaack/fix-input-icon-mapper-remapping-feature
Fixes input icon mapper re-selecting feature
2 parents 9cef27d + 991cdc7 commit 0946765

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

addons/maaacks_game_template/docs/LoadingScenes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ else:
4040

4141
A scene could load the next scene based on a timer, or when the player indicates that they are ready.
4242

43-
An example is in `opening.gd` of [Maaack's Game Template](https://github.com/Maaack/Godot-Game-Template/blob/main/addons/maaacks_game_template/base/scenes/opening/opening.gd), which starts loading the main menu immediately, and switches to it when its animations finish. Player's input can speed them up the animations, so by the end, if the next scene is not ready, a loading screen can be shown instead.
43+
An example is in `opening.gd` of [Maaack's Game Template](https://github.com/Maaack/Godot-Game-Template/blob/main/addons/maaacks_game_template/base/nodes/opening/opening.gd), which starts loading the main menu immediately, and switches to it when its animations finish. Player's input can speed them up the animations, so by the end, if the next scene is not ready, a loading screen can be shown instead.
4444

4545
Below is an example of starting the load of the next scene.
4646

addons/maaacks_game_template/installer/kenney_input_prompts_installer.gd

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const DownloadAndExtract = MaaacksGameTemplatePlugin.DownloadAndExtract
1111
const RELATIVE_PATH_TO_CONFIGURE_SCENE = "scenes/menus/options_menu/input/input_icon_mapper.tscn"
1212
const REIMPORT_CHECK_DELAY : float = 0.5
1313
const OPEN_SCENE_DELAY : float = 0.5
14-
const REGEX_PREFIX = """\\[node name="InputIconMapper" type="Node"\\][\\s\\S]*"""
14+
const MATCH_REGEX = """(\\[node name="InputIconMapper" instance=ExtResource\\("[0-9a-z_]+"\\)\\])[\\s\\S]*"""
1515

1616
const FILLED_WHITE_CONFIGURATION = """
1717
replace_strings = {
@@ -223,31 +223,35 @@ func _delete_extras() -> void:
223223
EditorInterface.get_resource_filesystem().scan()
224224

225225
func _configure_icons() -> void:
226-
var input_options_menu_path := copy_dir_path + RELATIVE_PATH_TO_CONFIGURE_SCENE
227-
var input_options_menu := FileAccess.get_file_as_string(input_options_menu_path)
226+
var input_mapper_path := copy_dir_path + RELATIVE_PATH_TO_CONFIGURE_SCENE
227+
var icon_mapper_string := FileAccess.get_file_as_string(input_mapper_path)
228+
var replacing_string := "$1\n"
228229
match(_configuration_index % 4):
229230
0:
230-
input_options_menu += FILLED_COLOR_CONFIGURATION
231+
replacing_string += FILLED_COLOR_CONFIGURATION
231232
1:
232-
input_options_menu += FILLED_WHITE_CONFIGURATION
233+
replacing_string += FILLED_WHITE_CONFIGURATION
233234
2:
234-
input_options_menu += OUTLINED_COLOR_CONFIGURATION
235+
replacing_string += OUTLINED_COLOR_CONFIGURATION
235236
3:
236-
input_options_menu += OUTLINED_WHITE_CONFIGURATION
237+
replacing_string += OUTLINED_WHITE_CONFIGURATION
237238
match(_configuration_index / 4):
238239
0:
239-
input_options_menu = input_options_menu.replace("Default", "Vector").replace(".png", ".svg")
240+
replacing_string = replacing_string.replace("Default", "Vector").replace(".png", ".svg")
240241
1:
241242
pass
242243
2:
243-
input_options_menu = input_options_menu.replace("Default", "Double")
244-
var file_rewrite := FileAccess.open(input_options_menu_path, FileAccess.WRITE)
245-
file_rewrite.store_string(input_options_menu)
244+
replacing_string = replacing_string.replace("Default", "Double")
245+
var regex = RegEx.new()
246+
regex.compile(MATCH_REGEX)
247+
icon_mapper_string = regex.sub(icon_mapper_string, replacing_string)
248+
var file_rewrite := FileAccess.open(input_mapper_path, FileAccess.WRITE)
249+
file_rewrite.store_string(icon_mapper_string)
246250
file_rewrite.close()
247-
if input_options_menu_path in EditorInterface.get_open_scenes():
248-
EditorInterface.reload_scene_from_path(input_options_menu_path)
251+
if input_mapper_path in EditorInterface.get_open_scenes():
252+
EditorInterface.reload_scene_from_path(input_mapper_path)
249253
else:
250-
EditorInterface.open_scene_from_path(input_options_menu_path)
254+
EditorInterface.open_scene_from_path(input_mapper_path)
251255
await get_tree().create_timer(OPEN_SCENE_DELAY).timeout
252256
EditorInterface.save_scene()
253257
await get_tree().create_timer(REIMPORT_CHECK_DELAY).timeout

0 commit comments

Comments
 (0)