format
Some checks failed
Some checks failed
This commit is contained in:
@@ -20,15 +20,20 @@ func _ready() -> void:
|
||||
|
||||
# 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"
|
||||
"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")
|
||||
DebugManager.log_info(
|
||||
"set_gameplay_mode called with mode: %s" % mode, "Game"
|
||||
)
|
||||
current_gameplay_mode = mode
|
||||
await load_gameplay(mode)
|
||||
DebugManager.log_info("set_gameplay_mode completed for mode: %s" % mode, "Game")
|
||||
DebugManager.log_info(
|
||||
"set_gameplay_mode completed for mode: %s" % mode, "Game"
|
||||
)
|
||||
|
||||
|
||||
func load_gameplay(mode: String) -> void:
|
||||
@@ -37,24 +42,35 @@ func load_gameplay(mode: String) -> void:
|
||||
# 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")
|
||||
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")
|
||||
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(),
|
||||
(
|
||||
"Children removal complete, container count: %d"
|
||||
% gameplay_container.get_child_count()
|
||||
),
|
||||
"Game"
|
||||
)
|
||||
|
||||
# Load new gameplay
|
||||
if GAMEPLAY_SCENES.has(mode):
|
||||
DebugManager.log_debug("Found scene path: %s" % GAMEPLAY_SCENES[mode], "Game")
|
||||
DebugManager.log_debug(
|
||||
"Found scene path: %s" % GAMEPLAY_SCENES[mode], "Game"
|
||||
)
|
||||
var gameplay_scene = load(GAMEPLAY_SCENES[mode])
|
||||
var gameplay_instance = gameplay_scene.instantiate()
|
||||
DebugManager.log_debug("Instantiated gameplay: %s" % gameplay_instance.name, "Game")
|
||||
DebugManager.log_debug(
|
||||
"Instantiated gameplay: %s" % gameplay_instance.name, "Game"
|
||||
)
|
||||
gameplay_container.add_child(gameplay_instance)
|
||||
DebugManager.log_debug(
|
||||
(
|
||||
@@ -69,7 +85,9 @@ func load_gameplay(mode: String) -> void:
|
||||
gameplay_instance.score_changed.connect(_on_score_changed)
|
||||
DebugManager.log_debug("Connected score_changed signal", "Game")
|
||||
else:
|
||||
DebugManager.log_error("Gameplay mode '%s' not found in GAMEPLAY_SCENES" % mode, "Game")
|
||||
DebugManager.log_error(
|
||||
"Gameplay mode '%s' not found in GAMEPLAY_SCENES" % mode, "Game"
|
||||
)
|
||||
|
||||
|
||||
func set_global_score(value: int) -> void:
|
||||
@@ -102,10 +120,15 @@ func _on_back_button_pressed() -> void:
|
||||
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():
|
||||
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")
|
||||
DebugManager.log_warn(
|
||||
"Gameplay instance invalid, skipping grid save on exit", "Game"
|
||||
)
|
||||
|
||||
# Save the current score immediately before exiting
|
||||
SaveManager.finish_game(global_score)
|
||||
@@ -116,7 +139,10 @@ func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_back"):
|
||||
# Handle gamepad/keyboard back action - same as back button
|
||||
_on_back_button_pressed()
|
||||
elif event.is_action_pressed("action_south") and Input.is_action_pressed("action_north"):
|
||||
elif (
|
||||
event.is_action_pressed("action_south")
|
||||
and Input.is_action_pressed("action_north")
|
||||
):
|
||||
# Debug: Switch to clickomania when primary+secondary actions pressed together
|
||||
if current_gameplay_mode == "match3":
|
||||
set_gameplay_mode("clickomania")
|
||||
|
||||
Reference in New Issue
Block a user