rat-times/scripts/config_manager.gd

86 lines
1.8 KiB
GDScript3
Raw Permalink Normal View History

2023-03-03 21:12:54 +00:00
class_name ConfigManager extends Resource
const CONFIG_PATH := "user://settings.cfg"
var _config := ConfigFile.new()
2023-03-04 13:31:27 +00:00
var timesheet: TimeSheet:
get:
if timesheet == null:
timesheet = TimeSheet.restore(current_file)
return timesheet
signal file_changed
2023-03-03 21:12:54 +00:00
var current_file: String = "":
2023-03-04 13:31:27 +00:00
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:
2023-03-03 21:12:54 +00:00
get:
2023-03-04 13:31:27 +00:00
if theme == null:
theme = ResourceLoader.load(theme_path, "Theme")
return theme
2023-03-03 21:12:54 +00:00
2023-03-04 13:31:27 +00:00
signal theme_changed
2023-03-03 21:12:54 +00:00
var theme_path: String = "":
2023-03-04 13:31:27 +00:00
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)
2023-03-03 21:12:54 +00:00
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)