class_name ConfigManager extends Resource signal file_changed signal time_sheet_reloaded const CONFIG_PATH := "user://settings.cfg" var timesheet: TimeSheet setget ,get_timesheet var _config := ConfigFile.new() var _watcher: FileWatcher func get_timesheet() -> TimeSheet: if timesheet == null: timesheet = _load_timesheet(get_current_file()) return timesheet func _load_timesheet(path: String) -> TimeSheet: timesheet = TimeSheet.restore(path) if timesheet == null: return null _watcher = FileWatcher.new() _watcher.file_name = path # warning-ignore:return_value_discarded _watcher.connect("file_changed", self, "reload_timesheet") _watcher.start() # warning-ignore:return_value_discarded #timesheet.connect("entry_started", self, "_on_entry_started") # warning-ignore:return_value_discarded #timesheet.connect("entry_stopped", self, "_on_entry_stopped") return timesheet func reload_timesheet() -> void: var new_timesheet = _load_timesheet(get_current_file()) if new_timesheet == null: printerr("failed to load new timesheet") return timesheet = new_timesheet emit_signal("time_sheet_reloaded") var current_file: String = "" setget set_current_file, get_current_file func set_current_file(value: String) -> void: timesheet = _load_timesheet(value) if timesheet == null: return current_file = value _config.set_value("MAIN", "file", value) emit_signal("file_changed") save() func get_current_file() -> String: var _default_path := OS.get_system_dir(OS.SYSTEM_DIR_DOCUMENTS, true).plus_file("mouse_timer.csv") return _config.get_value("MAIN", "file", _default_path) var theme: Theme setget , get_theme func get_theme() -> Theme: if theme == null: theme = ResourceLoader.load(theme_path, "Theme") return theme signal theme_changed var theme_path: String = "" setget set_theme_path, get_theme_path func set_theme_path(value: String) -> void: var new_theme: Theme = ResourceLoader.load(value, "Theme") if new_theme != null: theme = new_theme theme_path = value _config.set_value("MAIN", "theme", value) emit_signal("theme_changed") save() func get_theme_path() -> String: return _config.get_value("MAIN", "theme", preload("res://assets/default_theme.theme").resource_path) var last_task_name: String = "" setget set_last_task_name, get_last_task_name func set_last_task_name(value: String) -> void: last_task_name = value _config.set_value("MAIN", "last_task_name", value) save() func get_last_task_name() -> String: return _config.get_value("MAIN", "last_task_name", "") var sound_fx_on: bool = true setget set_sound_fx_on, get_sound_fx_on func set_sound_fx_on(value: bool) -> void: sound_fx_on = value _config.set_value("MAIN", "sound_fx_on", value) save() func get_sound_fx_on() -> bool: return _config.get_value("MAIN", "sound_fx", true) func _init() -> void: # warning-ignore:return_value_discarded _config.load(CONFIG_PATH) func save() -> void: # warning-ignore:return_value_discarded _config.save(CONFIG_PATH)