open SQLite from Godot

main
Fabien Freling 2023-12-04 22:19:23 +01:00
parent 1959852747
commit e406e9e44c
4 changed files with 44 additions and 1 deletions

28
godot/global.gd Normal file
View File

@ -0,0 +1,28 @@
extends Node
# https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html
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)
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

View File

@ -1,8 +1,8 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
$FileDialog.mode = FileDialog.FILE_MODE_OPEN_FILE
$FileDialog.access = FileDialog.ACCESS_FILESYSTEM
$FileDialog.use_native_dialog = true
@ -13,3 +13,9 @@ func _process(delta):
func _on_button_pressed():
$FileDialog.show()
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()

View File

@ -35,3 +35,4 @@ text = "Load database"
[node name="FileDialog" type="FileDialog" parent="."]
[connection signal="pressed" from="MarginContainer/CenterContainer/Button" to="." method="_on_button_pressed"]
[connection signal="file_selected" from="FileDialog" to="." method="_on_file_dialog_file_selected"]

View File

@ -15,11 +15,19 @@ run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.2", "GL Compatibility")
config/icon="res://icon.svg"
[autoload]
Global="*res://global.gd"
[display]
window/size/viewport_width=600
window/size/viewport_height=900
[editor_plugins]
enabled=PackedStringArray("res://addons/godot-sqlite/plugin.cfg")
[rendering]
renderer/rendering_method="gl_compatibility"