Compare commits
	
		
			2 commits
		
	
	
		
			0965eea94b
			...
			810a3aa9b5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						810a3aa9b5 | ||
| 
							 | 
						a7c7fb0b6f | 
					 3 changed files with 36 additions and 6 deletions
				
			
		| 
						 | 
					@ -1,13 +1,46 @@
 | 
				
			||||||
extends Node
 | 
					extends Node
 | 
				
			||||||
# https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html
 | 
					# https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					signal state_changed(previous, new)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum State {UNLOADED, LOADED}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const config_path = "user://logue.cfg"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var config = ConfigFile.new()
 | 
				
			||||||
 | 
					var db = SQLite.new()
 | 
				
			||||||
var current_scene = null
 | 
					var current_scene = null
 | 
				
			||||||
var db : SQLite = null
 | 
					var current_state = State.UNLOADED
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _ready():
 | 
					func _ready():
 | 
				
			||||||
	var root = get_tree().root
 | 
						var root = get_tree().root
 | 
				
			||||||
	current_scene = root.get_child(root.get_child_count() - 1)
 | 
						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 switch_state(new: State):
 | 
				
			||||||
 | 
						var old = current_state
 | 
				
			||||||
 | 
						if old == new:
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						current_state = new
 | 
				
			||||||
 | 
						#signal state_changed(old, new)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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):
 | 
					func goto_scene(path):
 | 
				
			||||||
	call_deferred("_deferred_goto_scene", path)
 | 
						call_deferred("_deferred_goto_scene", path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,4 @@ func _on_button_pressed():
 | 
				
			||||||
	print("button pressed")
 | 
						print("button pressed")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _on_file_dialog_file_selected(path):
 | 
					func _on_file_dialog_file_selected(path):
 | 
				
			||||||
	Global.db = SQLite.new()
 | 
						Global.load_db(path)
 | 
				
			||||||
	Global.db.path = path
 | 
					 | 
				
			||||||
	Global.db.verbosity_level = SQLite.VERBOSE
 | 
					 | 
				
			||||||
	Global.db.open_db()
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,7 +10,7 @@ config_version=5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[application]
 | 
					[application]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
config/name="FabApp"
 | 
					config/name="Logue"
 | 
				
			||||||
run/main_scene="res://main.tscn"
 | 
					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"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue