store user config for db path

This commit is contained in:
Fabien Freling 2023-12-05 13:42:52 +01:00
parent 0965eea94b
commit a7c7fb0b6f
3 changed files with 22 additions and 6 deletions

View file

@ -1,12 +1,31 @@
extends Node
# https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html
const config_path = "user://logue.cfg"
var config = ConfigFile.new()
var db : SQLite = SQLite.new()
var current_scene = null
var db : SQLite = null
func _ready():
var root = get_tree().root
current_scene = root.get_child(root.get_child_count() - 1)
db.verbosity_level = SQLite.VERBOSE
var err = config.load(config_path)
if err == OK:
var db_path = config.get_value("general", "db_path")
load_db(db_path)
func load_db(path: String):
db.path = path
var success = db.open_db()
if success:
config.set_value("general", "db_path", path)
config.save(config_path)
else:
db.path = ""
func goto_scene(path):
call_deferred("_deferred_goto_scene", path)