Skip to content

Commit 991cdc7

Browse files
committed
Fixes selecting a different style for input icon matcher.
1 parent 6ceeebe commit 991cdc7

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

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)