open SQLite from Godot
This commit is contained in:
parent
1959852747
commit
e406e9e44c
28
godot/global.gd
Normal file
28
godot/global.gd
Normal 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
|
|
@ -1,8 +1,8 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
$FileDialog.mode = FileDialog.FILE_MODE_OPEN_FILE
|
||||||
$FileDialog.access = FileDialog.ACCESS_FILESYSTEM
|
$FileDialog.access = FileDialog.ACCESS_FILESYSTEM
|
||||||
$FileDialog.use_native_dialog = true
|
$FileDialog.use_native_dialog = true
|
||||||
|
|
||||||
|
@ -13,3 +13,9 @@ func _process(delta):
|
||||||
func _on_button_pressed():
|
func _on_button_pressed():
|
||||||
$FileDialog.show()
|
$FileDialog.show()
|
||||||
print("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()
|
||||||
|
|
|
@ -35,3 +35,4 @@ text = "Load database"
|
||||||
[node name="FileDialog" type="FileDialog" parent="."]
|
[node name="FileDialog" type="FileDialog" parent="."]
|
||||||
|
|
||||||
[connection signal="pressed" from="MarginContainer/CenterContainer/Button" to="." method="_on_button_pressed"]
|
[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"]
|
||||||
|
|
|
@ -15,11 +15,19 @@ run/main_scene="res://main.tscn"
|
||||||
config/features=PackedStringArray("4.2", "GL Compatibility")
|
config/features=PackedStringArray("4.2", "GL Compatibility")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
Global="*res://global.gd"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/size/viewport_width=600
|
window/size/viewport_width=600
|
||||||
window/size/viewport_height=900
|
window/size/viewport_height=900
|
||||||
|
|
||||||
|
[editor_plugins]
|
||||||
|
|
||||||
|
enabled=PackedStringArray("res://addons/godot-sqlite/plugin.cfg")
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
renderer/rendering_method="gl_compatibility"
|
renderer/rendering_method="gl_compatibility"
|
||||||
|
|
Loading…
Reference in a new issue