saves and score are added
This commit is contained in:
@@ -16,20 +16,29 @@ func _ready() -> void:
|
||||
if not back_button.pressed.is_connected(_on_back_button_pressed):
|
||||
back_button.pressed.connect(_on_back_button_pressed)
|
||||
|
||||
# Default to match3 for now
|
||||
set_gameplay_mode("match3")
|
||||
# GameManager will set the gameplay mode, don't set default here
|
||||
DebugManager.log_debug("Game _ready() completed, waiting for GameManager to set gameplay mode", "Game")
|
||||
|
||||
func set_gameplay_mode(mode: String) -> void:
|
||||
DebugManager.log_info("set_gameplay_mode called with mode: %s" % mode, "Game")
|
||||
current_gameplay_mode = mode
|
||||
load_gameplay(mode)
|
||||
await load_gameplay(mode)
|
||||
DebugManager.log_info("set_gameplay_mode completed for mode: %s" % mode, "Game")
|
||||
|
||||
func load_gameplay(mode: String) -> void:
|
||||
DebugManager.log_debug("Loading gameplay mode: %s" % mode, "Game")
|
||||
|
||||
# Clear existing gameplay
|
||||
for child in gameplay_container.get_children():
|
||||
DebugManager.log_debug("Removing existing child: %s" % child.name, "Game")
|
||||
child.queue_free()
|
||||
# Clear existing gameplay and wait for removal
|
||||
var existing_children = gameplay_container.get_children()
|
||||
if existing_children.size() > 0:
|
||||
DebugManager.log_debug("Removing %d existing children" % existing_children.size(), "Game")
|
||||
for child in existing_children:
|
||||
DebugManager.log_debug("Removing existing child: %s" % child.name, "Game")
|
||||
child.queue_free()
|
||||
|
||||
# Wait for children to be properly removed from scene tree
|
||||
await get_tree().process_frame
|
||||
DebugManager.log_debug("Children removal complete, container count: %d" % gameplay_container.get_child_count(), "Game")
|
||||
|
||||
# Load new gameplay
|
||||
if GAMEPLAY_SCENES.has(mode):
|
||||
@@ -54,11 +63,32 @@ func set_global_score(value: int) -> void:
|
||||
|
||||
func _on_score_changed(points: int) -> void:
|
||||
self.global_score += points
|
||||
SaveManager.update_current_score(self.global_score)
|
||||
|
||||
func get_global_score() -> int:
|
||||
return global_score
|
||||
|
||||
func _get_current_gameplay_instance() -> Node:
|
||||
if gameplay_container.get_child_count() > 0:
|
||||
return gameplay_container.get_child(0)
|
||||
return null
|
||||
|
||||
func _on_back_button_pressed() -> void:
|
||||
DebugManager.log_debug("Back button pressed in game scene", "Game")
|
||||
AudioManager.play_ui_click()
|
||||
GameManager.save_game()
|
||||
|
||||
# Save current grid state if we have an active match3 gameplay
|
||||
var gameplay_instance = _get_current_gameplay_instance()
|
||||
if gameplay_instance and gameplay_instance.has_method("save_current_state"):
|
||||
DebugManager.log_info("Saving grid state before exit", "Game")
|
||||
# Make sure the gameplay instance is still valid and not being destroyed
|
||||
if is_instance_valid(gameplay_instance) and gameplay_instance.is_inside_tree():
|
||||
gameplay_instance.save_current_state()
|
||||
else:
|
||||
DebugManager.log_warn("Gameplay instance invalid, skipping grid save on exit", "Game")
|
||||
|
||||
# Save the current score immediately before exiting
|
||||
SaveManager.finish_game(global_score)
|
||||
GameManager.exit_to_main_menu()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
|
||||
Reference in New Issue
Block a user