From 4ad79253b2d7cee1b5fcce79fcaab52a53cea7e4 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Mon, 10 Apr 2023 23:55:55 +0200 Subject: [PATCH] Merge Brocken Saving of Rempaping --- Scripts/SaveSystem/GameDataSaver.gd | 4 ++++ Scripts/SaveSystem/GlobalSettings.gd | 13 +++++++++++++ Scripts/UI/MainMenuManager.gd | 1 + Scripts/UI/Remaping/RemapController.gd | 4 +++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Scripts/SaveSystem/GameDataSaver.gd b/Scripts/SaveSystem/GameDataSaver.gd index 4013988..30b90bb 100644 --- a/Scripts/SaveSystem/GameDataSaver.gd +++ b/Scripts/SaveSystem/GameDataSaver.gd @@ -13,6 +13,10 @@ func load_data(): "display_mode": 0, "vsync_on": false, "current_resolution_index": 0, + "move_up": KEY_W, + "move_down": KEY_S, + "move_left": KEY_A, + "move_right": KEY_D, "master_volume": 0, "music_volume": 0, "sfx_volume": 0, diff --git a/Scripts/SaveSystem/GlobalSettings.gd b/Scripts/SaveSystem/GlobalSettings.gd index 667d236..0890f19 100644 --- a/Scripts/SaveSystem/GlobalSettings.gd +++ b/Scripts/SaveSystem/GlobalSettings.gd @@ -4,6 +4,8 @@ extends Node @export var music_bus_index : int = 1 @export var sfx_bus_index : int = 2 +@export var remappable_input_actions = ["move_up", "move_down", "move_left", "move_right"] + const resolutions_dictionary : Dictionary = { "800x600" : Vector2(800, 600), "1024x546" : Vector2(1024, 546), @@ -59,3 +61,14 @@ func update_sfx_volume(vol : int) -> void: Save.save_data() AudioServer.set_bus_volume_db(sfx_bus_index, vol) pass + +# Controls +func set_controls_from_save_file() -> void: + for remappable_input_action in remappable_input_actions: + for i in Save.game_data.keys().size(): + if Save.game_data.keys()[i] == remappable_input_action: + for key in InputMap.action_get_events(remappable_input_action): + InputMap.action_erase_event(remappable_input_action, key) + var control_key = InputEventKey.new() + control_key.set_keycode(Save.game_data.values()[i]) + InputMap.action_add_event(remappable_input_action, control_key) diff --git a/Scripts/UI/MainMenuManager.gd b/Scripts/UI/MainMenuManager.gd index 16405f1..6d2cc53 100644 --- a/Scripts/UI/MainMenuManager.gd +++ b/Scripts/UI/MainMenuManager.gd @@ -6,6 +6,7 @@ extends Node # Engine Callbackss func _ready(): + GlobalSettings.set_controls_from_save_file() GlobalSettings.set_display_mode(Save.game_data.display_mode) GlobalSettings.toggle_vsync(Save.game_data.vsync_on) GlobalSettings.set_resolution(Save.game_data.current_resolution_index) diff --git a/Scripts/UI/Remaping/RemapController.gd b/Scripts/UI/Remaping/RemapController.gd index a75eb2d..f054198 100644 --- a/Scripts/UI/Remaping/RemapController.gd +++ b/Scripts/UI/Remaping/RemapController.gd @@ -26,8 +26,10 @@ func remap_key(event): print(event) # Do Actual Rebinding for key in InputMap.action_get_events(remap_action): - InputMap.action_erase_event(remap_action, key) + InputMap.action_erase_event(remap_action, key) InputMap.action_add_event(remap_action, event) + print(event.as_text_keycode()) + #Save.game_data["%s" % [remap_action]] = event.get_text_keycode() remap_button.display_key() remap_button = null set_process_unhandled_key_input(false)