From 6ec3c5764a9a4ec1447520f69d5f4b457fa7fb46 Mon Sep 17 00:00:00 2001 From: Xanatos <10531466+XanatosX@users.noreply.github.com> Date: Tue, 30 Jun 2026 17:38:11 +0200 Subject: [PATCH 1/2] fix: broken AI actions There was an issue with the implementation of the new interaction field. This did result in the AI not loading the card id's correctly anymore. This commit will move all data from the cards to the interaction field making this the game logic host. The cards are visible only now. They still do hold data but it's not used anymore. fix $19o --- .../card_collider/scripts/CardCollider.gd | 9 + .../card_template/scripts/CardTemplate.gd | 3 - .../game/memory_game/scenes/MemoryGame.tscn | 30 +-- .../scripts/CardInteractionField.gd | 101 ++++++++-- .../game/memory_game/scripts/CardSpawner.gd | 182 ------------------ .../memory_game/scripts/CardSpawner.gd.uid | 1 - .../game/memory_game/scripts/GameCardGrid.gd | 85 +++----- .../game/memory_game/scripts/MemoryGame.gd | 2 + .../resources/behaviors/GetMatchingCard.gd | 45 ++--- .../clickable_button/ClickableButton.gd | 2 +- 10 files changed, 153 insertions(+), 307 deletions(-) delete mode 100644 entities/game/memory_game/scripts/CardSpawner.gd delete mode 100644 entities/game/memory_game/scripts/CardSpawner.gd.uid diff --git a/entities/game/card_collider/scripts/CardCollider.gd b/entities/game/card_collider/scripts/CardCollider.gd index 6155d28d..09bd0bfd 100644 --- a/entities/game/card_collider/scripts/CardCollider.gd +++ b/entities/game/card_collider/scripts/CardCollider.gd @@ -10,10 +10,19 @@ var _shape: CollisionShape2D = null var _mouse_inside: bool = false var _active_state: bool = false +var _card_id: int = -1 func _ready() -> void: _shape = get_node("%CollisionShape") +func set_card_id(id: int) -> void: + if _card_id != -1: + return + _card_id = id + +func get_card_id() -> int: + return _card_id + func set_size(size: Vector2) -> void: var shape: RectangleShape2D = RectangleShape2D.new() shape.size = size diff --git a/entities/game/card_template/scripts/CardTemplate.gd b/entities/game/card_template/scripts/CardTemplate.gd index 408f0880..849d003f 100644 --- a/entities/game/card_template/scripts/CardTemplate.gd +++ b/entities/game/card_template/scripts/CardTemplate.gd @@ -281,9 +281,6 @@ func play_sound(audio: AudioStream) -> void: return GlobalSoundManager.play_sound_effect(audio) -func player_changed(ai_player: bool) -> void: - input_allowed(!ai_player) - func input_allowed(allowed: bool) -> void: input_active.emit(allowed) diff --git a/entities/game/memory_game/scenes/MemoryGame.tscn b/entities/game/memory_game/scenes/MemoryGame.tscn index 48d391e9..aafd594a 100644 --- a/entities/game/memory_game/scenes/MemoryGame.tscn +++ b/entities/game/memory_game/scenes/MemoryGame.tscn @@ -30,7 +30,6 @@ [ext_resource type="Script" uid="uid://6fa28680utd5" path="res://shared/entities/popup_manager/scripts/PopupSystem.gd" id="21_dv4ao"] [ext_resource type="PackedScene" uid="uid://d15qeu4s4bgjk" path="res://entities/game/tutorial_window/scenes/TutorialWindow.tscn" id="22_ubsrg"] [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://cf8loyigibdp6" path="res://entities/game/memory_game/scripts/CardInteractionField.gd" id="27_7lv0s"] [ext_resource type="PackedScene" uid="uid://0m4c62oqj4ih" path="res://entities/game/card_collider/scene/CardCollider.tscn" id="28_7ou1n"] [ext_resource type="Script" uid="uid://drr3p4wba2ys3" path="res://entities/game/memory_game/scripts/systems/NetworkHandler.gd" id="29_kihnp"] @@ -120,11 +119,6 @@ script = ExtResource("29_kihnp") finished_game_template = ExtResource("4_6f670") metadata/_custom_type_script = "uid://drr3p4wba2ys3" -[node name="CardSpawnerSystem" type="Node" parent="Systems" unique_id=1452917331] -script = ExtResource("26_a3528") -card_template = ExtResource("3_ihyl6") -metadata/_custom_type_script = "uid://btm576yjkyt4j" - [node name="UiInformationSystem" type="Node" parent="Systems" unique_id=1812178848] unique_name_in_owner = true script = ExtResource("36_m766l") @@ -146,6 +140,7 @@ script = ExtResource("19_ploi3") state_machine = NodePath("../../Systems/GameStateSystem") matching_card_sound_effect = ExtResource("6_a3528") visual_card_node = NodePath("CardVisuals") +card_template = ExtResource("3_ihyl6") [node name="CardInteractionField" type="Node2D" parent="World/CardBoard" unique_id=1435215390] z_index = 10 @@ -239,9 +234,9 @@ mouse_filter = 2 memory_game = NodePath("../..") debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")]) +[connection signal="announce_deck" from="." to="World/CardBoard" method="set_deck"] [connection signal="game_paused" from="." to="Systems/PlayerInputSystem" method="game_paused"] [connection signal="game_paused" from="." to="World/Camera2D" method="game_paused"] -[connection signal="load_game" from="." to="Systems/CardSpawnerSystem" method="place_cards_from_deck"] [connection signal="load_game" from="." to="World/CardBoard/CardInteractionField" method="set_board_information"] [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"] @@ -282,19 +277,6 @@ debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")] [connection signal="player_has_changed" from="Systems/NetworkHandlerSystem" to="Systems/PlayerSystem" method="set_player_by_id"] [connection signal="player_has_scored" from="Systems/NetworkHandlerSystem" to="Systems/PlayerSystem" method="set_player_score"] [connection signal="remove_card" from="Systems/NetworkHandlerSystem" to="World/CardBoard" method="remove_card_from_board"] -[connection signal="announce_field_size" from="Systems/CardSpawnerSystem" to="World/Camera2D" method="adjust_zoom_and_position_to_play_area"] -[connection signal="card_placed" from="Systems/CardSpawnerSystem" to="." method="card_was_placed"] -[connection signal="card_placed" from="Systems/CardSpawnerSystem" to="World/CardBoard" method="card_was_placed"] -[connection signal="card_placed" from="Systems/CardSpawnerSystem" to="World/CardBoard/CardInteractionField" method="card_was_added"] -[connection signal="card_placing_done" from="Systems/CardSpawnerSystem" to="." method="all_cards_placed"] -[connection signal="card_placing_done" from="Systems/CardSpawnerSystem" to="Systems/GameStateSystem" method="game_field_ready"] -[connection signal="card_placing_done" from="Systems/CardSpawnerSystem" to="World/CardBoard" method="card_loading_done"] -[connection signal="card_placing_done" from="Systems/CardSpawnerSystem" to="UI/PauseMenuButton" method="show_button_if_valid"] -[connection signal="card_placing_done" from="Systems/CardSpawnerSystem" to="UI/PlayersOverlay" method="show"] -[connection signal="card_placing_done" from="Systems/CardSpawnerSystem" to="UI/ZoomButtons/ZoomIn" method="show_button_if_valid"] -[connection signal="card_placing_done" from="Systems/CardSpawnerSystem" to="UI/ZoomButtons/ZoomOut" method="show_button_if_valid"] -[connection signal="field_constructed" from="Systems/CardSpawnerSystem" to="World/CardBoard" method="receive_field_size"] -[connection signal="field_constructed" from="Systems/CardSpawnerSystem" to="World/CardBoard/CardInteractionField" method="build_field"] [connection signal="all_matching_cards_removed" from="World/CardBoard" to="." method="all_cards_removed"] [connection signal="all_matching_cards_removed" from="World/CardBoard" to="Systems/GameStateSystem" method="matches_found"] [connection signal="all_matching_cards_removed" from="World/CardBoard" to="Systems/TutorialStateSystem" method="matching_card_found"] @@ -307,7 +289,15 @@ debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")] [connection signal="card_triggered" from="World/CardBoard" to="Systems/AiAgentSystem" method="card_was_triggered"] [connection signal="identical_cards" from="World/CardBoard" to="Systems/AiAgentSystem" method="card_was_identically"] [connection signal="no_matches_found" from="World/CardBoard" to="Systems/GameStateSystem" method="no_matches"] +[connection signal="board_area" from="World/CardBoard/CardInteractionField" to="World/Camera2D" method="adjust_zoom_and_position_to_play_area"] +[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="." method="all_cards_placed"] +[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="Systems/GameStateSystem" method="game_field_ready"] +[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="UI/PauseMenuButton" method="show_button_if_valid"] +[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="UI/PlayersOverlay" method="show"] +[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="UI/ZoomButtons/ZoomIn" method="show_button_if_valid"] +[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="UI/ZoomButtons/ZoomOut" method="show_button_if_valid"] [connection signal="clicked" from="World/CardBoard/CardInteractionField" to="World/CardBoard" method="trigger_card_at_position"] [connection signal="mouse_enter" from="World/CardBoard/CardInteractionField" to="World/CardBoard" method="select_card_at_position"] +[connection signal="place_card" from="World/CardBoard/CardInteractionField" to="World/CardBoard" method="place_card"] [connection signal="touch_used" from="World/Camera2D" to="World/CardBoard" method="disable_card_effects"] [connection signal="pressed" from="UI/PauseMenuButton" to="." method="show_game_menu"] diff --git a/entities/game/memory_game/scripts/CardInteractionField.gd b/entities/game/memory_game/scripts/CardInteractionField.gd index c7411d0f..906851c9 100644 --- a/entities/game/memory_game/scripts/CardInteractionField.gd +++ b/entities/game/memory_game/scripts/CardInteractionField.gd @@ -4,6 +4,10 @@ signal mouse_enter(grid: Vector2i) signal mouse_left(grid: Vector2i) signal clicked(grid: Vector2i) +signal place_card(card: MemoryCardResource, grid_position: Vector2i, world_position: Vector2) +signal board_area(area: Rect2) +signal board_build() + enum Axis {X, Y} @export var default_texture_size: Vector2 = Vector2(499, 550) @@ -19,6 +23,9 @@ var _is_ai_player: bool = false var _selected_grid_position: Vector2i = -Vector2i.ONE var _controller_input_was_made: bool = false +var _placed_cards: Dictionary[Vector2i, CardCollider] +var _current_deck: MemoryDeckResource = null + var possible_movements: Array[Vector2] = [ Vector2.RIGHT, Vector2.DOWN, @@ -26,11 +33,12 @@ var possible_movements: Array[Vector2] = [ Vector2.UP ] - func _reset_grid_position() -> void: _selected_grid_position = -Vector2i.ONE func set_board_information(deck_to_use: MemoryDeckResource, card_separation: int, field_offset: Vector2i) -> void: + _current_deck = deck_to_use + var back_image: Texture2D = deck_to_use.get_back_image() _card_size = default_texture_size if back_image != null: @@ -38,10 +46,48 @@ func set_board_information(deck_to_use: MemoryDeckResource, card_separation: int _separation = card_separation _offset = field_offset -func build_field(cards_on_x: int, cards_on_y: int) -> void: - _field_size = Vector2i(cards_on_x, cards_on_y) - for x: int in cards_on_x: - for y: int in cards_on_y: + await _create_field() + var area: Rect2 = _calculate_field_area() + board_area.emit(area) + board_build.emit() + +func _create_field() -> void: + var play_cards: Array[MemoryCardResource] = _create_card_set() + _field_size = _calculate_field_size(play_cards.size()) + + build_field(play_cards) + await RenderingServer.frame_post_draw + +func _calculate_field_size(card_count: int) -> Vector2i: + if card_count <= 0: + return Vector2i.ZERO + + var side_length: int = floori(sqrt(card_count)) + + var row_count: int = side_length + var column_count: int = side_length + + while row_count * column_count < card_count: + column_count = column_count + 1 + + return Vector2i(column_count, row_count) + +func _create_card_set() -> Array[MemoryCardResource]: + var return_data: Array[MemoryCardResource] = [] + for card: MemoryCardResource in _current_deck.cards: + return_data.append(card) + return_data.append(card) + + return_data.shuffle() + return return_data + +func build_field(cards: Array[MemoryCardResource]) -> void: + for x: int in _field_size.x: + for y: int in _field_size.y: + if cards.size() == 0: + return + var card: MemoryCardResource = cards.pick_random() + _remove_card_from_cards_stack(card.id, cards) var x_addition: int = _separation * x x_addition += int(_card_size.x) * x var y_addition: int = _separation * y @@ -50,10 +96,24 @@ func build_field(cards_on_x: int, cards_on_y: int) -> void: template.set_size(_card_size) template.position = _offset + additional_offset + Vector2i(x_addition, y_addition) template.set_grid_coordinate(Vector2i(x, y)) + template.set_card_id(card.id) _connect_card_interaction(template) - + _placed_cards.set(Vector2i(x, y), template) add_child(template) template.disable_collider() + place_card.emit(card, Vector2i(x, y), Vector2i(x_addition, y_addition) + _offset) + +func _calculate_field_area() -> Rect2: + var field_width: float = _card_size.x * _field_size.x + var field_height: float = _card_size.y * _field_size.y + + var center_x: float = field_width / 2 + var center_y: float = field_height / 2 + return Rect2(center_x, center_y, field_width, field_height) + +func _remove_card_from_cards_stack(id: int, cards: Array[MemoryCardResource]) -> void: + var index: int = cards.find_custom((func(card: MemoryCardResource) -> bool: return card.id == id)) + cards.remove_at(index) func get_field_size() -> Vector2i: return _field_size @@ -62,28 +122,30 @@ func card_was_added(card: CardTemplate) -> void: card.remove_requested.connect(remove_card.bind(card.grid_position)) func remove_card(grid_position: Vector2i) -> void: - for child: CardCollider in get_children(): - if child.get_grid_coordinate() == grid_position: - child.queue_free() + if _placed_cards.has(grid_position): + var child: CardCollider = _placed_cards.get(grid_position) + child.queue_free() + _placed_cards.erase(grid_position) func player_changed(current_player: PlayerResource) -> void: _is_ai_player = current_player.is_ai() func game_state_changed(new_state: GameEnum.State) -> void: var _new_collider_enabled_state: bool = false - if new_state == GameEnum.State.TURN_START and not _is_ai_player: + if new_state == GameEnum.State.TURN_START: _new_collider_enabled_state = true - + if new_state == GameEnum.State.TURN_FREEZE: _new_collider_enabled_state = false _change_interaction_state(_new_collider_enabled_state) func _change_interaction_state(new_state: bool) -> void: - for child: CardCollider in get_children(): + for child: CardCollider in _placed_cards.values(): if new_state: - child.enable_collider() child.reset() + if not _is_ai_player: + child.enable_collider() else: child.disable_collider() @@ -145,9 +207,14 @@ func _get_closest_card_position(movement: Vector2) -> Vector2i: return return_position +func get_card_id_from_position(grid_position: Vector2i) -> int: + if _placed_cards.has(grid_position): + return _placed_cards.get(grid_position).get_card_id() + return -1 + func get_all_card_positions(get_turned: bool = false) -> Array[Vector2i]: var card_positions: Array[Vector2i] = [] - for card_collider: CardCollider in get_children(): + for card_collider: CardCollider in _placed_cards.values(): if card_collider != null and not card_collider.is_queued_for_deletion(): if get_turned or card_collider.is_active(): card_positions.append(card_collider.get_grid_coordinate()) @@ -155,14 +222,14 @@ func get_all_card_positions(get_turned: bool = false) -> Array[Vector2i]: func get_all_disabled_cards() -> Array[Vector2i]: var card_positions: Array[Vector2i] = [] - for card_collider: CardCollider in get_children(): + for card_collider: CardCollider in _placed_cards.values(): if card_collider != null and not card_collider.is_queued_for_deletion(): if not card_collider.is_active(): card_positions.append(card_collider.get_grid_coordinate()) return card_positions func is_there_a_card_on_position(grid_position: Vector2i) -> bool: - for card_collider: CardCollider in get_children(): + for card_collider: CardCollider in _placed_cards.values(): if card_collider.get_grid_coordinate() == grid_position: var active: bool = card_collider.is_active() return active @@ -170,7 +237,7 @@ func is_there_a_card_on_position(grid_position: Vector2i) -> bool: func _get_all_relevant_available_cards(current_pos: Vector2i, go_negative: bool, axis: Axis) -> Array[Vector2i]: var valid_cards: Array[Vector2i] = [] - for card_collider: Node in get_children(): + for card_collider: Node in _placed_cards.values(): if card_collider != null and not card_collider.is_queued_for_deletion() and card_collider is CardCollider: if _check_if_valid_card(current_pos, go_negative, axis, card_collider): valid_cards.append(card_collider.get_grid_coordinate()) diff --git a/entities/game/memory_game/scripts/CardSpawner.gd b/entities/game/memory_game/scripts/CardSpawner.gd deleted file mode 100644 index a2335107..00000000 --- a/entities/game/memory_game/scripts/CardSpawner.gd +++ /dev/null @@ -1,182 +0,0 @@ -class_name CardSpawnerSystem extends Node - -signal field_constructed(cards_on_x: int, cards_on_y: int) -signal card_loading_done() -signal announce_field_size(area: Rect2) -signal card_placed(card: CardTemplate) -signal card_placing_done() - -@export var card_template: PackedScene -#@export var separation: int = 25 -# A artificial wait time between each card placement, this does prevent a total blockage of the game -@export var artificial_wait_time: int = 4 -#@export var place_offset: Vector2 = Vector2.ZERO -@onready var _card_target_node: Node2D = get_node("%CardBoard/CardVisuals") - -var _field_size: Vector2i = Vector2i.ZERO -var _current_deck: MemoryDeckResource - -func _ready() -> void: - process_mode = Node.PROCESS_MODE_DISABLED - if _card_target_node == null: - push_error("Missing \"Cards\" node") - queue_free() - -func place_cards_from_deck(deck_to_use: MemoryDeckResource, card_separation: int, field_offset: Vector2i) -> void: - _current_deck = deck_to_use - if multiplayer.is_server(): - _rpc_announce_deck.rpc(deck_to_use.resource_path) - - var loaded_cards: Array[CardTemplate] = await build_card_layout(deck_to_use, card_template, card_separation, field_offset) - - field_constructed.emit(_field_size.x, _field_size.y) - process_mode = PROCESS_MODE_INHERIT - - await _add_cards_to_field_async(loaded_cards, _card_target_node) - card_placing_done.emit() - - for card: CardTemplate in loaded_cards: - card.visible = true - announce_card_field() - card_loading_done.emit() - queue_free() - -func _add_cards_to_field_async(cards: Array[CardTemplate], target: Node2D) -> void: - for card: CardTemplate in cards: - card.visible = false - target.add_child(card) - - card_placed.emit(card) - - for i: int in artificial_wait_time: - await get_tree().physics_frame - -func _calculate_field_size(cards_on_x: int, cards_on_y: int, separation: int) -> void: - if card_template == null: - return - var card_instance: CardTemplate = card_template.instantiate() as CardTemplate - var card_height: float = card_instance.get_height() + separation - var card_width: float = card_instance.get_width() + separation - - var field_width: float = card_width * cards_on_x - var field_height: float = card_height * cards_on_y - - var center_x: float = field_width / 2 - var center_y: float = field_height / 2 - - var field: Rect2 = Rect2(center_x, center_y, field_width, field_height) - if multiplayer.is_server(): - _rpc_sync_field_size.rpc({ - "x": field.position.x, - "y": field.position.y, - "width": field.size.x, - "height": field.size.y - }) - announce_field_size.emit(field) - -func build_card_layout(deck_of_cards: MemoryDeckResource, - template: PackedScene, - card_separation: int, - offset: Vector2i - ) -> Array[CardTemplate]: - var return_cards: Array[CardTemplate] = [] - var card_pool: Array[MemoryCardResource] = deck_of_cards.cards - var additional_cards: Array[MemoryCardResource] = deck_of_cards.cards - card_pool = numbering_cards_from_pool(card_pool) - card_pool.append_array(numbering_cards_from_pool(additional_cards)) - for i: int in range((randi() % 20) + 1): - card_pool.shuffle() - - var current_card: int = 0 - var side_length: int = floori(sqrt(card_pool.size())) - - var row_count: int = side_length - var column_count: int = side_length - - while row_count * column_count < card_pool.size(): - column_count = column_count + 1 - _calculate_field_size(column_count, row_count, card_separation) - for y: int in row_count: - for x: int in column_count: - var card_template_node: CardTemplate = template.instantiate() as CardTemplate - card_template_node.card_deck = deck_of_cards - if current_card >= card_pool.size(): - print("exceed pool!") - continue - card_template_node.memory_card = card_pool[current_card] - var height: float = card_template_node.get_height() - var width: float = card_template_node.get_width() - var height_to_set: float = y * height + y * card_separation - var width_to_set: float = x * width + x * card_separation - height_to_set += offset.y - width_to_set += offset.x - card_template_node.position = Vector2(width_to_set, height_to_set) - card_template_node.grid_position = Vector2i(x, y) - - return_cards.append(card_template_node) - current_card = current_card + 1 - await get_tree().physics_frame - _field_size = Vector2i(column_count, row_count) - return return_cards - -func numbering_cards_from_pool(card_pool: Array[MemoryCardResource]) -> Array[MemoryCardResource]: - var cards: Array[MemoryCardResource] - for i: int in card_pool.size(): - var card: MemoryCardResource = card_pool[i] as MemoryCardResource - cards.append(card) - return cards - -@rpc("authority", "reliable") -func _rpc_announce_deck(path: String) -> void: - if _current_deck == null: - _current_deck = load(path) - -func announce_card_field() -> void: - if !multiplayer.is_server(): - return - var network_cards: Array[Dictionary] = [] - for card: CardTemplate in _card_target_node.get_children().filter(func(data: Node) -> bool: return data is CardTemplate): - var real_card: MemoryCardResource = card.memory_card - network_cards.append({ - "id": real_card.get_id(), - "grid-position": { - "x": card.grid_position.x, - "y": card.grid_position.y, - }, - "world-position": { - "x": card.global_position.x, - "y": card.global_position.y, - }, - "card-resource": real_card.resource_path - }) - - _rpc_rebuild_field.rpc({"cards": network_cards}) - -@rpc("authority", "reliable") -func _rpc_rebuild_field(field: Dictionary) -> void: - if multiplayer.is_server(): - return - for card: Dictionary in field["cards"]: - var real_card: CardTemplate = card_template.instantiate() as CardTemplate - var world_pos: Dictionary = card["world-position"] - var grid_pos: Dictionary = card["grid-position"] - real_card.global_position = Vector2(world_pos["x"], world_pos["y"]) - real_card.grid_position = Vector2i(grid_pos["x"], grid_pos["y"]) - real_card.memory_card = load(card["card-resource"]) - real_card.card_deck = _current_deck - - real_card.visible = true - card_placed.emit(real_card) - - _card_target_node.add_child(real_card) - print("connect signals") - queue_free() - - card_loading_done.emit() - -@rpc("authority", "reliable") -func _rpc_sync_field_size(field_size: Dictionary) -> void: - if multiplayer.is_server(): - return - var rect: Rect2 = Rect2(field_size["x"], field_size["y"], field_size["width"], field_size["height"]) - announce_field_size.emit(rect) diff --git a/entities/game/memory_game/scripts/CardSpawner.gd.uid b/entities/game/memory_game/scripts/CardSpawner.gd.uid deleted file mode 100644 index 1e15b991..00000000 --- a/entities/game/memory_game/scripts/CardSpawner.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://btm576yjkyt4j diff --git a/entities/game/memory_game/scripts/GameCardGrid.gd b/entities/game/memory_game/scripts/GameCardGrid.gd index 35f7399a..5d23c115 100644 --- a/entities/game/memory_game/scripts/GameCardGrid.gd +++ b/entities/game/memory_game/scripts/GameCardGrid.gd @@ -13,6 +13,8 @@ signal card_activated() @export var matching_card_sound_effect: AudioStream @export var visual_card_node: Node2D +@export var card_template: PackedScene + var current_card: CardTemplate var controller_input_was_made: bool = false @@ -20,50 +22,14 @@ var currently_ai_player: bool = false var number_of_triggered_cards: int = 0 -var _field_size: Vector2i = Vector2i.ZERO var _game_completed: bool = false -enum Axis {X, Y} +var _deck: MemoryDeckResource = null -func get_current_grid_position() -> Vector2i: - if current_card == null: - return -Vector2i.ONE - return current_card.grid_position - -func receive_field_size(x: int, y: int) -> void: - _field_size = Vector2i(x - 1, y - 1) # Field size starts at 1 but index starts at 0 - -func get_field_size() -> Vector2i: - return _field_size - -func _get_valid_card_positions(current_pos: Vector2i, go_negative: bool, axis: Axis) -> Array[Vector2i]: - var all_card_positions: Array[Vector2i] = get_card_grid(current_pos); - var valid_cards: Array[Vector2i] = [] - for card_position: Vector2i in all_card_positions: - var current_card_position: int = 0 - var current_position: int = 0 - match axis: - Axis.X: - current_card_position = card_position.x - current_position = current_pos.x - Axis.Y: - current_card_position = card_position.y - current_position = current_pos.y - - if go_negative and current_card_position >= current_position: - continue - if !go_negative and current_card_position <= current_position: - continue - valid_cards.append(card_position) - return valid_cards - -func get_card_grid(current_pos: Vector2i) -> Array[Vector2i]: - var all_cards: Array[Vector2i] = [] - for card: Node2D in visual_card_node.get_children(): - if card is CardTemplate and card.grid_position != current_pos and not card.is_getting_removed(): - all_cards.append(card.grid_position) +enum Axis {X, Y} - return all_cards +func set_deck(deck: MemoryDeckResource) -> void: + _deck = deck func trigger_card_at_position(grid_position: Vector2i) -> void: if select_card_at_position(grid_position): @@ -101,29 +67,12 @@ func select_card_at_position(grid_position: Vector2i) -> bool: current_card.got_focus() return found_card - -func get_card_on_position(card_position: Vector2i) -> MemoryCardResource: - for card: CardTemplate in _get_game_card_templates_children(): - if card_position == card.grid_position: - return card.memory_card - return null - func round_frozen() -> void: current_card = null -func card_loading_done() -> void: - for card: CardTemplate in _get_game_card_templates(): - card.mouse_was_used.connect(func() -> void: - current_card = null - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - ) - func game_state_changed(game_state: GameEnum.State) -> void: match game_state: GameEnum.State.TURN_START: - for card: CardTemplate in _get_game_card_templates(): - card.player_changed(currently_ai_player) - print(_get_game_card_templates().size()) if _get_game_card_templates().size() == 0: _announce_empty_board() @@ -217,24 +166,38 @@ func disable_card_effects() -> void: func _get_game_card_templates_children() -> Array[CardTemplate]: var return_data: Array[CardTemplate] - for card_template: CardTemplate in visual_card_node.get_children().filter(func(data: Node) -> bool: return data is CardTemplate): - return_data.append(card_template) + for template: CardTemplate in visual_card_node.get_children().filter(func(data: Node) -> bool: return data is CardTemplate): + return_data.append(template) return return_data func _get_game_card_templates() -> Array[CardTemplate]: var return_data: Array[CardTemplate] - for card_template: CardTemplate in get_tree().get_nodes_in_group("game_card").filter(func(card: Node) -> bool: return card is CardTemplate): - return_data.append(card_template) + for template: CardTemplate in get_tree().get_nodes_in_group("game_card").filter(func(card: Node) -> bool: return card is CardTemplate): + return_data.append(template) return return_data func prevent_input(prevent: bool) -> void: for card: CardTemplate in _get_game_card_templates_children(): card.input_allowed(!prevent) +# remove func card_was_placed(card: CardTemplate) -> void: card.card_triggered.connect(card_triggered_hook) state_machine.state_changed.connect(card.game_state_changed) +func place_card(card: MemoryCardResource, grid_position: Vector2i, world_position: Vector2) -> void: + var card_template_node: CardTemplate = card_template.instantiate() as CardTemplate + card_template_node.memory_card = card + card_template_node.position = world_position + card_template_node.grid_position = grid_position + card_template_node.card_deck = _deck + + visual_card_node.add_child(card_template_node) + + ## Should be changed + card_template_node.card_triggered.connect(card_triggered_hook) + state_machine.state_changed.connect(card_template_node.game_state_changed) + func card_triggered_hook(card: CardTemplate) -> void: select_card_at_position(card.grid_position) card_triggered.emit(card) diff --git a/entities/game/memory_game/scripts/MemoryGame.gd b/entities/game/memory_game/scripts/MemoryGame.gd index f55c0743..95df8250 100644 --- a/entities/game/memory_game/scripts/MemoryGame.gd +++ b/entities/game/memory_game/scripts/MemoryGame.gd @@ -1,6 +1,7 @@ class_name MemoryGame extends Node2D signal load_game(card_deck: MemoryDeckResource, separation: int, field_offset: Vector2i) +signal announce_deck(card_deck: MemoryDeckResource) signal game_paused(is_paused: bool) @@ -47,6 +48,7 @@ func set_card_deck(deck: MemoryDeckResource) -> void: _card_deck = deck func start_loading_data() -> void: + announce_deck.emit(_card_deck) load_game.emit(_card_deck, card_separation, field_offset) func _process(_delta: float) -> void: diff --git a/shared/entities/ai_behavior/resources/behaviors/GetMatchingCard.gd b/shared/entities/ai_behavior/resources/behaviors/GetMatchingCard.gd index b5f8e9e8..200b912b 100644 --- a/shared/entities/ai_behavior/resources/behaviors/GetMatchingCard.gd +++ b/shared/entities/ai_behavior/resources/behaviors/GetMatchingCard.gd @@ -1,29 +1,30 @@ class_name GetMatchingCard extends AiBehaviorNode func can_execute(blackboard: Blackboard, grid: CardInteractionField) -> bool: - var unrevealed_cards: Array[Vector2i] = grid.get_all_disabled_cards() - if unrevealed_cards.size() != 1: - return false; + var unrevealed_cards: Array[Vector2i] = grid.get_all_disabled_cards() + if unrevealed_cards.size() != 1: + return false; - var card_of_focus: Vector2i = unrevealed_cards[0] - var loaded_card: MemoryCardResource = grid.get_card_on_position(card_of_focus) - if loaded_card == null: - return false; - var stored_cards: Array[CardInformationResource] = blackboard.get_all_cards_with_id(loaded_card.id) - for stored_card: CardInformationResource in stored_cards: - if !stored_card.position == card_of_focus: - return true - return false + var card_of_focus: Vector2i = unrevealed_cards[0] + var id: int = grid.get_card_id_from_position(card_of_focus) + if id == -1: + return false + var stored_cards: Array[CardInformationResource] = blackboard.get_all_cards_with_id(id) + for stored_card: CardInformationResource in stored_cards: + if !stored_card.position == card_of_focus: + return true + return false func execute_action(blackboard: Blackboard, grid: CardInteractionField) -> void: - print_debug("GetMatchingCard") - var unrevealed_cards: Array[Vector2i] = grid.get_al() - var card_of_focus: Vector2i = unrevealed_cards[0] - var loaded_card: MemoryCardResource = grid.get_card_on_position(card_of_focus) - var card_to_reveal: CardInformationResource = null - var stored_cards: Array[CardInformationResource] = blackboard.get_all_cards_with_id(loaded_card.id) + print_debug("GetMatchingCard") + var unrevealed_cards: Array[Vector2i] = grid.get_all_disabled_cards() + var card_of_focus: Vector2i = unrevealed_cards[0] + + var id: int = grid.get_card_id_from_position(card_of_focus) + var card_to_reveal: CardInformationResource = null + var stored_cards: Array[CardInformationResource] = blackboard.get_all_cards_with_id(id) - for stored_card: CardInformationResource in stored_cards: - if not stored_card.position == (card_of_focus): - card_to_reveal = stored_card - _trigger_card(card_to_reveal.position, blackboard, grid) + for stored_card: CardInformationResource in stored_cards: + if not stored_card.position == (card_of_focus): + card_to_reveal = stored_card + _trigger_card(card_to_reveal.position, blackboard, grid) diff --git a/shared/entities/clickable_button/ClickableButton.gd b/shared/entities/clickable_button/ClickableButton.gd index d6d726b6..26620214 100644 --- a/shared/entities/clickable_button/ClickableButton.gd +++ b/shared/entities/clickable_button/ClickableButton.gd @@ -97,7 +97,7 @@ func check_if_can_execute() -> void: func _process(_delta: float) -> void: if button_behavior != null: button_behavior.process() - if not can_request_debug_view: + if not can_request_debug_view: return if Input.is_action_just_pressed("toggle_debug") and OS.is_debug_build(): From 6a7932cd31dfe739494647220d6b63c9667efd47 Mon Sep 17 00:00:00 2001 From: Xanatos <10531466+XanatosX@users.noreply.github.com> Date: Tue, 30 Jun 2026 17:40:17 +0200 Subject: [PATCH 2/2] chore: increase game version to 0.20.1 --- project.godot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.godot b/project.godot index 06ffc35c..4f8d516f 100644 --- a/project.godot +++ b/project.godot @@ -15,7 +15,7 @@ compatibility/default_parent_skeleton_in_mesh_instance_3d=true [application] config/name="Samory" -config/version="0.20.0" +config/version="0.20.1" config/tags=PackedStringArray("public") run/main_scene="res://shared/global_entities/game_manager/scenes/GameManager.tscn" config/features=PackedStringArray("4.7", "GL Compatibility")