mirror of
https://github.com/mr0xb/godot-flashcards.git
synced 2026-08-27 20:44:56 -04:00
initial commit
This commit is contained in:
commit
94847a50a2
42 changed files with 2063 additions and 0 deletions
62
scenes/autoloads/game_manager.gd
Normal file
62
scenes/autoloads/game_manager.gd
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
extends Node
|
||||
|
||||
signal scene_changed(scene_name: String)
|
||||
|
||||
var current_scene: Node = null
|
||||
var scene_container: Node = null
|
||||
|
||||
const MAIN_MENU = "res://scenes/ui/main_menu/main_menu.tscn"
|
||||
const DECK_MANAGER = "res://scenes/ui/deck_manager/deck_manager.tscn"
|
||||
const QUIZ_SCENE = "res://scenes/ui/quiz_mode/quiz_scene.tscn"
|
||||
|
||||
func _ready() -> void:
|
||||
await get_tree().process_frame
|
||||
|
||||
var root = get_tree().root
|
||||
var main = root.get_node_or_null("Main")
|
||||
|
||||
if main:
|
||||
scene_container = main.get_node_or_null("CanvasLayer/SceneContainer")
|
||||
if scene_container:
|
||||
change_scene(MAIN_MENU)
|
||||
else:
|
||||
push_error("SceneContainer not found in Main scene")
|
||||
else:
|
||||
push_warning("Main scene not found yet, waiting for initialization")
|
||||
|
||||
func change_scene(scene_path: String) -> void:
|
||||
if not scene_container:
|
||||
push_error("Cannot change scene - scene_container is null")
|
||||
return
|
||||
|
||||
if current_scene:
|
||||
current_scene.queue_free()
|
||||
await current_scene.tree_exited
|
||||
|
||||
if not ResourceLoader.exists(scene_path):
|
||||
push_error("Scene does not exist: " + scene_path)
|
||||
return
|
||||
|
||||
var new_scene_resource = load(scene_path)
|
||||
if not new_scene_resource:
|
||||
push_error("Failed to load scene: " + scene_path)
|
||||
return
|
||||
|
||||
var new_scene = new_scene_resource.instantiate()
|
||||
scene_container.add_child(new_scene)
|
||||
current_scene = new_scene
|
||||
|
||||
print("Changed scene to: " + scene_path)
|
||||
scene_changed.emit(scene_path)
|
||||
|
||||
func start_quiz(deck: Deck) -> void:
|
||||
change_scene(QUIZ_SCENE)
|
||||
await scene_changed
|
||||
if current_scene and current_scene.has_method("start_quiz"):
|
||||
current_scene.start_quiz(deck)
|
||||
|
||||
func return_to_main_menu() -> void:
|
||||
change_scene(MAIN_MENU)
|
||||
|
||||
func open_deck_manager() -> void:
|
||||
change_scene(DECK_MANAGER)
|
||||
Loading…
Reference in a new issue