From d7f6432bb7bbfbdd31d2b54a01fee184aa62a1c0 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Thu, 9 Nov 2023 03:36:30 +0200 Subject: [PATCH] Update Keychain --- addons/README.md | 2 +- addons/keychain/Keychain.gd | 41 ++++++++++++++++++++++++++------- addons/keychain/ShortcutEdit.gd | 11 +-------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/addons/README.md b/addons/README.md index f73373f39..9860d2964 100644 --- a/addons/README.md +++ b/addons/README.md @@ -9,7 +9,7 @@ ## Keychain - Upstream: https://github.com/Orama-Interactive/Keychain -- Version: 4a08d6b380929031b2c9202811ae0a65d850a5ac +- Version: [5031af557efcff4eb1ae77550e91868ab57cb1c0](https://github.com/Orama-Interactive/Keychain/commit/5031af557efcff4eb1ae77550e91868ab57cb1c0) - License: [MIT](https://github.com/Orama-Interactive/Keychain/blob/main/LICENSE) ## gdgifexporter diff --git a/addons/keychain/Keychain.gd b/addons/keychain/Keychain.gd index be39efd18..2288107b2 100644 --- a/addons/keychain/Keychain.gd +++ b/addons/keychain/Keychain.gd @@ -2,19 +2,28 @@ extends Node const PROFILES_PATH := "user://shortcut_profiles" -## Change these settings +## [Array] of [ShortcutProfile]s. var profiles: Array[ShortcutProfile] = [preload("profiles/default.tres")] -var selected_profile := profiles[0] -var profile_index := 0 +var selected_profile := profiles[0] ## The currently selected [ShortcutProfile]. +var profile_index := 0 ## The index of the currently selected [ShortcutProfile]. +## [Dictionary] of [String] and [InputAction]. ## Syntax: "action_name": InputAction.new("Action Display Name", "Group", true) ## Note that "action_name" must already exist in the Project's Input Map. var actions := {} +## [Dictionary] of [String] and [InputGroup]. ## Syntax: "Group Name": InputGroup.new("Parent Group Name") var groups := {} -var ignore_actions := [] +var ignore_actions: Array[StringName] = [] ## [Array] of [StringName] input map actions to ignore. +## If [code]true[/code], ignore Godot's default "ui_" input map actions. var ignore_ui_actions := true -var changeable_types := [true, true, true, true] +## A [PackedByteArray] of [bool]s with a fixed length of 4. Used for developers to allow or +## forbid setting certain types of InputEvents. The first element is for [InputEventKey]s, +## the second for [InputEventMouseButton]s, the third for [InputEventJoypadButton]s +## and the fourth for [InputEventJoypadMotion]s. +var changeable_types: PackedByteArray = [true, true, true, true] +## The file path of the [code]config_file[/code]. var config_path := "user://cache.ini" +## Used to store the settings to the filesystem. var config_file: ConfigFile @@ -85,15 +94,15 @@ func change_profile(index: int) -> void: action_add_event(action, event) -func action_add_event(action: String, event: InputEvent) -> void: +func action_add_event(action: StringName, event: InputEvent) -> void: InputMap.action_add_event(action, event) -func action_erase_event(action: String, event: InputEvent) -> void: +func action_erase_event(action: StringName, event: InputEvent) -> void: InputMap.action_erase_event(action, event) -func action_erase_events(action: String) -> void: +func action_erase_events(action: StringName) -> void: InputMap.action_erase_events(action) @@ -101,3 +110,19 @@ func load_translation(locale: String) -> void: var translation = load("res://addons/keychain/translations".path_join(locale + ".po")) if is_instance_valid(translation) and translation is Translation: TranslationServer.add_translation(translation) + + +## Converts a [param text] with snake case to a more readable format, by replacing +## underscores with spaces. If [param capitalize_first_letter] is [code]true[/code], +## the first letter of the text is capitalized. +## E.g, "snake_case" would be converted to "Snake case" if +## [param capitalize_first_letter] is [code]true[/code], else it would be converted to +## "snake case". +func humanize_snake_case(text: String, capitalize_first_letter := true) -> String: + text = text.replace("_", " ") + if capitalize_first_letter: + var first_letter := text.left(1) + first_letter = first_letter.capitalize() + text = text.right(-1) + text = text.insert(0, first_letter) + return text diff --git a/addons/keychain/ShortcutEdit.gd b/addons/keychain/ShortcutEdit.gd index 5a1a63603..207ddec11 100644 --- a/addons/keychain/ShortcutEdit.gd +++ b/addons/keychain/ShortcutEdit.gd @@ -199,19 +199,10 @@ func get_action_name(action: String) -> String: display_name = Keychain.actions[action].display_name if display_name.is_empty(): - display_name = _humanize_snake_case(action) + display_name = Keychain.humanize_snake_case(action) return display_name -func _humanize_snake_case(text: String) -> String: - text = text.replace("_", " ") - var first_letter := text.left(1) - first_letter = first_letter.capitalize() - text = text.right(-1) - text = text.insert(0, first_letter) - return text - - func add_event_tree_item(event: InputEvent, action_tree_item: TreeItem) -> void: var event_class := event.get_class() match event_class: