From e14e6a5b6234b650d1198966d4f240689b766961 Mon Sep 17 00:00:00 2001 From: Xanatos <10531466+XanatosX@users.noreply.github.com> Date: Fri, 26 Jun 2026 22:12:46 +0200 Subject: [PATCH] feat: extract mouse interaction Commit will extract the mouse interaction from the card template and create a system out of it. fix $19e --- .../card_collider/scene/CardCollider.tscn | 17 ++++ .../card_collider/scripts/CardCollider.gd | 48 +++++++++++ .../card_collider/scripts/CardCollider.gd.uid | 1 + .../scripts/CollisionShapeGenerator.gd | 1 + .../scripts/CollisionShapeGenerator.gd.uid | 1 + .../card_template/scenes/CardTemplate.tscn | 19 +---- .../card_template/scripts/CardTemplate.gd | 2 - .../scripts/ToggleCardVisibility.gd | 24 +----- .../game/memory_game/scenes/MemoryGame.tscn | 79 +++++++++++-------- .../scripts/CardInteractionField.gd | 73 +++++++++++++++++ .../scripts/CardInteractionField.gd.uid | 1 + .../game/memory_game/scripts/CardSpawner.gd | 22 +++--- .../game/memory_game/scripts/GameCardGrid.gd | 5 +- .../game/memory_game/scripts/MemoryGame.gd | 21 ++--- .../scripts/systems/PlayerInputSystem.gd | 6 +- .../game_manager/scripts/GameManager.gd | 4 +- 16 files changed, 223 insertions(+), 101 deletions(-) create mode 100644 entities/game/card_collider/scene/CardCollider.tscn create mode 100644 entities/game/card_collider/scripts/CardCollider.gd create mode 100644 entities/game/card_collider/scripts/CardCollider.gd.uid create mode 100644 entities/game/card_collider/scripts/CollisionShapeGenerator.gd create mode 100644 entities/game/card_collider/scripts/CollisionShapeGenerator.gd.uid create mode 100644 entities/game/memory_game/scripts/CardInteractionField.gd create mode 100644 entities/game/memory_game/scripts/CardInteractionField.gd.uid diff --git a/entities/game/card_collider/scene/CardCollider.tscn b/entities/game/card_collider/scene/CardCollider.tscn new file mode 100644 index 0000000..4878b34 --- /dev/null +++ b/entities/game/card_collider/scene/CardCollider.tscn @@ -0,0 +1,17 @@ +[gd_scene format=3 uid="uid://0m4c62oqj4ih"] + +[ext_resource type="Script" uid="uid://bdy6xfwtsa3ff" path="res://entities/game/card_collider/scripts/CardCollider.gd" id="1_rityh"] + +[node name="CardCollider" type="Node2D" unique_id=620304416] +script = ExtResource("1_rityh") + +[node name="StaticBody2D" type="StaticBody2D" parent="." unique_id=214623478] +input_pickable = true + +[node name="CollisionShape" type="CollisionShape2D" parent="StaticBody2D" unique_id=721046375] +unique_name_in_owner = true + +[connection signal="set_shape" from="." to="StaticBody2D/CollisionShape" method="set_shape"] +[connection signal="input_event" from="StaticBody2D" to="." method="input_event"] +[connection signal="mouse_entered" from="StaticBody2D" to="." method="mouse_entered"] +[connection signal="mouse_exited" from="StaticBody2D" to="." method="mouse_has_left"] diff --git a/entities/game/card_collider/scripts/CardCollider.gd b/entities/game/card_collider/scripts/CardCollider.gd new file mode 100644 index 0000000..e180506 --- /dev/null +++ b/entities/game/card_collider/scripts/CardCollider.gd @@ -0,0 +1,48 @@ +class_name CardCollider extends Node2D + +signal set_shape(shape: RectangleShape2D) +signal mouse_enter(grid: Vector2i) +signal mouse_left(grid: Vector2i) +signal clicked(grid: Vector2i) + +var _grid_coordinate: Vector2i = Vector2i.ZERO +var _shape: CollisionShape2D = null + +var _mouse_inside: bool = false + +func _ready() -> void: + _shape = get_node("%CollisionShape") + +func set_size(size: Vector2) -> void: + var shape: RectangleShape2D = RectangleShape2D.new() + shape.size = size + + set_shape.emit(shape) + +func set_grid_coordinate(grid_data: Vector2i) -> void: + _grid_coordinate = grid_data + +func get_grid_coordinate() -> Vector2i: + return _grid_coordinate + +func enable_collider() -> void: + _shape.disabled = false + +func disable_collider() -> void: + _shape.disabled = true + +func mouse_entered() -> void: + mouse_enter.emit(_grid_coordinate) + _mouse_inside = true + +func mouse_has_left() -> void: + mouse_left.emit(_grid_coordinate) + _mouse_inside = false + +func input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: + if not _mouse_inside: + return + if event is InputEventMouseButton: + if event.pressed and event.button_index == MouseButton.MOUSE_BUTTON_LEFT: + clicked.emit(_grid_coordinate) + disable_collider() diff --git a/entities/game/card_collider/scripts/CardCollider.gd.uid b/entities/game/card_collider/scripts/CardCollider.gd.uid new file mode 100644 index 0000000..951233e --- /dev/null +++ b/entities/game/card_collider/scripts/CardCollider.gd.uid @@ -0,0 +1 @@ +uid://bdy6xfwtsa3ff diff --git a/entities/game/card_collider/scripts/CollisionShapeGenerator.gd b/entities/game/card_collider/scripts/CollisionShapeGenerator.gd new file mode 100644 index 0000000..61510e1 --- /dev/null +++ b/entities/game/card_collider/scripts/CollisionShapeGenerator.gd @@ -0,0 +1 @@ +extends Node diff --git a/entities/game/card_collider/scripts/CollisionShapeGenerator.gd.uid b/entities/game/card_collider/scripts/CollisionShapeGenerator.gd.uid new file mode 100644 index 0000000..53cd9ba --- /dev/null +++ b/entities/game/card_collider/scripts/CollisionShapeGenerator.gd.uid @@ -0,0 +1 @@ +uid://3sou5fpl2h3r diff --git a/entities/game/card_template/scenes/CardTemplate.tscn b/entities/game/card_template/scenes/CardTemplate.tscn index 7303eb8..8a4afad 100644 --- a/entities/game/card_template/scenes/CardTemplate.tscn +++ b/entities/game/card_template/scenes/CardTemplate.tscn @@ -14,7 +14,6 @@ [ext_resource type="Resource" uid="uid://0hefyj7q57o6" path="res://entities/game/card_template/assets/dissolve_effects/dissolve.tres" id="8_nugiu"] [ext_resource type="Script" uid="uid://cdvlsp04l5fhr" path="res://entities/game/card_template/scripts/ToggleCardVisibility.gd" id="8_pw264"] [ext_resource type="Script" uid="uid://b5mhdwdn1h8fo" path="res://entities/game/card_template/scripts/CardDropShadow.gd" id="9_ja01p"] -[ext_resource type="Script" uid="uid://dni6lxtacurf1" path="res://entities/game/card_template/scripts/CardHandler.gd" id="9_mu0q4"] [ext_resource type="Shader" uid="uid://djs1o5pxaguit" path="res://assets/shaders/SingleColorShader.gdshader" id="9_vcvmk"] [ext_resource type="Texture2D" uid="uid://bmxqeqo65xwt" path="res://assets/sprites/spritesheet-default.png" id="12_h72da"] [ext_resource type="Texture2D" uid="uid://b0lfebra6adhv" path="res://assets/sprites/Axuree/back_card_1.png" id="14_bmj37"] @@ -52,9 +51,6 @@ region = Rect2(384, 256, 64, 64) shader = ExtResource("14_l7f2y") shader_parameter/edge_fade_width = 0.05 -[sub_resource type="RectangleShape2D" id="RectangleShape2D_phkhd"] -size = Vector2(500, 550) - [sub_resource type="Curve" id="Curve_vcvmk"] _data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.113014, 1), 0.0, 0.0, 0, 0, Vector2(0.75, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] point_count = 4 @@ -165,13 +161,6 @@ toggle_material = ExtResource("5_b0osi") focus_material = ExtResource("16_ja01p") enforced_back_color = Color(1, 0.8745098, 0.7372549, 1) -[node name="Collider" type="Area2D" parent="CardBack" unique_id=1050148911] -unique_name_in_owner = true -script = ExtResource("9_mu0q4") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="CardBack/Collider" unique_id=876216407] -shape = SubResource("RectangleShape2D_phkhd") - [node name="DebugInformation" type="Node2D" parent="." unique_id=1036970705 node_paths=PackedStringArray("card_id_label", "card_position_label")] position = Vector2(-250, -250) script = ExtResource("18_tqsbp") @@ -220,8 +209,10 @@ volume = -15.0 [connection signal="about_to_get_delete" from="." to="CardContentGroup" method="animate_destruction"] [connection signal="about_to_get_delete" from="." to="CardBack" method="remove_from_board"] [connection signal="about_to_get_delete" from="." to="MatchingFoundEffect" method="trigger"] +[connection signal="card_in_focus" from="." to="CardContentGroup/DropShadow" method="got_focus"] [connection signal="card_in_focus" from="." to="CardBack" method="is_focused"] [connection signal="card_in_focus" from="." to="FocusEffect" method="trigger_random_effect"] +[connection signal="card_lost_focus" from="." to="CardContentGroup/DropShadow" method="lost_focus"] [connection signal="card_lost_focus" from="." to="CardBack" method="lost_focus"] [connection signal="card_text_changed" from="." to="CardContentGroup/CardNameBackground/CardName" method="set_card_text"] [connection signal="card_tooltip_changed" from="." to="CardContentGroup/CardNameBackground/CardName" method="set_tooltip"] @@ -235,13 +226,7 @@ volume = -15.0 [connection signal="show_card" from="." to="CardContentGroup" method="show_card_content"] [connection signal="show_card" from="." to="CardBack" method="toggle_off"] [connection signal="ready_for_destruction" from="CardContentGroup" to="." method="destory_now"] -[connection signal="focus_lost" from="CardBack" to="CardContentGroup/DropShadow" method="lost_focus"] [connection signal="fully_hidden" from="CardBack" to="." method="signal_repeater_fully_hidden"] [connection signal="fully_hidden" from="CardBack" to="CardContentGroup" method="hide_card_content"] [connection signal="fully_shown" from="CardBack" to="." method="signal_repeater_fully_shown"] [connection signal="hide_started" from="CardBack" to="CardContentGroup/DropShadow" method="lost_focus"] -[connection signal="in_focus" from="CardBack" to="CardContentGroup/DropShadow" method="got_focus"] -[connection signal="in_focus" from="CardBack" to="FocusEffect" method="trigger_random_effect"] -[connection signal="clicked" from="CardBack/Collider" to="." method="card_was_clicked"] -[connection signal="mouse_entered" from="CardBack/Collider" to="." method="selected_by_mouse"] -[connection signal="mouse_entered" from="CardBack/Collider" to="CardBack" method="is_focused"] diff --git a/entities/game/card_template/scripts/CardTemplate.gd b/entities/game/card_template/scripts/CardTemplate.gd index 0a8bfd8..7f63265 100644 --- a/entities/game/card_template/scripts/CardTemplate.gd +++ b/entities/game/card_template/scripts/CardTemplate.gd @@ -130,7 +130,6 @@ func get_height() -> float: func freeze_card() -> void: if back_side == null: return - back_side.freeze_card() _card_frozen = true lost_focus() @@ -139,7 +138,6 @@ func unfreeze_card() -> void: return _was_clicked = false _card_frozen = false - back_side.unfreeze_card() func get_width() -> float: return back_side.get_rect().size.x diff --git a/entities/game/card_template/scripts/ToggleCardVisibility.gd b/entities/game/card_template/scripts/ToggleCardVisibility.gd index 56500c2..48f2d3d 100644 --- a/entities/game/card_template/scripts/ToggleCardVisibility.gd +++ b/entities/game/card_template/scripts/ToggleCardVisibility.gd @@ -6,8 +6,6 @@ signal ready_for_removal() signal fully_hidden() signal fully_shown() signal hide_started() -signal in_focus() -signal focus_lost() enum VisibilityEnum { @@ -28,11 +26,10 @@ var _internal_focus_material: ShaderMaterial var currently_in_focus: bool = false -var collider: Area2D var removal_requested: bool = false var can_remove: bool = false var removal_planned: bool = false -var currently_ai: bool = false +#var currently_ai: bool = false var animation_tween: Tween = null var _focus_tween: Tween = null @@ -42,7 +39,6 @@ var fix_image_thread: Thread var visibility: VisibilityEnum = VisibilityEnum.HIDDEN func _ready() -> void: - collider = %Collider visible = true _internal_focus_material = focus_material.duplicate_deep() _internal_toggle_material = toggle_material.duplicate_deep() @@ -88,14 +84,6 @@ func _animation_finished(should_hide: bool) -> void: can_remove = true print("shown") -func freeze_card() -> void: - collider.visible = false - -func unfreeze_card() -> void: - if currently_ai: - return - collider.visible = true - # This method will show a fully hidden card func toggle_off() -> void: print("toggle off") @@ -125,14 +113,11 @@ func is_focused() -> void: currently_in_focus = true set_shader_material(_internal_focus_material) - in_focus.emit() _animate_focus(focus_scale) func lost_focus() -> void: currently_in_focus = false set_shader_material(_internal_toggle_material) - if collider.visible: - focus_lost.emit() _animate_focus(1.0) @@ -162,10 +147,3 @@ func _process(_delta: float) -> void: if removal_planned && can_remove: ready_for_removal.emit() queue_free() - -func input_active(is_active: bool) -> void: - currently_ai = !is_active - if is_active: - unfreeze_card() - return - freeze_card() diff --git a/entities/game/memory_game/scenes/MemoryGame.tscn b/entities/game/memory_game/scenes/MemoryGame.tscn index cacbf55..11e0ec3 100644 --- a/entities/game/memory_game/scenes/MemoryGame.tscn +++ b/entities/game/memory_game/scenes/MemoryGame.tscn @@ -31,6 +31,8 @@ [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"] [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"] @@ -69,15 +71,11 @@ metadata/_custom_type_script = "uid://cgdnmg4wop2a6" 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")] +[node name="MemoryGame" type="Node2D" unique_id=648295195] process_mode = 1 script = ExtResource("1_13jq5") -round_end_message = ExtResource("2_fspeh") -round_end_message_no_auto_complete = ExtResource("3_a3528") finished_game_template = ExtResource("4_6f670") game_menu_template = ExtResource("12_dfx06") -game_nodes_to_show = [NodePath("UI"), NodePath("World/Background")] -card_target_node = NodePath("World/Cards") [node name="Systems" type="Node" parent="." unique_id=1325794078] unique_name_in_owner = true @@ -103,7 +101,7 @@ metadata/_custom_type_script = "uid://bxjrl2ikqn4tk" [node name="AiAgentSystem" type="Node" parent="Systems" unique_id=1896166842 node_paths=PackedStringArray("cards_node", "players")] script = ExtResource("15_u3ner") -cards_node = NodePath("../../World/Cards") +cards_node = NodePath("../../World/CardBoard") players = NodePath("../PlayerSystem") min_wait_seconds = 0.75 metadata/_custom_type_script = "uid://c3hyh8ifpeuxg" @@ -125,7 +123,6 @@ 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") -place_offset = Vector2(250, 250) metadata/_custom_type_script = "uid://btm576yjkyt4j" [node name="UiInformationSystem" type="Node" parent="Systems" unique_id=1812178848] @@ -143,11 +140,21 @@ script = ExtResource("7_kxmqb") background_texture = ExtResource("23_a3528") camera_node = NodePath("../Camera2D") -[node name="Cards" type="Node2D" parent="World" unique_id=2054375941 node_paths=PackedStringArray("state_machine")] +[node name="CardBoard" type="Node2D" parent="World" unique_id=2054375941 node_paths=PackedStringArray("state_machine", "visual_card_node")] unique_name_in_owner = true script = ExtResource("19_ploi3") state_machine = NodePath("../../Systems/GameStateSystem") matching_card_sound_effect = ExtResource("6_a3528") +visual_card_node = NodePath("CardVisuals") + +[node name="CardInteractionField" type="Node2D" parent="World/CardBoard" unique_id=1435215390] +z_index = 10 +script = ExtResource("27_7lv0s") +collider_template = ExtResource("28_7ou1n") +metadata/_custom_type_script = "uid://cf8loyigibdp6" + +[node name="CardVisuals" type="Node2D" parent="World/CardBoard" unique_id=1427743299] +unique_name_in_owner = true [node name="CardTemplateGhost" parent="World" unique_id=155356654 groups=["game_initialize_scene"] instance=ExtResource("3_ihyl6")] position = Vector2(-11367, -8587) @@ -235,6 +242,7 @@ 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="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"] [connection signal="request_popup" from="Systems/GameStateSystem" to="Systems/PopupSystem" method="add_and_show_popup"] @@ -245,7 +253,8 @@ debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")] [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/CardBoard" method="game_state_changed"] +[connection signal="state_changed" from="Systems/GameStateSystem" to="World/CardBoard/CardInteractionField" 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="tutorial_requested" from="Systems/TutorialStateSystem" to="Systems/PopupSystem" method="add_and_show_popup"] @@ -255,45 +264,53 @@ debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")] [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/CardBoard" method="player_changed"] +[connection signal="player_resource_changed" from="Systems/PlayerSystem" to="World/CardBoard/CardInteractionField" method="player_changed"] [connection signal="player_resource_changed" from="Systems/PlayerSystem" to="World/Camera2D" 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"] +[connection signal="card_movement" from="Systems/PlayerInputSystem" to="World/CardBoard" method="parse_movement"] +[connection signal="confirm_current_card" from="Systems/PlayerInputSystem" to="World/CardBoard" method="confirm_current_card"] [connection signal="end_current_round" from="Systems/PlayerInputSystem" to="." method="end_round_now"] [connection signal="end_current_round" from="Systems/PlayerInputSystem" to="Systems/GameStateSystem" method="force_end_round"] [connection signal="game_menu_requested" from="Systems/PlayerInputSystem" to="." method="show_game_menu"] [connection signal="continue_game" from="Systems/PopupSystem" to="." method="unpause_game"] [connection signal="pause_game" from="Systems/PopupSystem" to="." method="pause_game"] -[connection signal="card_was_clicked" from="Systems/NetworkHandlerSystem" to="World/Cards" method="trigger_card_at_position"] +[connection signal="card_was_clicked" from="Systems/NetworkHandlerSystem" to="World/CardBoard" method="trigger_card_at_position"] [connection signal="game_has_been_finished" from="Systems/NetworkHandlerSystem" to="UI/PlayersOverlay" method="game_ended"] [connection signal="game_state_has_changed" from="Systems/NetworkHandlerSystem" to="Systems/PlayerInputSystem" method="game_state_changed"] -[connection signal="game_state_has_changed" from="Systems/NetworkHandlerSystem" to="World/Cards" method="game_state_changed"] +[connection signal="game_state_has_changed" from="Systems/NetworkHandlerSystem" to="World/CardBoard" method="game_state_changed"] [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/Cards" method="remove_card_from_board"] +[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/Cards" 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/Cards" method="card_loading_done"] +[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/Cards" method="receive_field_size"] -[connection signal="all_matching_cards_removed" from="World/Cards" to="." method="all_cards_removed"] -[connection signal="all_matching_cards_removed" from="World/Cards" to="Systems/GameStateSystem" method="matches_found"] -[connection signal="all_matching_cards_removed" from="World/Cards" to="Systems/TutorialStateSystem" method="matching_card_found"] -[connection signal="all_matching_cards_removed" from="World/Cards" to="Systems/PlayerSystem" method="player_scored"] -[connection signal="board_empty" from="World/Cards" to="." method="show_game_end_screen"] -[connection signal="board_empty" from="World/Cards" to="Systems/GameStateSystem" method="board_empty"] -[connection signal="board_ready" from="World/Cards" to="Systems/GameStateSystem" method="board_ready"] -[connection signal="card_activated" from="World/Cards" to="Systems/GameStateSystem" method="card_was_clicked"] -[connection signal="card_activated" from="World/Cards" to="Systems/TutorialStateSystem" method="card_triggered"] -[connection signal="card_triggered" from="World/Cards" to="Systems/AiAgentSystem" method="card_was_triggered"] -[connection signal="identical_cards" from="World/Cards" to="Systems/AiAgentSystem" method="card_was_identically"] -[connection signal="no_matches_found" from="World/Cards" to="Systems/GameStateSystem" method="no_matches"] -[connection signal="touch_used" from="World/Camera2D" to="World/Cards" method="disable_card_effects"] +[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"] +[connection signal="all_matching_cards_removed" from="World/CardBoard" to="Systems/PlayerSystem" method="player_scored"] +[connection signal="board_empty" from="World/CardBoard" to="." method="show_game_end_screen"] +[connection signal="board_empty" from="World/CardBoard" to="Systems/GameStateSystem" method="board_empty"] +[connection signal="board_ready" from="World/CardBoard" to="Systems/GameStateSystem" method="board_ready"] +[connection signal="card_activated" from="World/CardBoard" to="Systems/GameStateSystem" method="card_was_clicked"] +[connection signal="card_activated" from="World/CardBoard" to="Systems/TutorialStateSystem" method="card_triggered"] +[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="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="deck_changed" from="World/CardTemplateGhost" to="World/CardTemplateGhost/CardContentGroup/DropShadow" method="deck_changed"] +[connection signal="deck_changed" from="World/CardTemplateGhost" to="World/CardTemplateGhost/CardBack" method="deck_changed"] +[connection signal="input_active" from="World/CardTemplateGhost" to="World/CardTemplateGhost/CardBack" method="input_active"] +[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 new file mode 100644 index 0000000..3251905 --- /dev/null +++ b/entities/game/memory_game/scripts/CardInteractionField.gd @@ -0,0 +1,73 @@ +class_name CardInteractionField extends Node2D + +signal mouse_enter(grid: Point) +signal mouse_left(grid: Point) +signal clicked(grid: Point) + +@export var default_texture_size: Vector2 = Vector2(499, 550) +@export var collider_template: PackedScene = null +@export var additional_offset: Vector2i = Vector2i(0, 25) + +var _separation: int = 0 +var _offset: Vector2i = Vector2i.ZERO +var _card_size: Vector2 + +var _is_ai_player: bool = false + +func set_board_information(deck_to_use: MemoryDeckResource, card_separation: int, field_offset: Vector2i) -> void: + var back_image: Texture2D = deck_to_use.get_back_image() + _card_size = default_texture_size + if back_image != null: + _card_size = deck_to_use.get_back_image().get_size() + _separation = card_separation + _offset = field_offset + +func build_field(cards_on_x: int, cards_on_y: int) -> void: + for x: int in cards_on_x: + for y: int in cards_on_y: + var x_addition: int = _separation * x + x_addition += int(_card_size.x) * x + var y_addition: int = _separation * y + y_addition += int(_card_size.y) * y + var template: CardCollider = collider_template.instantiate() + template.set_size(_card_size) + template.position = _offset + additional_offset + Vector2i(x_addition, y_addition) + template.set_grid_coordinate(Vector2i(x, y)) + _connect_card_interaction(template) + + add_child(template) + template.disable_collider() + +func card_was_added(card: CardTemplate) -> void: + card.remove_requested.connect(remove_card.bind(card.grid_position)) + +func remove_card(grid_position: Point) -> void: + for child: CardCollider in get_children(): + var coordinates: Point = Point.new(child.get_grid_coordinate().x, child.get_grid_coordinate().y) + if coordinates.is_identical(grid_position): + child.queue_free() + +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: + _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(): + if new_state: + child.enable_collider() + else: + child.disable_collider() + +func _connect_card_interaction(collider: CardCollider) -> void: + collider.mouse_enter.connect(func(data: Vector2i) -> void: mouse_enter.emit(Point.new(data.x, data.y))) + collider.mouse_left.connect(func(data: Vector2i) -> void: mouse_left.emit(Point.new(data.x, data.y))) + collider.clicked.connect(func(data: Vector2i) -> void: clicked.emit(Point.new(data.x, data.y))) diff --git a/entities/game/memory_game/scripts/CardInteractionField.gd.uid b/entities/game/memory_game/scripts/CardInteractionField.gd.uid new file mode 100644 index 0000000..e6540c8 --- /dev/null +++ b/entities/game/memory_game/scripts/CardInteractionField.gd.uid @@ -0,0 +1 @@ +uid://cf8loyigibdp6 diff --git a/entities/game/memory_game/scripts/CardSpawner.gd b/entities/game/memory_game/scripts/CardSpawner.gd index 79c88d3..ab2dfe8 100644 --- a/entities/game/memory_game/scripts/CardSpawner.gd +++ b/entities/game/memory_game/scripts/CardSpawner.gd @@ -1,6 +1,5 @@ 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) @@ -8,11 +7,11 @@ signal card_placed(card: CardTemplate) signal card_placing_done() @export var card_template: PackedScene -@export var separation: int = 25 +#@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("%Cards") +#@export var place_offset: Vector2 = Vector2.ZERO +@onready var _card_target_node: Node2D = get_node("%CardBoard/CardVisuals") var _load_thread: Thread = null var _place_thread: Thread = null @@ -24,14 +23,14 @@ func _ready() -> void: push_error("Missing \"Cards\" node") queue_free() -func place_cards_from_deck(deck_to_use: MemoryDeckResource) -> void: +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) _load_thread = Thread.new() - _load_thread.start(build_card_layout.bind(deck_to_use, card_template, separation)) + _load_thread.start(build_card_layout.bind(deck_to_use, card_template, card_separation, field_offset)) await field_constructed process_mode = PROCESS_MODE_INHERIT @@ -60,7 +59,7 @@ func _add_cards_to_field_async(cards: Array[CardTemplate], target: Node2D) -> vo await get_tree().physics_frame call_deferred("emit_signal","card_placing_done") -func _calculate_field_size(cards_on_x: int, cards_on_y: int) -> void: +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 @@ -85,7 +84,8 @@ func _calculate_field_size(cards_on_x: int, cards_on_y: int) -> void: func build_card_layout(deck_of_cards: MemoryDeckResource, template: PackedScene, - card_separation: int + card_separation: int, + offset: Vector2i ) -> Array[CardTemplate]: var return_cards: Array[CardTemplate] = [] var card_pool: Array[MemoryCardResource] = deck_of_cards.cards @@ -103,7 +103,7 @@ func build_card_layout(deck_of_cards: MemoryDeckResource, while row_count * column_count < card_pool.size(): column_count = column_count + 1 - call_deferred("_calculate_field_size", column_count, row_count) + call_deferred("_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 @@ -116,8 +116,8 @@ func build_card_layout(deck_of_cards: MemoryDeckResource, 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 += place_offset.y - width_to_set += place_offset.x + 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 = Point.new(x, y) diff --git a/entities/game/memory_game/scripts/GameCardGrid.gd b/entities/game/memory_game/scripts/GameCardGrid.gd index fbc67b6..010e608 100644 --- a/entities/game/memory_game/scripts/GameCardGrid.gd +++ b/entities/game/memory_game/scripts/GameCardGrid.gd @@ -11,6 +11,7 @@ signal card_activated() @export var state_machine: GameStateSystem @export var matching_card_sound_effect: AudioStream +@export var visual_card_node: Node2D var current_card: CardTemplate @@ -50,7 +51,7 @@ func _move_axis(direction: int, axis: Axis) -> void: func get_card_grid(current_pos: Point) -> Array[Point]: var all_cards: Array[Point] = [] - for card: Node2D in get_children(): + for card: Node2D in visual_card_node.get_children(): if card is CardTemplate and !card.grid_position.is_identical(current_pos) and not card.is_getting_removed(): all_cards.append(card.grid_position) @@ -317,7 +318,7 @@ func disable_card_effects() -> void: func _get_game_card_templates_children() -> Array[CardTemplate]: var return_data: Array[CardTemplate] - for card_template: CardTemplate in get_children().filter(func(data: Node) -> bool: return data is 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) return return_data diff --git a/entities/game/memory_game/scripts/MemoryGame.gd b/entities/game/memory_game/scripts/MemoryGame.gd index 78d2859..f55c074 100644 --- a/entities/game/memory_game/scripts/MemoryGame.gd +++ b/entities/game/memory_game/scripts/MemoryGame.gd @@ -1,6 +1,6 @@ class_name MemoryGame extends Node2D -signal load_game(card_deck: MemoryDeckResource) +signal load_game(card_deck: MemoryDeckResource, separation: int, field_offset: Vector2i) signal game_paused(is_paused: bool) @@ -8,16 +8,14 @@ signal request_popup(window: PopupWindow) const CARDS_PER_PLAYER: int = 2 -@export_group("Translations") -@export var round_end_message: TextTranslation -@export var round_end_message_no_auto_complete: TextTranslation - @export_group("Game Setup") -@export var card_deck: Resource +@export var card_separation: int = 25 +@export var field_offset: Vector2i = Vector2i(250, 250) @export var finished_game_template: PackedScene @export var game_menu_template: PackedScene -@export var game_nodes_to_show: Array[Node] -@export var card_target_node: Node2D + + +var _card_deck: Resource #var current_game_state: int var player_node: PlayerSystem @@ -45,8 +43,11 @@ func _ready() -> void: process_mode = PROCESS_MODE_DISABLED player_node = get_node("%PlayerSystem") +func set_card_deck(deck: MemoryDeckResource) -> void: + _card_deck = deck + func start_loading_data() -> void: - load_game.emit(card_deck) + load_game.emit(_card_deck, card_separation, field_offset) func _process(_delta: float) -> void: if !execute_logic(): @@ -68,7 +69,7 @@ func show_game_end_screen() -> void: var finish_node: GameFinished = finished_game_template.instantiate() as GameFinished finish_node.high_priority = true finish_node.set_player_manager(player_node) - finish_node.set_played_deck(card_deck) + finish_node.set_played_deck(_card_deck) request_popup.emit(finish_node) func set_players(players_of_game: Array[PlayerResource]) -> void: diff --git a/entities/game/memory_game/scripts/systems/PlayerInputSystem.gd b/entities/game/memory_game/scripts/systems/PlayerInputSystem.gd index 0250dea..fd74515 100644 --- a/entities/game/memory_game/scripts/systems/PlayerInputSystem.gd +++ b/entities/game/memory_game/scripts/systems/PlayerInputSystem.gd @@ -4,7 +4,7 @@ signal game_menu_requested() signal end_current_round() signal confirm_current_card() signal card_movement(information: Vector2) -signal disable_input() +#signal disable_input() @export var frames_to_skip_after_pause: int = 2 @@ -42,8 +42,8 @@ func player_changed(current_player:PlayerResource) -> void: current_ai_player = current_player.is_ai() if multiplayer.get_peers().size() > 0 and current_player.id != multiplayer.get_unique_id(): current_ai_player = true - if current_ai_player: - disable_input.emit() + #if current_ai_player: + #disable_input.emit() func prevent_input(prevent: bool) -> void: _prevent_input = prevent diff --git a/shared/global_entities/game_manager/scripts/GameManager.gd b/shared/global_entities/game_manager/scripts/GameManager.gd index ef9fcc6..9987ead 100644 --- a/shared/global_entities/game_manager/scripts/GameManager.gd +++ b/shared/global_entities/game_manager/scripts/GameManager.gd @@ -238,14 +238,14 @@ func _rpc_load_game(game_data: Dictionary) -> void: await ScreenTransitionManager.transit_screen_by_node_with_position(loading_screen, click_position, false) get_tree().root.add_child(game_scene_node) -func load_game(card_deck: Resource, players: Array[PlayerResource], click_position: Vector2) -> void: +func load_game(card_deck: MemoryDeckResource, 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 var game_scene_node: MemoryGame = game_scene.instantiate() as MemoryGame - game_scene_node.card_deck = card_deck + game_scene_node.set_card_deck(card_deck) game_scene_node.ready.connect(func() -> void: