rat-times/scripts/config_manager.gd
2023-03-04 17:31:27 +04:00

86 lines
1.8 KiB
GDScript

class_name ConfigManager extends Resource
const CONFIG_PATH := "user://settings.cfg"
var _config := ConfigFile.new()
var timesheet: TimeSheet:
get:
if timesheet == null:
timesheet = TimeSheet.restore(current_file)
return timesheet
signal file_changed
var current_file: String = "":
set = set_current_file,
get = get_current_file
func set_current_file(value: String) -> void:
timesheet = TimeSheet.restore(value)
if timesheet == null:
return
current_file = value
_config.set_value("MAIN", "file", value)
file_changed.emit()
save()
func get_current_file() -> String:
var _default_path := OS.get_system_dir(OS.SYSTEM_DIR_DOCUMENTS, true).path_join("mouse_timer.csv")
return _config.get_value("MAIN", "file", _default_path)
var theme: Theme:
get:
if theme == null:
theme = ResourceLoader.load(theme_path, "Theme")
return theme
signal theme_changed
var theme_path: String = "":
set = set_theme_path,
get = 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)
theme_changed.emit()
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 = "":
set(value):
last_task_name = value
_config.set_value("MAIN", "last_task_name", value)
save()
get:
return _config.get_value("MAIN", "last_task_name", "")
var sound_fx_on: bool = true:
set(value):
sound_fx_on = value
_config.set_value("MAIN", "sound_fx_on", value)
save()
get:
return _config.get_value("MAIN", "sound_fx", true)
func _init() -> void:
_config.load(CONFIG_PATH)
func save() -> void:
_config.save(CONFIG_PATH)