FunkPanion/scripts/GlobalConfigPreInit.gd

58 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:
load_from_file()
bind_keys()
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:
GlobalConfig.clone_config(Config.new())
GlobalConfig.save_to_file()
func save_to_file(file:String = "user://config.cfg") -> void:
var dict = self.format_config()
var config = ConfigFile.new()
for key in dict:
config.set_value("FunkPanion", key, dict[key])
config.save(file)
bind_keys()
func load_from_file(file:String = "user://config.cfg") -> void:
var config = ConfigFile.new()
var err = config.load(file)
if err != OK:
return
self.clone_config(Config.new_clear())
for key in config.get_section_keys("FunkPanion"):
var value = config.get_value("FunkPanion", key)
if value != null:
self[key] = value