extends Node

const SETTINGS_FILE_PATH = "user://settings.json"

signal changed(key, new_value)

#@onready var audio = $"/root/SimpleAudioLibrary"
var filesystem = preload("res://scripts/services/filesystem.gd").new()
var os_string = ""

var settings = {

	#/home/rubberduck/levels_test/
	"editor_level_path": "",
	"selected_level": "testlevel_01"
}


func _ready():
	self.load_settings_from_file()

func save_settings_to_file():
	self.filesystem.write_data_as_json_to_file(self.SETTINGS_FILE_PATH, self.settings)

func load_settings_from_file():
	var loaded_settings = self.filesystem.read_json_from_file(self.SETTINGS_FILE_PATH)

	for settings_key in loaded_settings:
		self.settings[settings_key] = loaded_settings[settings_key]
		self._apply_option(settings_key)
		print ("setting found: " + str(loaded_settings[settings_key]))

func get_option(key):
	if self.settings.has(key):
		return self.settings[key]
	return null

func set_option(key, value):
	print ("set option called..")
	self.settings[key] = value
	self.save_settings_to_file()

	self._apply_option(key)
	self.changed.emit(key, value)

func _apply_option(key):
	pass












