diff options
author | tpart <tpart120@proton.me> | 2024-08-31 12:29:03 +0200 |
---|---|---|
committer | tpart <tpart120@proton.me> | 2024-08-31 12:29:03 +0200 |
commit | d765bd2fc2cc303bf14699f32d93be8f448c4bfd (patch) | |
tree | 7aaa6abd376db5dd4b438af72f294707c9211c24 | |
parent | a141386e13192937d7d34d05733061f7fb2fe19b (diff) | |
download | hurrycurry-d765bd2fc2cc303bf14699f32d93be8f448c4bfd.tar hurrycurry-d765bd2fc2cc303bf14699f32d93be8f448c4bfd.tar.bz2 hurrycurry-d765bd2fc2cc303bf14699f32d93be8f448c4bfd.tar.zst |
Add input manager singleton
-rw-r--r-- | client/menu/input/input_manager.gd | 64 | ||||
-rw-r--r-- | client/menu/plus.svg.import | 37 | ||||
-rw-r--r-- | client/project.godot | 1 |
3 files changed, 102 insertions, 0 deletions
diff --git a/client/menu/input/input_manager.gd b/client/menu/input/input_manager.gd new file mode 100644 index 00000000..77affb38 --- /dev/null +++ b/client/menu/input/input_manager.gd @@ -0,0 +1,64 @@ +# Hurry Curry! - a game about cooking +# Copyright 2024 tpart +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +extends Node + +var default_input_map = {} +var input_map + +func _init(): + default_input_map = get_input_map() + input_map = default_input_map.duplicate(true) + +func get_input_map() -> Dictionary: + var actions = InputMap.get_actions().filter(func isBuiltIn(k: String): return !k.begins_with("ui_")) + var kb = {} + for a in actions: + kb[a] = InputMap.action_get_events(a).duplicate(true) + return kb.duplicate(true) + +func change_input_map_action(action_name: String, event: InputEvent, save: bool = true): + if !InputMap.has_action(action_name): + push_error("Action %s does not exist" % action_name, false) + return + # Erase previous keybindings + var events = InputMap.action_get_events(action_name).duplicate(true) + InputMap.action_erase_events(action_name) + # Add new keybindings + events[0] = event + for e in events: + InputMap.action_add_event(action_name, e) + + if save: + # Update input map dictionary + input_map = get_input_map() + # Save settings + Global.set_setting("input_map", input_map.duplicate(true)) + +func apply_input_map(new_input_map: Dictionary): + # Load into input map dictionary + for k in new_input_map.keys(): + input_map[k] = [] + for a in new_input_map[k]: + input_map[k].append(a) + print("Loaded keybind: %s with " % k + str(input_map[k])) + + # Apply keybindings + for k in input_map.keys(): + change_input_map_action(k, input_map[k][0], false) + +func reset_input_map(): + Global.set_setting("input_map", default_input_map.duplicate()) + apply_input_map(Global.get_setting("input_map")) diff --git a/client/menu/plus.svg.import b/client/menu/plus.svg.import new file mode 100644 index 00000000..13058c11 --- /dev/null +++ b/client/menu/plus.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cnfjbowd2i02r" +path="res://.godot/imported/plus.svg-9648647cb056d51ef71ca6c84e7bca36.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://menu/plus.svg" +dest_files=["res://.godot/imported/plus.svg-9648647cb056d51ef71ca6c84e7bca36.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/client/project.godot b/client/project.godot index 1d2c7aa6..d0f35b17 100644 --- a/client/project.godot +++ b/client/project.godot @@ -23,6 +23,7 @@ Global="*res://global.gd" Server="*res://server.gd" Sound="*res://audio/sound.tscn" DisableWrongJoypads="*res://disable_wrong_joypads.gd" +InputManager="*res://menu/input/input_manager.gd" [display] |