122 lines
2.9 KiB
GDScript
122 lines
2.9 KiB
GDScript
class_name ConfigManager extends Resource
|
|
|
|
|
|
signal entry_started
|
|
signal entry_stopped
|
|
signal file_changed
|
|
|
|
const CONFIG_PATH := "user://settings.cfg"
|
|
var _config := ConfigFile.new()
|
|
var _watcher: FileWatcher
|
|
|
|
var timesheet: TimeSheet setget ,get_timesheet
|
|
|
|
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:
|
|
_watcher = null
|
|
return null
|
|
_watcher = FileWatcher.new()
|
|
_watcher.file_name = path
|
|
_watcher.start()
|
|
# warning-ignore:return_value_discarded
|
|
_watcher.connect("file_changed", self, "_on_file_changed")
|
|
# 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 _on_entry_started() -> void:
|
|
emit_signal("entry_started")
|
|
|
|
func _on_entry_stopped() -> void:
|
|
emit_signal("entry_stopped")
|
|
|
|
|
|
func _on_file_changed() -> void:
|
|
emit_signal("file_changed")
|
|
|
|
|
|
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)
|