FunkPanion/scripts/GlobalConfigPreInit.gd
2024-11-23 14:36:52 -06:00

61 lines
1.7 KiB
GDScript

class_name GlobalConfigPreInit
extends Config
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
self.clone_config(Config.new_clear())
load_from_file()
func bind_keys() -> void:
bind_all_keys(self.bpm_increase, "bpm_increase")
bind_all_keys(self.bpm_decrease, "bpm_decrease")
bind_all_keys(self.bpm_tsincrease, "bpm_tsincrease")
bind_all_keys(self.bpm_tsdecrease, "bpm_tsdecrease")
bind_all_keys(self.bpm_opaincrease, "bpm_opaincrease")
bind_all_keys(self.bpm_opadecrease, "bpm_opadecrease")
bind_all_keys(self.bpm_reset, "bpm_reset")
bind_all_keys(self.mod_enable, "mod_enable")
bind_all_keys(self.mod_snap_fine, "mod_snap_fine")
bind_all_keys(self.mod_snap_coarse, "mod_snap_coarse")
for action in self.anim_binds:
if not InputMap.has_action("anim_" + action):
InputMap.add_action("anim_" + action)
bind_all_keys(self.anim_binds[action], "anim_" + action)
func bind_all_keys(array, action) -> void:
InputMap.action_erase_events(action)
for key in array:
var ev = InputEventKey.new()
ev.physical_keycode = key
InputMap.action_add_event(action, ev)
func reset_settings() -> void:
var config = ConfigFile.new()
GlobalConfig.clone_config(Config.new())
config.save("user://config.cfg")
bind_keys()
func save_to_file() -> void:
var dict = self.format_config()
var config = ConfigFile.new()
for key in dict:
config.set_value("FunkPanion", key, dict[key])
config.save("user://config.cfg")
bind_keys()
func load_from_file() -> void:
var config = ConfigFile.new()
var err = config.load("user://config.cfg")
if err != OK:
return
for key in config.get_section_keys("FunkPanion"):
var value = config.get_value("FunkPanion", key)
if value != null:
self[key] = value
bind_keys()