From d0c903a91c05ac47b2546cbf2f7cf674f4c46239 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Jun 2025 00:52:09 +0000 Subject: [PATCH 1/4] Initial plan for issue From e0e974bf0190923cb67de839fd8b66f2f82f79d7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Jun 2025 01:00:30 +0000 Subject: [PATCH 2/4] Implement dynamic game scene loading and unloading Co-authored-by: saebyn <185030+saebyn@users.noreply.github.com> --- scenes/main.tscn | 5 +---- scripts/gamemanager.gd | 10 +++++++++- scripts/main.gd | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/scenes/main.tscn b/scenes/main.tscn index b9a208b..3b43b3e 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -1,14 +1,11 @@ -[gd_scene load_steps=4 format=3 uid="uid://c1ibyecb1dmow"] +[gd_scene load_steps=3 format=3 uid="uid://c1ibyecb1dmow"] -[ext_resource type="PackedScene" uid="uid://cc2n5bb6al7qg" path="res://scenes/game.tscn" id="1_0xm2m"] [ext_resource type="Script" uid="uid://c8qyieqgdrge2" path="res://scripts/main.gd" id="1_h2yge"] [ext_resource type="PackedScene" uid="uid://dax0hhxr4xyjj" path="res://ui/menu.tscn" id="2_h2yge"] [node name="Main" type="Node2D"] script = ExtResource("1_h2yge") -[node name="GameScene" parent="." instance=ExtResource("1_0xm2m")] - [node name="GameMenu" parent="." instance=ExtResource("2_h2yge")] anchors_preset = 0 anchor_right = 0.0 diff --git a/scripts/gamemanager.gd b/scripts/gamemanager.gd index c520ac5..fc76029 100644 --- a/scripts/gamemanager.gd +++ b/scripts/gamemanager.gd @@ -12,4 +12,12 @@ class Score extends Resource: self.score = score_ self.initials = initials_ -@export var high_scores: Array[Score] = [] \ No newline at end of file +@export var high_scores: Array[Score] = [] + +func reset_game() -> void: + # Reset game state - placeholder for actual game logic + pass + +func restart_level() -> void: + # Restart current level - placeholder for actual game logic + pass \ No newline at end of file diff --git a/scripts/main.gd b/scripts/main.gd index d141f5d..dedd010 100644 --- a/scripts/main.gd +++ b/scripts/main.gd @@ -1,9 +1,12 @@ extends Node2D @onready var game_menu := $GameMenu -@onready var game_scene := $GameScene @onready var music_player := $MusicAudioStreamPlayer +# Dynamic game scene management +var game_scene: Node2D = null +var game_scene_packed: PackedScene = preload("res://scenes/game.tscn") + func _ready() -> void: GameManager.game_over.connect(_on_game_manager_game_over) @@ -13,7 +16,8 @@ func _on_game_manager_game_over(player_won: bool) -> void: get_tree().paused = true # Load the game over screen game_menu.show() - game_scene.hide() + if game_scene: + game_scene.hide() func _input(event: InputEvent) -> void: if event.is_action_pressed("ui_cancel"): @@ -32,10 +36,14 @@ func is_game_paused() -> bool: func pause_game() -> void: - game_menu.pause() + # Only pause if there's an active game scene + if game_scene: + game_menu.pause() func resume_game() -> void: - game_menu.unpause() + # Only unpause if there's an active game scene + if game_scene: + game_menu.unpause() func _on_game_menu_exit_game() -> void: @@ -47,7 +55,11 @@ func _on_game_menu_return_main_menu() -> void: # Return to the main menu get_tree().paused = true game_menu.show() - game_scene.hide() + + # Unload the game scene completely + if game_scene: + game_scene.queue_free() + game_scene = null func _on_game_menu_start_game() -> void: @@ -56,7 +68,12 @@ func _on_game_menu_start_game() -> void: # Hide the game menu game_menu.hide() - # Start the game scene + # Load and instantiate the game scene + if not game_scene: + game_scene = game_scene_packed.instantiate() + add_child(game_scene) + + # Show the game scene game_scene.show() # start the music @@ -67,5 +84,12 @@ func _on_game_menu_start_game() -> void: func _on_game_menu_restart_game() -> void: print("Restarting game") + + # Ensure game scene is loaded before restarting + if not game_scene: + game_scene = game_scene_packed.instantiate() + add_child(game_scene) + game_scene.show() + GameManager.restart_level() resume_game() From e344651d643f34ec3e0c8fc9b2b213e9e693fdaf Mon Sep 17 00:00:00 2001 From: saebyn Date: Sun, 8 Jun 2025 18:10:25 -0700 Subject: [PATCH 3/4] Update scripts/main.gd Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- scripts/main.gd | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/main.gd b/scripts/main.gd index dedd010..649f09f 100644 --- a/scripts/main.gd +++ b/scripts/main.gd @@ -69,10 +69,7 @@ func _on_game_menu_start_game() -> void: game_menu.hide() # Load and instantiate the game scene - if not game_scene: - game_scene = game_scene_packed.instantiate() - add_child(game_scene) - + ensure_game_scene_loaded() # Show the game scene game_scene.show() From b4e7027a47708dee44d1911ae47b451d3d91d072 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Jun 2025 01:13:33 +0000 Subject: [PATCH 4/4] Implement ensure_game_scene_loaded function to eliminate code duplication Co-authored-by: saebyn <185030+saebyn@users.noreply.github.com> --- scripts/main.gd | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/main.gd b/scripts/main.gd index 649f09f..582a44c 100644 --- a/scripts/main.gd +++ b/scripts/main.gd @@ -46,6 +46,13 @@ func resume_game() -> void: game_menu.unpause() +func ensure_game_scene_loaded() -> void: + # Ensure the game scene is loaded and added to the scene tree + if not game_scene: + game_scene = game_scene_packed.instantiate() + add_child(game_scene) + + func _on_game_menu_exit_game() -> void: # Exit the game get_tree().quit() @@ -83,10 +90,8 @@ func _on_game_menu_restart_game() -> void: print("Restarting game") # Ensure game scene is loaded before restarting - if not game_scene: - game_scene = game_scene_packed.instantiate() - add_child(game_scene) - game_scene.show() + ensure_game_scene_loaded() + game_scene.show() GameManager.restart_level() resume_game()