From 97efcc335feda40c0627df73a8d05234f37cefb3 Mon Sep 17 00:00:00 2001 From: Xanatos <10531466+XanatosX@users.noreply.github.com> Date: Wed, 24 Jun 2026 23:45:12 +0200 Subject: [PATCH] fix: replay game button not working correctly feat: add new debug menu to the game, this should allow to add more debug functionality more easily in the future speeding up the test process. fix $19a --- .../game/debug_tool/scenes/DebugPanel.tscn | 29 ++++++++++++++ .../debug_tool/scripts/DebugFunctionality.gd | 7 ++++ .../scripts/DebugFunctionality.gd.uid | 1 + .../game/debug_tool/scripts/DebugPanel.gd | 29 ++++++++++++++ .../game/debug_tool/scripts/DebugPanel.gd.uid | 1 + .../debug_tool/scripts/FinishGameFunction.gd | 7 ++++ .../scripts/FinishGameFunction.gd.uid | 1 + .../game/finish_game/scenes/FinishGame.tscn | 2 + .../game/finish_game/scripts/ReplayGame.gd | 9 ++--- .../game/memory_game/scenes/MemoryGame.tscn | 16 +++++++- .../game/memory_game/scripts/CardSpawner.gd | 1 - .../game/memory_game/scripts/MemoryGame.gd | 1 - .../game_manager/scripts/GameManager.gd | 40 +++++++++++++------ 13 files changed, 123 insertions(+), 21 deletions(-) create mode 100644 entities/game/debug_tool/scenes/DebugPanel.tscn create mode 100644 entities/game/debug_tool/scripts/DebugFunctionality.gd create mode 100644 entities/game/debug_tool/scripts/DebugFunctionality.gd.uid create mode 100644 entities/game/debug_tool/scripts/DebugPanel.gd create mode 100644 entities/game/debug_tool/scripts/DebugPanel.gd.uid create mode 100644 entities/game/debug_tool/scripts/FinishGameFunction.gd create mode 100644 entities/game/debug_tool/scripts/FinishGameFunction.gd.uid diff --git a/entities/game/debug_tool/scenes/DebugPanel.tscn b/entities/game/debug_tool/scenes/DebugPanel.tscn new file mode 100644 index 0000000..e414947 --- /dev/null +++ b/entities/game/debug_tool/scenes/DebugPanel.tscn @@ -0,0 +1,29 @@ +[gd_scene format=3 uid="uid://laeqw1xjwd1b"] + +[ext_resource type="Script" uid="uid://be2gfsbg286u5" path="res://entities/game/debug_tool/scripts/DebugPanel.gd" id="1_8hepm"] + +[node name="DebugPanel" type="Control" unique_id=190453148] +physics_interpolation_mode = 0 +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +script = ExtResource("1_8hepm") +metadata/_custom_type_script = "uid://be2gfsbg286u5" + +[node name="CenterContainer" type="CenterContainer" parent="." unique_id=257169691] +layout_mode = 1 +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_top = -40.0 +offset_right = 40.0 +grow_vertical = 0 +mouse_filter = 2 + +[node name="ButtonHook" type="PanelContainer" parent="CenterContainer" unique_id=1406501716] +unique_name_in_owner = true +layout_mode = 2 diff --git a/entities/game/debug_tool/scripts/DebugFunctionality.gd b/entities/game/debug_tool/scripts/DebugFunctionality.gd new file mode 100644 index 0000000..c9cf472 --- /dev/null +++ b/entities/game/debug_tool/scripts/DebugFunctionality.gd @@ -0,0 +1,7 @@ +class_name DebugFunctionality extends Resource + +func get_display_name() -> String: + return "" + +func execute_function(_memory_game: MemoryGame) -> void: + pass diff --git a/entities/game/debug_tool/scripts/DebugFunctionality.gd.uid b/entities/game/debug_tool/scripts/DebugFunctionality.gd.uid new file mode 100644 index 0000000..61396dc --- /dev/null +++ b/entities/game/debug_tool/scripts/DebugFunctionality.gd.uid @@ -0,0 +1 @@ +uid://c1wsjd5pkvtiq diff --git a/entities/game/debug_tool/scripts/DebugPanel.gd b/entities/game/debug_tool/scripts/DebugPanel.gd new file mode 100644 index 0000000..24b1e58 --- /dev/null +++ b/entities/game/debug_tool/scripts/DebugPanel.gd @@ -0,0 +1,29 @@ +class_name DebugPanel extends Control + +@export var memory_game: MemoryGame +@export var debug_functions: Array[DebugFunctionality] + +@onready var button_root: Control = get_node("%ButtonHook") + +func _init() -> void: + visible = false + GlobalGameManagerAccess.game_manager.debug_mode.connect(toggle_visibility) + toggle_visibility(GlobalGameManagerAccess.game_manager.is_debug) + +func _ready() -> void: + if not OS.is_debug_build(): + queue_free() + return + if memory_game == null: + queue_free() + _create_buttons() + +func _create_buttons() -> void: + for function: DebugFunctionality in debug_functions: + var child: Button = Button.new() + child.text = function.get_display_name() + child.pressed.connect(function.execute_function.bind(memory_game)) + button_root.add_child(child) + +func toggle_visibility(new_state: bool) -> void: + visible = new_state \ No newline at end of file diff --git a/entities/game/debug_tool/scripts/DebugPanel.gd.uid b/entities/game/debug_tool/scripts/DebugPanel.gd.uid new file mode 100644 index 0000000..aa3c787 --- /dev/null +++ b/entities/game/debug_tool/scripts/DebugPanel.gd.uid @@ -0,0 +1 @@ +uid://be2gfsbg286u5 diff --git a/entities/game/debug_tool/scripts/FinishGameFunction.gd b/entities/game/debug_tool/scripts/FinishGameFunction.gd new file mode 100644 index 0000000..5df8072 --- /dev/null +++ b/entities/game/debug_tool/scripts/FinishGameFunction.gd @@ -0,0 +1,7 @@ +class_name FinishGame extends DebugFunctionality + +func get_display_name() -> String: + return "Finish Game" + +func execute_function(memory_game: MemoryGame) -> void: + memory_game.show_game_end_screen() diff --git a/entities/game/debug_tool/scripts/FinishGameFunction.gd.uid b/entities/game/debug_tool/scripts/FinishGameFunction.gd.uid new file mode 100644 index 0000000..0db1f87 --- /dev/null +++ b/entities/game/debug_tool/scripts/FinishGameFunction.gd.uid @@ -0,0 +1 @@ +uid://ce067cc441ff1 diff --git a/entities/game/finish_game/scenes/FinishGame.tscn b/entities/game/finish_game/scenes/FinishGame.tscn index c0d8740..1bf3eba 100644 --- a/entities/game/finish_game/scenes/FinishGame.tscn +++ b/entities/game/finish_game/scenes/FinishGame.tscn @@ -124,3 +124,5 @@ script = ExtResource("6_f0a12") finish_game_node = NodePath("../../../../../..") [connection signal="finish_game_ui_loaded" from="." to="PanelContainer/MarginContainer/VBoxContainer2/BodyContainer/PanelContainer/VBoxContainer2/Player List" method="build_player_statistic"] +[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer2/Footer/Buttons/OkButton" to="." method="hide"] +[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer2/Footer/Buttons/ReplayGame" to="." method="hide"] diff --git a/entities/game/finish_game/scripts/ReplayGame.gd b/entities/game/finish_game/scripts/ReplayGame.gd index a689d27..b4ddc8b 100644 --- a/entities/game/finish_game/scripts/ReplayGame.gd +++ b/entities/game/finish_game/scripts/ReplayGame.gd @@ -4,13 +4,12 @@ extends ClickableButton func _ready() -> void: await get_tree().physics_frame - if finish_game_node.played_deck == null: + if finish_game_node.played_deck == null or was_multiplayer_game(): queue_free() func _pressed() -> void: get_tree().paused = false - if multiplayer.multiplayer_peer != null: - multiplayer.multiplayer_peer.close() - GlobalGameManagerAccess.get_game_manager().play_network_game(finish_game_node.manager.get_players(), finish_game_node.played_deck, get_screen_position()) - return GlobalGameManagerAccess.get_game_manager().play_game_with_position(finish_game_node.manager.get_players(), finish_game_node.played_deck, get_screen_position()) + +func was_multiplayer_game() -> bool: + return not multiplayer.multiplayer_peer is OfflineMultiplayerPeer \ No newline at end of file diff --git a/entities/game/memory_game/scenes/MemoryGame.tscn b/entities/game/memory_game/scenes/MemoryGame.tscn index 0dfada7..7830854 100644 --- a/entities/game/memory_game/scenes/MemoryGame.tscn +++ b/entities/game/memory_game/scenes/MemoryGame.tscn @@ -31,6 +31,9 @@ [ext_resource type="Texture2D" uid="uid://vk4fpd7xo01j" path="res://assets/sprites/Axuree/wood_medium.png" id="23_a3528"] [ext_resource type="Script" uid="uid://btm576yjkyt4j" path="res://entities/game/memory_game/scripts/CardSpawner.gd" id="26_a3528"] [ext_resource type="Script" uid="uid://drr3p4wba2ys3" path="res://entities/game/memory_game/scripts/systems/NetworkHandler.gd" id="29_kihnp"] +[ext_resource type="PackedScene" uid="uid://laeqw1xjwd1b" path="res://entities/game/debug_tool/scenes/DebugPanel.tscn" id="33_j82c0"] +[ext_resource type="Script" uid="uid://c1wsjd5pkvtiq" path="res://entities/game/debug_tool/scripts/DebugFunctionality.gd" id="34_4hsit"] +[ext_resource type="Script" uid="uid://ce067cc441ff1" path="res://entities/game/debug_tool/scripts/FinishGameFunction.gd" id="35_imof5"] [ext_resource type="Script" uid="uid://p5xd1ppjr4ph" path="res://entities/game/memory_game/scripts/systems/TutorialStateSystem.gd" id="40_1resq"] [sub_resource type="Resource" id="Resource_kihnp"] @@ -60,6 +63,10 @@ script = ExtResource("17_tgl34") button_action_name = "zoom_in" metadata/_custom_type_script = "uid://cgdnmg4wop2a6" +[sub_resource type="Resource" id="Resource_8rpam"] +script = ExtResource("35_imof5") +metadata/_custom_type_script = "uid://ce067cc441ff1" + [node name="MemoryGame" type="Node2D" unique_id=648295195 node_paths=PackedStringArray("game_nodes_to_show", "card_target_node")] process_mode = 1 script = ExtResource("1_13jq5") @@ -211,8 +218,13 @@ grow_horizontal = 2 grow_vertical = 2 mouse_filter = 2 +[node name="DebugPanel" parent="UI" unique_id=190453148 node_paths=PackedStringArray("memory_game") instance=ExtResource("33_j82c0")] +memory_game = NodePath("../..") +debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")]) + [connection signal="game_paused" from="." to="Systems/PlayerInputSystem" method="game_paused"] [connection signal="game_paused" from="." to="World/Camera2D" method="game_paused"] +[connection signal="game_was_finished" from="." to="World/Camera2D" method="queue_free"] [connection signal="load_game" from="." to="Systems/CardSpawnerSystem" method="place_cards_from_deck"] [connection signal="request_popup" from="." to="Systems/PopupSystem" method="add_and_show_popup"] [connection signal="force_close_popup" from="Systems/GameStateSystem" to="Systems/PopupSystem" method="force_close_popup_with_id"] @@ -222,20 +234,20 @@ mouse_filter = 2 [connection signal="state_changed" from="Systems/GameStateSystem" to="Systems/PlayerSystem" method="game_state_changed"] [connection signal="state_changed" from="Systems/GameStateSystem" to="Systems/AiAgentSystem" method="game_state_changed"] [connection signal="state_changed" from="Systems/GameStateSystem" to="Systems/PlayerInputSystem" method="game_state_changed"] +[connection signal="state_changed" from="Systems/GameStateSystem" to="Systems/NetworkHandlerSystem" method="game_state_changed"] [connection signal="state_changed" from="Systems/GameStateSystem" to="World/Background" method="game_state_changed"] [connection signal="state_changed" from="Systems/GameStateSystem" to="World/Cards" method="game_state_changed"] [connection signal="state_changed" from="Systems/GameStateSystem" to="World/Camera2D" method="game_state_changed"] [connection signal="state_changed" from="Systems/GameStateSystem" to="UI/PlayersOverlay" method="game_state_changed"] -[connection signal="state_changed" from="Systems/GameStateSystem" to="Systems/NetworkHandlerSystem" method="game_state_changed"] [connection signal="tutorial_requested" from="Systems/TutorialStateSystem" to="Systems/PopupSystem" method="add_and_show_popup"] [connection signal="player_added" from="Systems/PlayerSystem" to="UI/PlayersOverlay" method="add_player"] [connection signal="player_changed" from="Systems/PlayerSystem" to="UI/PlayersOverlay" method="player_changed"] [connection signal="player_resource_changed" from="Systems/PlayerSystem" to="Systems/TutorialStateSystem" method="player_changed"] [connection signal="player_resource_changed" from="Systems/PlayerSystem" to="Systems/AiAgentSystem" method="player_changed"] [connection signal="player_resource_changed" from="Systems/PlayerSystem" to="Systems/PlayerInputSystem" method="player_changed"] +[connection signal="player_resource_changed" from="Systems/PlayerSystem" to="Systems/NetworkHandlerSystem" method="player_changed"] [connection signal="player_resource_changed" from="Systems/PlayerSystem" to="World/Cards" method="player_changed"] [connection signal="player_resource_changed" from="Systems/PlayerSystem" to="World/Camera2D" method="player_changed"] -[connection signal="player_resource_changed" from="Systems/PlayerSystem" to="Systems/NetworkHandlerSystem" method="player_changed"] [connection signal="player_score_changed" from="Systems/PlayerSystem" to="UI/PlayersOverlay" method="player_scored"] [connection signal="card_movement" from="Systems/PlayerInputSystem" to="World/Cards" method="parse_movement"] [connection signal="confirm_current_card" from="Systems/PlayerInputSystem" to="World/Cards" method="confirm_current_card"] diff --git a/entities/game/memory_game/scripts/CardSpawner.gd b/entities/game/memory_game/scripts/CardSpawner.gd index 9533a38..79c88d3 100644 --- a/entities/game/memory_game/scripts/CardSpawner.gd +++ b/entities/game/memory_game/scripts/CardSpawner.gd @@ -43,7 +43,6 @@ func place_cards_from_deck(deck_to_use: MemoryDeckResource) -> void: _place_thread.start(_add_cards_to_field_async.bind(cards, _card_target_node)) await card_placing_done - _place_thread = null for card: CardTemplate in cards: card.visible = true diff --git a/entities/game/memory_game/scripts/MemoryGame.gd b/entities/game/memory_game/scripts/MemoryGame.gd index d3eaa0a..5487322 100644 --- a/entities/game/memory_game/scripts/MemoryGame.gd +++ b/entities/game/memory_game/scripts/MemoryGame.gd @@ -30,7 +30,6 @@ var game_menu: GamePauseMenu = null var ending_round: bool = false -var message_banner: PackedScene = preload("res://entities/game/bottom_message_banner/scenes/BottomMessageBanner.tscn") var auto_close_popup: PackedScene = preload("res://entities/game/auto_close_popup/scenes/AutoClosePopup.tscn") var last_message_banner_id: int = -1 diff --git a/shared/global_entities/game_manager/scripts/GameManager.gd b/shared/global_entities/game_manager/scripts/GameManager.gd index 1bed296..ef9fcc6 100644 --- a/shared/global_entities/game_manager/scripts/GameManager.gd +++ b/shared/global_entities/game_manager/scripts/GameManager.gd @@ -128,16 +128,13 @@ func translate_built_in_decks() -> void: translated_build_in_decks.append(new_deck) func close_game_with_position(transition_start_position: Vector2) -> void: - var nodes: Array[Node] = get_children() + var previous_children: Array[Node] = _get_active_children() var animation_scene: AnimationScene = await ScreenTransitionManager.transit_screen_with_position(main_menu_template, transition_start_position) await animation_scene.animation_done - for node: Node in nodes: - if node == null or node.is_queued_for_deletion(): - continue - if node.name == "GlobalFixedNode" or node.is_in_group("static"): + for child: Node in previous_children: + if child == null or child.is_queued_for_deletion(): continue - node.queue_free() - + child.queue_free() func close_game() -> void: close_game_with_position(Vector2.ZERO) @@ -243,6 +240,7 @@ func _rpc_load_game(game_data: Dictionary) -> void: func load_game(card_deck: Resource, players: Array[PlayerResource], click_position: Vector2) -> void: var current_player_id: int = 0 + var active_nodes: Array[Node] = _get_active_children() for player: PlayerResource in players: player.id = current_player_id current_player_id = current_player_id + 1 @@ -256,12 +254,20 @@ func load_game(card_deck: Resource, players: Array[PlayerResource], click_positi ) + var old_camera: Camera2D = get_viewport().get_camera_2d() var loading_screen: LoadingScreen = loading_screen_template.instantiate() as LoadingScreen loading_screen.add_to_group("game_initialize_scene") loading_screen.set_follow_up_node(game_scene_node) await ScreenTransitionManager.transit_screen_by_node_with_position(loading_screen, click_position, false) + if old_camera != null and not old_camera.is_queued_for_deletion(): + old_camera.zoom = Vector2.ONE + old_camera.queue_free() add_child(game_scene_node) + for node: Node in active_nodes: + if node == null or node.is_queued_for_deletion(): + continue + node.queue_free() func get_available_decks() -> Array[MemoryDeckResource]: @@ -273,10 +279,13 @@ func get_available_decks() -> Array[MemoryDeckResource]: return return_array func clear_all_nodes() -> void: - for child: Node in get_children(): - if child.name == "GlobalFixedNode" or child.is_in_group("static"): - continue - remove_child(child) + for child: Node in get_children(): + if child == null or child.is_queued_for_deletion(): + continue + if child.name == "GlobalFixedNode" or child.is_in_group("static"): + continue + remove_child(child) + child.queue_free() func loading_data_done() -> void: if initial_menu_shown: @@ -290,4 +299,11 @@ func loading_data_done() -> void: current_loading_node.call("destroy") return current_loading_node.queue_free() - #open_menu(main_menu_template) + +func _get_active_children() -> Array[Node]: + var children: Array[Node] = [] + for child: Node in get_children(): + if child == null or child.is_queued_for_deletion(): + continue + children.append(child) + return children