From a7c7fb0b6f9f465c2a6a27344e089f772b575644 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Tue, 5 Dec 2023 13:42:52 +0100 Subject: [PATCH] store user config for db path --- godot/global.gd | 21 ++++++++++++++++++++- godot/main.gd | 5 +---- godot/project.godot | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/godot/global.gd b/godot/global.gd index 7817cb4..35e56e4 100644 --- a/godot/global.gd +++ b/godot/global.gd @@ -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) diff --git a/godot/main.gd b/godot/main.gd index ce83834..5912bbb 100644 --- a/godot/main.gd +++ b/godot/main.gd @@ -15,7 +15,4 @@ func _on_button_pressed(): print("button pressed") func _on_file_dialog_file_selected(path): - Global.db = SQLite.new() - Global.db.path = path - Global.db.verbosity_level = SQLite.VERBOSE - Global.db.open_db() + Global.load_db(path) diff --git a/godot/project.godot b/godot/project.godot index 8fbccb2..1b49b39 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -10,7 +10,7 @@ config_version=5 [application] -config/name="FabApp" +config/name="Logue" run/main_scene="res://main.tscn" config/features=PackedStringArray("4.2", "GL Compatibility") config/icon="res://icon.svg"