A Godot Engine app to help streamers organize Majority Judgment polls in their streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 lines
1.3 KiB

extends Node
# Meant to be used as a singleton.
# Don't store Objects in here for now.
export(String) var file_path := "user://config.ini"
var __config : Dictionary
func get_parameter(parameter_key:String, default=null):
hydrate_lazily()
if self.__config.has(parameter_key):
# print("[Config] Reading parameter `%s' from Config." % parameter_key)
return self.__config[parameter_key]
else:
# print("[Config] Using default value for parameter `%s'." % parameter_key)
return default
func set_parameter(parameter_key:String, parameter_value) -> void:
self.__config[parameter_key] = parameter_value
write_to_file(self.__config)
func hydrate_lazily() -> void:
if null == self.__config or self.__config.empty():
self.__config = load_from_file()
func write_to_file(config_to_write:Dictionary) -> void:
var file = File.new()
var opened = file.open(self.file_path, File.WRITE)
if OK != opened:
printerr("[Config] Cannot write to file `%s'." % self.file_path)
return
file.store_var(config_to_write)
file.close()
func load_from_file() -> Dictionary:
var file = File.new()
var opened = file.open(self.file_path, File.READ)
if OK != opened:
printerr("[Config] Cannot read from file `%s'." % self.file_path)
return {} # null
var data = file.get_var()
assert(data is Dictionary)
file.close()
return data