fabapp/godot/global.gd

48 lines
1.2 KiB
GDScript3
Raw Normal View History

2023-12-04 22:19:23 +01:00
extends Node
# https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html
2023-12-05 13:42:52 +01:00
const config_path = "user://logue.cfg"
var config = ConfigFile.new()
var db : SQLite = SQLite.new()
2023-12-04 22:19:23 +01:00
var current_scene = null
func _ready():
var root = get_tree().root
current_scene = root.get_child(root.get_child_count() - 1)
2023-12-05 13:42:52 +01:00
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 = ""
2023-12-04 22:19:23 +01:00
func goto_scene(path):
call_deferred("_deferred_goto_scene", path)
func _deferred_goto_scene(path):
# It is now safe to remove the current scene.
current_scene.free()
# Load the new scene.
var s = ResourceLoader.load(path)
# Instance the new scene.
current_scene = s.instantiate()
# Add it to the active scene, as child of root.
get_tree().root.add_child(current_scene)
# Optionally, to make it compatible with the SceneTree.change_scene_to_file() API.
get_tree().current_scene = current_scene