feature/match3/move-gems (#7)

Reviewed-on: #7
Co-authored-by: Vladimir nett00n Budylnikov <git@nett00n.org>
Co-committed-by: Vladimir nett00n Budylnikov <git@nett00n.org>
This commit is contained in:
2025-09-25 11:48:08 +02:00
committed by nett00n
parent e76297b3f3
commit ea8c85d7ad
53 changed files with 2335 additions and 524 deletions

View File

@@ -4,6 +4,7 @@ const GAME_SCENE_PATH := "res://scenes/game/game.tscn"
const MAIN_SCENE_PATH := "res://scenes/main/main.tscn"
var pending_gameplay_mode: String = "match3"
var is_changing_scene: bool = false
func start_new_game() -> void:
start_game_with_mode("match3")
@@ -15,25 +16,86 @@ func start_clickomania_game() -> void:
start_game_with_mode("clickomania")
func start_game_with_mode(gameplay_mode: String) -> void:
# Input validation for gameplay mode
if not gameplay_mode or gameplay_mode.is_empty():
DebugManager.log_error("Empty or null gameplay mode provided", "GameManager")
return
if not gameplay_mode is String:
DebugManager.log_error("Invalid gameplay mode type: " + str(typeof(gameplay_mode)), "GameManager")
return
# Prevent concurrent scene changes
if is_changing_scene:
DebugManager.log_warn("Scene change already in progress, ignoring request", "GameManager")
return
# Validate gameplay mode against allowed values
var valid_modes = ["match3", "clickomania"]
if not gameplay_mode in valid_modes:
DebugManager.log_error("Invalid gameplay mode: '%s'. Valid modes: %s" % [gameplay_mode, str(valid_modes)], "GameManager")
return
is_changing_scene = true
pending_gameplay_mode = gameplay_mode
var packed_scene := load(GAME_SCENE_PATH)
if not packed_scene or not packed_scene is PackedScene:
DebugManager.log_error("Failed to load Game scene at: %s" % GAME_SCENE_PATH, "GameManager")
is_changing_scene = false
return
get_tree().change_scene_to_packed(packed_scene)
# Wait one frame for the scene to be ready, then set gameplay mode
var result = get_tree().change_scene_to_packed(packed_scene)
if result != OK:
DebugManager.log_error("Failed to change to game scene (Error code: %d)" % result, "GameManager")
is_changing_scene = false
return
# Wait for scene to be properly instantiated and added to tree
await get_tree().process_frame
if get_tree().current_scene and get_tree().current_scene.has_method("set_gameplay_mode"):
await get_tree().process_frame # Additional frame for complete initialization
# Validate scene was loaded successfully
if not get_tree().current_scene:
DebugManager.log_error("Current scene is null after scene change", "GameManager")
is_changing_scene = false
return
# Set gameplay mode with timeout protection
if get_tree().current_scene.has_method("set_gameplay_mode"):
DebugManager.log_info("Setting gameplay mode to: %s" % pending_gameplay_mode, "GameManager")
get_tree().current_scene.set_gameplay_mode(pending_gameplay_mode)
else:
DebugManager.log_error("Game scene does not have set_gameplay_mode method", "GameManager")
is_changing_scene = false
func save_game() -> void:
DebugManager.log_info("Game saved (mock)", "GameManager")
func exit_to_main_menu() -> void:
# Prevent concurrent scene changes
if is_changing_scene:
DebugManager.log_warn("Scene change already in progress, ignoring exit to main menu request", "GameManager")
return
is_changing_scene = true
DebugManager.log_info("Attempting to exit to main menu", "GameManager")
var packed_scene := load(MAIN_SCENE_PATH)
if not packed_scene or not packed_scene is PackedScene:
DebugManager.log_error("Failed to load Main scene at: %s" % MAIN_SCENE_PATH, "GameManager")
is_changing_scene = false
return
DebugManager.log_info("Loading main scene", "GameManager")
get_tree().change_scene_to_packed(packed_scene)
var result = get_tree().change_scene_to_packed(packed_scene)
if result != OK:
DebugManager.log_error("Failed to change to main scene (Error code: %d)" % result, "GameManager")
is_changing_scene = false
return
DebugManager.log_info("Successfully loaded main scene", "GameManager")
# Wait for scene to be ready, then mark scene change as complete
await get_tree().process_frame
is_changing_scene = false