Skip to content

Commit

Permalink
Merge pull request mbrlabs#159 from HuntClauss/main
Browse files Browse the repository at this point in the history
primitive config with custom shortcuts
  • Loading branch information
mbrlabs authored Jul 4, 2022
2 parents d38b9aa + 34c4ff3 commit b8392e1
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lorien/Misc/Settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ var language_names: PoolStringArray
func _ready():
_config_file = ConfigFile.new()
_load_settings()
reload_locales()
reload_locales()
_setup_shortcuts()
_load_shortcuts()

# -------------------------------------------------------------------------------------------------
func reload_locales():
Expand All @@ -51,7 +53,7 @@ func _save_settings() -> int:
if err == ERR_FILE_NOT_FOUND:
pass
elif err != OK:
printerr("Failed to load settings file")
printerr("Failed to save settings file")

return err

Expand All @@ -64,4 +66,32 @@ func set_value(key: String, value = null):
_config_file.set_value(DEFAULT_SECTION, key, value)
_save_settings()

# -------------------------------------------------------------------------------------------------
func _setup_shortcuts(override = false) -> void:
for action_name in InputMap.get_actions():
if !override && _config_file.has_section_key("shortcuts", action_name):
continue

set_default_shortcut(action_name)
_save_settings()

# -------------------------------------------------------------------------------------------------
func set_default_shortcut(action_name: String, save = false) -> void:
var shortcuts = []
for event in InputMap.get_action_list(action_name):
shortcuts.append(event)

_config_file.set_value("shortcuts", action_name, shortcuts)
if save:
_save_settings()

# -------------------------------------------------------------------------------------------------
func _load_shortcuts() -> void:
for action_name in InputMap.get_actions():
if !_config_file.has_section_key("shortcuts", action_name):
continue
var shortcuts = _config_file.get_value("shortcuts", action_name)
InputMap.action_erase_events(action_name)

for shortcut in shortcuts:
InputMap.action_add_event(action_name, shortcut)

0 comments on commit b8392e1

Please sign in to comment.