X Tutup
Skip to content

Commit 5031af5

Browse files
Move humanize_snake_case to Keychain.gd and add some documentation comments
1 parent 4a08d6b commit 5031af5

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

addons/keychain/Keychain.gd

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@ extends Node
22

33
const PROFILES_PATH := "user://shortcut_profiles"
44

5-
## Change these settings
5+
## [Array] of [ShortcutProfile]s.
66
var profiles: Array[ShortcutProfile] = [preload("profiles/default.tres")]
7-
var selected_profile := profiles[0]
8-
var profile_index := 0
7+
var selected_profile := profiles[0] ## The currently selected [ShortcutProfile].
8+
var profile_index := 0 ## The index of the currently selected [ShortcutProfile].
9+
## [Dictionary] of [String] and [InputAction].
910
## Syntax: "action_name": InputAction.new("Action Display Name", "Group", true)
1011
## Note that "action_name" must already exist in the Project's Input Map.
1112
var actions := {}
13+
## [Dictionary] of [String] and [InputGroup].
1214
## Syntax: "Group Name": InputGroup.new("Parent Group Name")
1315
var groups := {}
14-
var ignore_actions := []
16+
var ignore_actions: Array[StringName] = [] ## [Array] of [StringName] input map actions to ignore.
17+
## If [code]true[/code], ignore Godot's default "ui_" input map actions.
1518
var ignore_ui_actions := true
16-
var changeable_types := [true, true, true, true]
19+
## A [PackedByteArray] of [bool]s with a fixed length of 4. Used for developers to allow or
20+
## forbid setting certain types of InputEvents. The first element is for [InputEventKey]s,
21+
## the second for [InputEventMouseButton]s, the third for [InputEventJoypadButton]s
22+
## and the fourth for [InputEventJoypadMotion]s.
23+
var changeable_types: PackedByteArray = [true, true, true, true]
24+
## The file path of the [code]config_file[/code].
1725
var config_path := "user://cache.ini"
26+
## Used to store the settings to the filesystem.
1827
var config_file: ConfigFile
1928

2029

@@ -85,19 +94,35 @@ func change_profile(index: int) -> void:
8594
action_add_event(action, event)
8695

8796

88-
func action_add_event(action: String, event: InputEvent) -> void:
97+
func action_add_event(action: StringName, event: InputEvent) -> void:
8998
InputMap.action_add_event(action, event)
9099

91100

92-
func action_erase_event(action: String, event: InputEvent) -> void:
101+
func action_erase_event(action: StringName, event: InputEvent) -> void:
93102
InputMap.action_erase_event(action, event)
94103

95104

96-
func action_erase_events(action: String) -> void:
105+
func action_erase_events(action: StringName) -> void:
97106
InputMap.action_erase_events(action)
98107

99108

100109
func load_translation(locale: String) -> void:
101110
var translation = load("res://addons/keychain/translations".path_join(locale + ".po"))
102111
if is_instance_valid(translation) and translation is Translation:
103112
TranslationServer.add_translation(translation)
113+
114+
115+
## Converts a [param text] with snake case to a more readable format, by replacing
116+
## underscores with spaces. If [param capitalize_first_letter] is [code]true[/code],
117+
## the first letter of the text is capitalized.
118+
## E.g, "snake_case" would be converted to "Snake case" if
119+
## [param capitalize_first_letter] is [code]true[/code], else it would be converted to
120+
## "snake case".
121+
func humanize_snake_case(text: String, capitalize_first_letter := true) -> String:
122+
text = text.replace("_", " ")
123+
if capitalize_first_letter:
124+
var first_letter := text.left(1)
125+
first_letter = first_letter.capitalize()
126+
text = text.right(-1)
127+
text = text.insert(0, first_letter)
128+
return text

addons/keychain/ShortcutEdit.gd

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,10 @@ func get_action_name(action: String) -> String:
199199
display_name = Keychain.actions[action].display_name
200200

201201
if display_name.is_empty():
202-
display_name = _humanize_snake_case(action)
202+
display_name = Keychain.humanize_snake_case(action)
203203
return display_name
204204

205205

206-
func _humanize_snake_case(text: String) -> String:
207-
text = text.replace("_", " ")
208-
var first_letter := text.left(1)
209-
first_letter = first_letter.capitalize()
210-
text = text.right(-1)
211-
text = text.insert(0, first_letter)
212-
return text
213-
214-
215206
func add_event_tree_item(event: InputEvent, action_tree_item: TreeItem) -> void:
216207
var event_class := event.get_class()
217208
match event_class:

0 commit comments

Comments
 (0)
X Tutup