116 lines
2.7 KiB
GDScript
116 lines
2.7 KiB
GDScript
extends Node
|
|
|
|
|
|
var configPath = OS.get_user_data_dir() + "/config.cfg";
|
|
var configObject;
|
|
|
|
const version:String = "1.3";
|
|
|
|
func Init():
|
|
LoadConfig();
|
|
return GetConfig();
|
|
|
|
func LoadConfig():
|
|
var config = load("res://scripts/Config.gd");
|
|
configObject = config.new();
|
|
|
|
var fileObj = File.new();
|
|
|
|
if not (fileObj.file_exists(configPath)):
|
|
SettingsSingleton.SetFirstStartup(true);
|
|
else :
|
|
fileObj.open(configPath, File.READ);
|
|
var content = fileObj.get_as_text();
|
|
fileObj.close();
|
|
DeserializeConfig(content);
|
|
|
|
func CreateConfigFile():
|
|
var file = File.new();
|
|
file.open(configPath, File.WRITE);
|
|
var content = SerializeConfig();
|
|
file.store_string(content);
|
|
file.close();
|
|
|
|
func DeserializeConfig(content):
|
|
var dict = parse_json(content);
|
|
if content == "":
|
|
|
|
return
|
|
|
|
var updateConfig:bool = false;
|
|
|
|
if dict.has("Version") and dict["Version"] != version:
|
|
updateConfig = true;
|
|
dict["Version"] = version;
|
|
DeleteDialogicSlots();
|
|
|
|
|
|
for i in dict.keys():
|
|
configObject[i] = dict[i];
|
|
|
|
if updateConfig:
|
|
SaveConfig();
|
|
|
|
func SerializeConfig():
|
|
var properties = [
|
|
"Language", "VoiceLanguage", "WindowState", "ScreenResolution", "LowProcessor",
|
|
"GeneralVolume", "MusicVolume", "EffectsVolume", "AutoRead", "SkipSeen",
|
|
"TextSpeed", "DefaultTheme", "TextColor", "BackgroundColor", "TwitchEnabled", "TwitchChannel", "TwitchTimer",
|
|
"Explanation", "AsyncBackgroundLoading", "UseDlc",
|
|
"Version"]
|
|
|
|
var save = {};
|
|
|
|
for i in properties:
|
|
save[i] = configObject[i];
|
|
|
|
return to_json(save);
|
|
|
|
func GetConfig():
|
|
return configObject;
|
|
|
|
func SaveConfig():
|
|
var file = File.new();
|
|
file.open(configPath, File.WRITE);
|
|
var content = SerializeConfig();
|
|
file.store_string(content);
|
|
file.close();
|
|
|
|
func DeleteDialogicSlots():
|
|
var dialogicFolder = OS.get_user_data_dir() + "/dialogic"
|
|
remove_recursive(dialogicFolder)
|
|
|
|
|
|
var slotImagesFolder = OS.get_user_data_dir() + "/slotImages"
|
|
remove_recursive(slotImagesFolder)
|
|
var dir = Directory.new();
|
|
if not dir.dir_exists(slotImagesFolder):
|
|
dir.make_dir(slotImagesFolder);
|
|
|
|
func DeleteAchievementsForReleaseVersion():
|
|
var directory = Directory.new()
|
|
var files = ["globalSeen.txt"];
|
|
for i in files:
|
|
var file = str(OS.get_user_data_dir(), "/", i);
|
|
var _kek = directory.remove(file);
|
|
|
|
func remove_recursive(path):
|
|
var directory = Directory.new()
|
|
|
|
|
|
var error = directory.open(path)
|
|
if error == OK:
|
|
|
|
directory.list_dir_begin(true)
|
|
var file_name = directory.get_next()
|
|
while file_name != "":
|
|
if directory.current_is_dir():
|
|
remove_recursive(path + "/" + file_name)
|
|
else :
|
|
directory.remove(file_name)
|
|
file_name = directory.get_next()
|
|
|
|
|
|
directory.remove(path)
|
|
else :
|
|
print("Error removing " + path)
|