diff --git a/entities/game/card_template/scripts/CardTemplate.gd b/entities/game/card_template/scripts/CardTemplate.gd index 7f63265..408f088 100644 --- a/entities/game/card_template/scripts/CardTemplate.gd +++ b/entities/game/card_template/scripts/CardTemplate.gd @@ -45,7 +45,7 @@ signal remove_requested() var card_deck: MemoryDeckResource var memory_card: MemoryCardResource -var grid_position: Point +var grid_position: Vector2i var _timer_for_hide_delay: Timer var _was_clicked: bool diff --git a/entities/game/card_template/scripts/CardTemplateDebug.gd b/entities/game/card_template/scripts/CardTemplateDebug.gd index 452018a..0f1ad06 100644 --- a/entities/game/card_template/scripts/CardTemplateDebug.gd +++ b/entities/game/card_template/scripts/CardTemplateDebug.gd @@ -17,7 +17,7 @@ func _ready() -> void: if card == null: queue_free() return - var card_position: Point = card_information.grid_position + var card_position: Vector2i = card_information.grid_position card_id_label.text = str(card.get_id()) - card_position_label.text = "[" + str(card_position.get_x_pos()) + "," + str(card_position.get_y_pos()) + "]" + card_position_label.text = "[" + str(card_position.x) + "," + str(card_position.y) + "]" diff --git a/entities/game/memory_game/scenes/MemoryGame.tscn b/entities/game/memory_game/scenes/MemoryGame.tscn index 11e0ec3..68e1063 100644 --- a/entities/game/memory_game/scenes/MemoryGame.tscn +++ b/entities/game/memory_game/scenes/MemoryGame.tscn @@ -309,8 +309,5 @@ debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")] [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 index 3251905..4d6daf6 100644 --- a/entities/game/memory_game/scripts/CardInteractionField.gd +++ b/entities/game/memory_game/scripts/CardInteractionField.gd @@ -1,8 +1,8 @@ class_name CardInteractionField extends Node2D -signal mouse_enter(grid: Point) -signal mouse_left(grid: Point) -signal clicked(grid: Point) +signal mouse_enter(grid: Vector2i) +signal mouse_left(grid: Vector2i) +signal clicked(grid: Vector2i) @export var default_texture_size: Vector2 = Vector2(499, 550) @export var collider_template: PackedScene = null @@ -41,10 +41,9 @@ func build_field(cards_on_x: int, cards_on_y: int) -> void: func card_was_added(card: CardTemplate) -> void: card.remove_requested.connect(remove_card.bind(card.grid_position)) -func remove_card(grid_position: Point) -> void: +func remove_card(grid_position: Vector2i) -> 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): + if child.get_grid_coordinate() == grid_position: child.queue_free() func player_changed(current_player: PlayerResource) -> void: @@ -68,6 +67,6 @@ func _change_interaction_state(new_state: bool) -> void: 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))) + collider.mouse_enter.connect(func(data: Vector2i) -> void: mouse_enter.emit(data)) + collider.mouse_left.connect(func(data: Vector2i) -> void: mouse_left.emit(data)) + collider.clicked.connect(func(data: Vector2i) -> void: clicked.emit(data)) diff --git a/entities/game/memory_game/scripts/CardSpawner.gd b/entities/game/memory_game/scripts/CardSpawner.gd index ab2dfe8..12b61e4 100644 --- a/entities/game/memory_game/scripts/CardSpawner.gd +++ b/entities/game/memory_game/scripts/CardSpawner.gd @@ -119,7 +119,7 @@ func build_card_layout(deck_of_cards: MemoryDeckResource, 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) + card_template_node.grid_position = Vector2i(x, y) return_cards.append(card_template_node) current_card = current_card + 1 @@ -146,7 +146,10 @@ func announce_card_field() -> void: var real_card: MemoryCardResource = card.memory_card network_cards.append({ "id": real_card.get_id(), - "grid-position": card.grid_position.get_network_data(), + "grid-position": { + "x": card.grid_position.x, + "y": card.grid_position.y, + }, "world-position": { "x": card.global_position.x, "y": card.global_position.y, @@ -165,7 +168,7 @@ func _rpc_rebuild_field(field: Dictionary) -> void: 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 = Point.new(grid_pos["x"], grid_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 diff --git a/entities/game/memory_game/scripts/GameCardGrid.gd b/entities/game/memory_game/scripts/GameCardGrid.gd index 010e608..fec2f41 100644 --- a/entities/game/memory_game/scripts/GameCardGrid.gd +++ b/entities/game/memory_game/scripts/GameCardGrid.gd @@ -3,7 +3,7 @@ class_name GameCardGrid extends Node2D signal card_removed() signal all_matching_cards_removed() signal card_triggered(CardTemplate: CardTemplate) -signal identical_cards(first_card_point: Point, set_icon_modulated_card_point: Point) +signal identical_cards(first_card_Vector2i: Vector2i, set_icon_modulated_card_Vector2i: Vector2i) signal no_matches_found() signal board_ready() signal board_empty() @@ -25,10 +25,10 @@ var _game_completed: bool = false enum Axis {X, Y} -func get_current_grid_position() -> Point: +func get_current_grid_position() -> Vector2i: if current_card == null: - return Point.new(0,0) - return Point.new(current_card.grid_position.get_x_pos(), current_card.grid_position.get_y_pos()) + 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 @@ -36,61 +36,19 @@ func receive_field_size(x: int, y: int) -> void: func get_field_size() -> Vector2i: return _field_size -func _move_axis(direction: int, axis: Axis) -> void: - var clamped_direction: int = clampi(direction, -1, 1) - if clamped_direction == 0: - return - - var grid_position: Point = get_current_grid_position() - var is_negative_direction: bool = clamped_direction < 0 - - var next_position: Point = _get_next_card_position(grid_position, is_negative_direction, axis) - - if next_position == null or !select_card_at_position(next_position): - current_card = null - -func get_card_grid(current_pos: Point) -> Array[Point]: - var all_cards: Array[Point] = [] - 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) - - return all_cards - -func get_closest_card_to_position(current_pos: Point, card_positions: Array[Point]) -> Point: - var return_point: Point = null - var distance: float = 10000 - - for current_position: Point in card_positions: - if current_position.get_distance(current_pos) < distance: - return_point = current_position - distance = current_position.get_distance(current_pos) - - return return_point - -func _get_next_card_position(current_pos: Point, go_negative: bool, axis: Axis) -> Point: - var all_card_positions: Array[Point] = _get_valid_card_positions(current_pos, go_negative, axis) - - var return_point: Point = _get_card_on_same_axis(current_pos, all_card_positions, axis) - - if return_point == null: - return_point = get_closest_card_to_position(current_pos, all_card_positions) - - return return_point - -func _get_valid_card_positions(current_pos: Point, go_negative: bool, axis: Axis) -> Array[Point]: - var all_card_positions: Array[Point] = get_card_grid(current_pos); - var valid_cards: Array[Point] = [] - for card_position: Point in all_card_positions: +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.get_x_pos() - current_position = current_pos.get_x_pos() + current_card_position = card_position.x + current_position = current_pos.x Axis.Y: - current_card_position = card_position.get_y_pos() - current_position = current_pos.get_y_pos() + current_card_position = card_position.y + current_position = current_pos.y if go_negative and current_card_position >= current_position: continue @@ -99,46 +57,22 @@ func _get_valid_card_positions(current_pos: Point, go_negative: bool, axis: Axis valid_cards.append(card_position) return valid_cards -func _get_card_on_same_axis(current_position: Point, valid_positions: Array[Point], axis: Axis) -> Point: - var return_point: Point = null; - for valid_position: Point in valid_positions: - var is_same_axis: bool = false - match axis: - Axis.X: - is_same_axis = current_position.get_x_pos() == valid_position.get_x_pos() - Axis.Y: - is_same_axis = current_position.get_y_pos() == valid_position.get_y_pos() - - if not is_same_axis: - continue - - if return_point == null: - return_point = valid_position - continue - - var current_distance: int = 0 - var return_point_distance: int = 0 - match axis: - Axis.X: - current_distance = absi(valid_position.get_x_pos() - current_position.get_x_pos()) - return_point_distance = absi(return_point.get_x_pos() - current_position.get_x_pos()) - Axis.Y: - current_distance = absi(valid_position.get_y_pos() - current_position.get_y_pos()) - return_point_distance = absi(return_point.get_y_pos() - current_position.get_y_pos()) - - if current_distance < return_point_distance: - return_point = current_position +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) - return return_point + return all_cards -func trigger_card_at_position(grid_position: Point) -> void: +func trigger_card_at_position(grid_position: Vector2i) -> void: if select_card_at_position(grid_position): if current_card == null: return current_card.force_reveal_card() -func remove_cards_from_board(grid_positions: Array[Point]) -> void: - for grid_position: Point in grid_positions: +func remove_cards_from_board(grid_positions: Array[Vector2i]) -> void: + for grid_position: Vector2i in grid_positions: remove_card_from_board(grid_position) for card: CardTemplate in _get_game_card_templates(): if card.is_playing_animation(): @@ -146,18 +80,18 @@ func remove_cards_from_board(grid_positions: Array[Point]) -> void: all_matching_cards_removed.emit() GlobalSoundManager.play_sound_effect(matching_card_sound_effect) -func remove_card_from_board(grid_position: Point) -> void: +func remove_card_from_board(grid_position: Vector2i) -> void: for child: CardTemplate in _get_game_card_templates_children(): - if child.grid_position.is_identical(grid_position): + if child.grid_position == grid_position: child.remove_from_board(currently_ai_player) child.about_to_get_delete.connect(func() -> void: card_removed.emit()) -func select_card_at_position(grid_position: Point) -> bool: +func select_card_at_position(grid_position: Vector2i) -> bool: var found_card: bool = false var initial_card: CardTemplate = current_card for card: CardTemplate in _get_game_card_templates_children(): card.lost_focus() - if grid_position.is_identical(card.grid_position): + if grid_position == card.grid_position: card.got_focus() current_card = card found_card = true @@ -171,21 +105,10 @@ func confirm_current_card() -> void: if current_card == null or get_tree().paused: return current_card.card_was_clicked() - -func select_closest_card(source_position: Point, include_source: bool) -> void: - if currently_ai_player: - return - var cards: Array[Point] = get_card_grid(source_position) - if include_source: - cards.append(source_position) - var return_position: Point = get_closest_card_to_position(source_position, cards) - if return_position != null: - select_card_at_position(return_position) - -func get_card_on_position(card_position: Point) -> MemoryCardResource: +func get_card_on_position(card_position: Vector2i) -> MemoryCardResource: for card: CardTemplate in _get_game_card_templates_children(): - if card_position.is_identical(card.grid_position): + if card_position == card.grid_position: return card.memory_card return null @@ -196,8 +119,52 @@ func parse_movement(information: Vector2) -> void: if information != Vector2.ZERO: Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) - _move_axis(sign(information.x), Axis.X) - _move_axis(sign(information.y), Axis.Y) + var card_position: Vector2i =_get_closest_card_position(information) + if card_position == -Vector2i.ONE or !select_card_at_position(card_position): + current_card = null + +func _get_closest_card_position(movement: Vector2) -> Vector2i: + var current_selected_card: Vector2i = get_current_grid_position() + var target_position: Vector2i = Vector2i(int(movement.x), int(movement.y)) + current_selected_card + if current_selected_card == -Vector2i.ONE: + current_selected_card = -Vector2i.ONE + target_position = Vector2i.ZERO + + target_position.x = clampi(target_position.x, 0, _field_size.x) + target_position.y = clampi(target_position.y, 0, _field_size.y) + + if current_selected_card == target_position: + return current_selected_card + + print(target_position) + + var axis: Axis = Axis.X + var is_negative: bool = false + var closest_distance: float = 100000.0 + var return_position: Vector2i = -Vector2i.ONE + + if movement.y != 0: + axis = Axis.Y + + if movement.y < -0.0001 or movement.x < -0.0001: + is_negative = true + for valid_position: Vector2i in _get_valid_card_positions(current_selected_card, is_negative, axis): + if valid_position == target_position: + return valid_position + var calculate_distance: Vector2i = valid_position + var weight: int = (_field_size.x + _field_size.y) * 2 + if axis == Axis.X: + if valid_position.x == target_position.x: + weight = 0 + else: + if valid_position.y == target_position.y: + weight = 0 + var current_distance: float = calculate_distance.distance_to(target_position) + weight + if current_distance < closest_distance: + closest_distance = current_distance + return_position = valid_position + + return return_position func round_frozen() -> void: current_card = null @@ -207,7 +174,7 @@ func round_unfrozen() -> void: controller_input_was_made = false return if controller_input_was_made: - select_closest_card(Point.new(0,0), true) + _get_closest_card_position(Vector2i(1,0)) controller_input_was_made = false func card_loading_done() -> void: @@ -248,7 +215,7 @@ func _validate_grid() -> void: print("Waiting") await card.fully_shown if _any_matching(): - var card_positions: Array[Point] = [] + var card_positions: Array[Vector2i] = [] for card: CardTemplate in _get_game_card_templates(): if card.is_turned(): card_positions.append(card.grid_position) @@ -291,8 +258,8 @@ func _any_matching() -> bool: return true return false -func get_all_card_positions(get_turned: bool = false) -> Array[Point]: - var return_data: Array[Point] = [] +func get_all_card_positions(get_turned: bool = false) -> Array[Vector2i]: + var return_data: Array[Vector2i] = [] for card: CardTemplate in _get_game_card_templates_children(): if card.is_getting_removed(): continue @@ -300,8 +267,8 @@ func get_all_card_positions(get_turned: bool = false) -> Array[Point]: return_data.append(card.grid_position) return return_data -func get_all_cards_currently_turned() -> Array[Point]: - var return_data: Array[Point] = [] +func get_all_cards_currently_turned() -> Array[Vector2i]: + var return_data: Array[Vector2i] = [] for card: CardTemplate in _get_game_card_templates_children(): if card.is_turned(): return_data.append(card.grid_position) @@ -341,4 +308,3 @@ func card_triggered_hook(card: CardTemplate) -> void: select_card_at_position(card.grid_position) card_triggered.emit(card) card_activated.emit() - diff --git a/entities/game/memory_game/scripts/ai/Blackboard.gd b/entities/game/memory_game/scripts/ai/Blackboard.gd index 019ffa1..86feba9 100644 --- a/entities/game/memory_game/scripts/ai/Blackboard.gd +++ b/entities/game/memory_game/scripts/ai/Blackboard.gd @@ -10,9 +10,9 @@ func _init(max_cards: int) -> void: unlimited_memory = max_cards_to_remember == -1 -func add_card(position: Point, card: MemoryCardResource) -> void: +func add_card(position: Vector2i, card: MemoryCardResource) -> void: var new_card: CardInformationResource = CardInformationResource.new(position, card) - if !cards.any(func(current_card: CardInformationResource) -> bool: return current_card.position.is_identical(position)): + if !cards.any(func(current_card: CardInformationResource) -> bool: return current_card.position == position): cards.append(new_card) latest_added_card = new_card ensure_memory_boundry() @@ -20,11 +20,11 @@ func add_card(position: Point, card: MemoryCardResource) -> void: move_card_to_top(position) -func move_card_to_top(card_position: Point) -> void: +func move_card_to_top(card_position: Vector2i) -> void: var index: int = -1 var running_index: int = 0 for current_card: CardInformationResource in cards: - if card_position.is_identical(current_card.position): + if card_position == current_card.position: index = running_index break running_index = running_index + 1 @@ -43,11 +43,11 @@ func ensure_memory_boundry() -> void: for i: int in cards_to_remove: cards.remove_at(0) -func remove_card(position: Point) -> void: +func remove_card(position: Vector2i) -> void: var index: int = 0 var match_found: bool = false for card: CardInformationResource in cards: - if card.position.is_identical(position): + if card.position == position: match_found = true break index = index + 1 @@ -71,7 +71,7 @@ func get_all_saved_cards() -> Array[CardInformationResource]: func get_last_saved_card() -> CardInformationResource: for current_card: CardInformationResource in cards: - if current_card.position.is_identical(latest_added_card.position): + if current_card.position == latest_added_card.position: return current_card return null diff --git a/entities/game/memory_game/scripts/systems/AiAgentSystem.gd b/entities/game/memory_game/scripts/systems/AiAgentSystem.gd index 809527d..b24d05e 100644 --- a/entities/game/memory_game/scripts/systems/AiAgentSystem.gd +++ b/entities/game/memory_game/scripts/systems/AiAgentSystem.gd @@ -22,7 +22,7 @@ var last_card: MemoryCardResource = null func card_was_triggered(card: CardTemplate) -> void: add_card_to_all_ais(card.grid_position, card.memory_card) -func card_was_identically(first_card_position: Point, second_card_position: Point) -> void: +func card_was_identically(first_card_position: Vector2i, second_card_position: Vector2i) -> void: remove_card_to_all_ais(first_card_position) remove_card_to_all_ais(second_card_position) @@ -37,7 +37,7 @@ func game_state_changed(game_state: GameEnum.State) -> void: timer.stop() return -func get_all_card_positions() -> Array[Point]: +func get_all_card_positions() -> Array[Vector2i]: return cards_node.get_all_card_positions() func player_changed(current_player:PlayerResource) -> void: @@ -78,8 +78,8 @@ func _call_action_on_all_ais(callback: Callable) -> void: continue callback.call(ai) -func add_card_to_all_ais(point: Point, card: MemoryCardResource) -> void: - _call_action_on_all_ais(func(ai: AiDifficultyResource) -> void: ai.blackboard.add_card(point, card)) +func add_card_to_all_ais(position: Vector2i, card: MemoryCardResource) -> void: + _call_action_on_all_ais(func(ai: AiDifficultyResource) -> void: ai.blackboard.add_card(position, card)) -func remove_card_to_all_ais(point: Point) -> void: - _call_action_on_all_ais(func(ai: AiDifficultyResource) -> void: ai.blackboard.remove_card(point)) +func remove_card_to_all_ais(position: Vector2i) -> void: + _call_action_on_all_ais(func(ai: AiDifficultyResource) -> void: ai.blackboard.remove_card(position)) diff --git a/entities/game/memory_game/scripts/systems/NetworkHandler.gd b/entities/game/memory_game/scripts/systems/NetworkHandler.gd index e8e747c..a1abbe2 100644 --- a/entities/game/memory_game/scripts/systems/NetworkHandler.gd +++ b/entities/game/memory_game/scripts/systems/NetworkHandler.gd @@ -5,8 +5,8 @@ const PORT: int = 8000 signal player_has_changed(player_id: int) signal player_has_scored(player_id: int, new_score: int) -signal card_was_clicked(position: Point) -signal remove_card(position: Point) +signal card_was_clicked(position: Vector2i) +signal remove_card(position: Vector2i) signal game_state_has_changed(new_state: int) signal game_has_been_finished() signal request_popup(window: PopupWindow) @@ -37,7 +37,7 @@ func peer_gone(_id: int) -> void: func card_clicked(_game_state: int, clicked_cards: Array[CardTemplate]) -> void: for card: CardTemplate in clicked_cards: - _rpc_card_clicked.rpc(card.grid_position.get_network_data()) + _rpc_card_clicked.rpc(card.grid_position) @rpc("any_peer", "reliable") func _rpc_card_clicked(position: Dictionary) -> void: @@ -45,9 +45,8 @@ func _rpc_card_clicked(position: Dictionary) -> void: print(multiplayer.get_unique_id()) if multiplayer.get_remote_sender_id() == multiplayer.get_unique_id(): return - var point:Point = Point.new(position["x"], position["y"]) - card_was_clicked.emit(point) + card_was_clicked.emit(position) func game_state_changed(state: GameEnum.State) -> void: if multiplayer.is_server(): @@ -101,20 +100,28 @@ func player_scored(player: PlayerResource) -> void: func _rpc_player_scored(player: Dictionary) -> void: player_has_scored.emit(player["id"], player["score"]) -func matching_pair(first: Point, second: Point) -> void: +func matching_pair(first: Vector2i, second: Vector2i) -> void: if !multiplayer.is_server(): return - var card_data: Array[Dictionary] = [first.get_network_data(), second.get_network_data()] + var card_data: Array[Dictionary] = [vector2i_to_network_data(first), vector2i_to_network_data(second)] var dict: Dictionary = {"cards": card_data} _rpc_remove_cards.rpc(dict) +func vector2i_to_network_data(data: Vector2i) -> Dictionary[String, int]: + return { + "x": data.x, + "y": data.y + } + +func data_to_vector2i(data: Dictionary[String, int]) -> Vector2i: + return Vector2i(data["x"], data["y"]) + @rpc("authority", "reliable") func _rpc_remove_cards(array_data: Dictionary) -> void: var data: Array[Dictionary] = array_data.get_or_add("cards", []); - for card: Dictionary in data: - var point: Point = Point.new(card["x"], card["y"]) - remove_card.emit(point) + for card_data: Dictionary in data: + remove_card.emit(data_to_vector2i(card_data)) func end_game() -> void: rpc_game_ended.rpc() diff --git a/entities/ui/multiplayer_lobby/scripts/MultiplayerGameLobby.gd b/entities/ui/multiplayer_lobby/scripts/MultiplayerGameLobby.gd index 422b8ff..88addb9 100644 --- a/entities/ui/multiplayer_lobby/scripts/MultiplayerGameLobby.gd +++ b/entities/ui/multiplayer_lobby/scripts/MultiplayerGameLobby.gd @@ -18,7 +18,7 @@ func _ready() -> void: func set_player_name(local_player_name: String) -> void: _local_user_name = local_player_name -func set_connect_endpoint(ip: String) -> void: +func set_connect_endVector2i(ip: String) -> void: _connect_ip = ip _is_host = false diff --git a/entities/ui/multiplayer_server_browser/scripts/HostMultiplayerGame.gd b/entities/ui/multiplayer_server_browser/scripts/HostMultiplayerGame.gd index 10df40a..f490012 100644 --- a/entities/ui/multiplayer_server_browser/scripts/HostMultiplayerGame.gd +++ b/entities/ui/multiplayer_server_browser/scripts/HostMultiplayerGame.gd @@ -26,7 +26,7 @@ func _pressed() -> void: instance.set_player_name(_current_player_name) if is_connect_button: - instance.set_connect_endpoint(_current_ip) + instance.set_connect_endVector2i(_current_ip) SettingsRepository.save_current_settings() else: instance.start_as_host() diff --git a/shared/entities/ai_behavior/resources/AiBehaviorNode.gd b/shared/entities/ai_behavior/resources/AiBehaviorNode.gd index f66d7ed..9f0c318 100644 --- a/shared/entities/ai_behavior/resources/AiBehaviorNode.gd +++ b/shared/entities/ai_behavior/resources/AiBehaviorNode.gd @@ -11,7 +11,7 @@ func can_execute(_blackboard: Blackboard, _grid: GameCardGrid) -> bool: func execute_action(_blackboard: Blackboard, _grid: GameCardGrid) -> void: pass -func _trigger_card(position: Point, _blackboard: Blackboard, grid: GameCardGrid) -> bool: +func _trigger_card(position: Vector2i, _blackboard: Blackboard, grid: GameCardGrid) -> bool: var card: MemoryCardResource = grid.get_card_on_position(position) if card == null: return false diff --git a/shared/entities/ai_behavior/resources/behaviors/CardInformationResource.gd b/shared/entities/ai_behavior/resources/behaviors/CardInformationResource.gd index 6eb9533..c08cce0 100644 --- a/shared/entities/ai_behavior/resources/behaviors/CardInformationResource.gd +++ b/shared/entities/ai_behavior/resources/behaviors/CardInformationResource.gd @@ -1,8 +1,8 @@ class_name CardInformationResource extends Resource -var position: Point +var position: Vector2i var card: MemoryCardResource -func _init(pos: Point, card_data: MemoryCardResource) -> void: +func _init(pos: Vector2i, card_data: MemoryCardResource) -> void: position = pos card = card_data \ No newline at end of file diff --git a/shared/entities/ai_behavior/resources/behaviors/GetMatchingCard.gd b/shared/entities/ai_behavior/resources/behaviors/GetMatchingCard.gd index 308d28a..a88ed1b 100644 --- a/shared/entities/ai_behavior/resources/behaviors/GetMatchingCard.gd +++ b/shared/entities/ai_behavior/resources/behaviors/GetMatchingCard.gd @@ -1,29 +1,29 @@ class_name GetMatchingCard extends AiBehaviorNode func can_execute(blackboard: Blackboard, grid: GameCardGrid) -> bool: - var unrevealed_cards: Array[Point] = grid.get_all_cards_currently_turned() + var unrevealed_cards: Array[Vector2i] = grid.get_all_cards_currently_turned() if unrevealed_cards.size() != 1: return false; - var card_of_focus: Point = unrevealed_cards[0] + 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.is_identical(card_of_focus): + if !stored_card.position == card_of_focus: return true return false func execute_action(blackboard: Blackboard, grid: GameCardGrid) -> void: print_debug("GetMatchingCard") - var unrevealed_cards: Array[Point] = grid.get_all_cards_currently_turned() - var card_of_focus: Point = unrevealed_cards[0] + var unrevealed_cards: Array[Vector2i] = grid.get_all_cards_currently_turned() + 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) for stored_card: CardInformationResource in stored_cards: - if !stored_card.position.is_identical(card_of_focus): + 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/ai_behavior/resources/behaviors/OpenFirstMatchingCard.gd b/shared/entities/ai_behavior/resources/behaviors/OpenFirstMatchingCard.gd index f8ed198..edf8cbe 100644 --- a/shared/entities/ai_behavior/resources/behaviors/OpenFirstMatchingCard.gd +++ b/shared/entities/ai_behavior/resources/behaviors/OpenFirstMatchingCard.gd @@ -8,7 +8,7 @@ func _get_blackboard_identical_cards(blackboard: Blackboard) -> Array[CardInform var pairs: Array[CardInformationResource] = [] for card: CardInformationResource in known_cards: for other_card: CardInformationResource in known_cards: - if other_card.card.id == card.card.id and !other_card.position.is_identical(card.position): + if other_card.card.id == card.card.id and !other_card.position == card.position: pairs.append(card) pairs.append(other_card) return pairs diff --git a/shared/entities/ai_behavior/resources/behaviors/OpenLastRevealedCard.gd b/shared/entities/ai_behavior/resources/behaviors/OpenLastRevealedCard.gd index 2c39ad0..a0cbdb8 100644 --- a/shared/entities/ai_behavior/resources/behaviors/OpenLastRevealedCard.gd +++ b/shared/entities/ai_behavior/resources/behaviors/OpenLastRevealedCard.gd @@ -1,10 +1,10 @@ class_name OpenLastRevealedCard extends AiBehaviorNode func can_execute(blackboard: Blackboard, grid: GameCardGrid) -> bool: - var all_card_positions: Array[Point] = grid.get_all_card_positions(false) + var all_card_positions: Array[Vector2i] = grid.get_all_card_positions(false) if blackboard.get_last_saved_card() != null and all_card_positions.size() % 2 == 0: - for card: Point in all_card_positions: - if blackboard.get_last_saved_card().position.is_identical(card): + for card_position: Vector2i in all_card_positions: + if blackboard.get_last_saved_card().position == card_position: return true return false diff --git a/shared/entities/ai_behavior/resources/behaviors/OpenRandomCard.gd b/shared/entities/ai_behavior/resources/behaviors/OpenRandomCard.gd index 9da0339..e2b497b 100644 --- a/shared/entities/ai_behavior/resources/behaviors/OpenRandomCard.gd +++ b/shared/entities/ai_behavior/resources/behaviors/OpenRandomCard.gd @@ -7,7 +7,7 @@ func can_execute(_blackboard: Blackboard, grid: GameCardGrid) -> bool: func execute_action(blackboard: Blackboard, grid: GameCardGrid) -> void: print_debug("OpenRandomCard") - var card_positions: Array[Point] = grid.get_all_card_positions(false) + var card_positions: Array[Vector2i] = grid.get_all_card_positions(false) var index: int = randi() % card_positions.size() if !_trigger_card(card_positions[index], blackboard, grid): execute_action(blackboard, grid) diff --git a/shared/entities/ai_behavior/resources/behaviors/OpenUnknownCard.gd b/shared/entities/ai_behavior/resources/behaviors/OpenUnknownCard.gd index 41fdc2d..667c974 100644 --- a/shared/entities/ai_behavior/resources/behaviors/OpenUnknownCard.gd +++ b/shared/entities/ai_behavior/resources/behaviors/OpenUnknownCard.gd @@ -2,15 +2,15 @@ class_name OpenUnknownCard extends AiBehaviorNode func can_execute(blackboard: Blackboard, grid: GameCardGrid) -> bool: - var unknown_card_positions: Array[Point] = get_all_unknown_card_positions(blackboard, grid) + var unknown_card_positions: Array[Vector2i] = get_all_unknown_card_positions(blackboard, grid) return unknown_card_positions.size() > 0 -func get_all_unknown_card_positions(blackboard: Blackboard, grid: GameCardGrid) -> Array[Point]: - var return_data: Array[Point] = [] - var all_positions: Array[Point] = grid.get_all_card_positions() +func get_all_unknown_card_positions(blackboard: Blackboard, grid: GameCardGrid) -> Array[Vector2i]: + var return_data: Array[Vector2i] = [] + var all_positions: Array[Vector2i] = grid.get_all_card_positions() var known_positions: Array[CardInformationResource] = blackboard.get_all_saved_cards() - for current_position: Point in all_positions: - if known_positions.any(func(known_position: CardInformationResource) -> bool: return known_position.position.is_identical(current_position)): + for current_position: Vector2i in all_positions: + if known_positions.any(func(known_position: CardInformationResource) -> bool: return known_position.position == current_position): continue return_data.append(current_position) @@ -19,7 +19,7 @@ func get_all_unknown_card_positions(blackboard: Blackboard, grid: GameCardGrid) func execute_action(blackboard: Blackboard, grid: GameCardGrid) -> void: print_debug("OpenUnknownCard") - var cards: Array[Point] = get_all_unknown_card_positions(blackboard, grid) + var cards: Array[Vector2i] = get_all_unknown_card_positions(blackboard, grid) var card_index: int = randi_range(0, cards.size() - 1) _trigger_card(cards[card_index], blackboard, grid) diff --git a/shared/entities/ai_behavior/resources/behaviors/RevealUnknownCornerCard.gd b/shared/entities/ai_behavior/resources/behaviors/RevealUnknownCornerCard.gd index bb94b90..5140413 100644 --- a/shared/entities/ai_behavior/resources/behaviors/RevealUnknownCornerCard.gd +++ b/shared/entities/ai_behavior/resources/behaviors/RevealUnknownCornerCard.gd @@ -1,15 +1,14 @@ class_name RevealUnknownCornerCard extends AiBehaviorNode func can_execute(blackboard: Blackboard, grid: GameCardGrid) -> bool: - for position: Point in grid.get_all_card_positions(false): - var real_position: Vector2i = Vector2i(position.get_x_pos(), position.get_y_pos()) - if _get_corner_positions(grid).find(real_position) != -1 and not _blackboard_card_known(blackboard, position): + for position: Vector2i in grid.get_all_card_positions(false): + if _get_corner_positions(grid).find(position) != -1 and not _blackboard_card_known(blackboard, position): return true return false -func _blackboard_card_known(blackboard: Blackboard, position: Point) -> bool: +func _blackboard_card_known(blackboard: Blackboard, position: Vector2i) -> bool: for card: CardInformationResource in blackboard.get_all_saved_cards(): - if card.position.is_identical(position): + if card.position == position: return true return false @@ -27,9 +26,8 @@ func execute_action(blackboard: Blackboard, grid: GameCardGrid) -> void: var allowed_positions: Array[Vector2i] = _get_corner_positions(grid) var valid_positions: Array[Vector2i] = [] for position: Vector2i in allowed_positions: - if not _blackboard_card_known(blackboard, Point.new(position.x, position.y)): + if not _blackboard_card_known(blackboard, position): valid_positions.append(position) var position: Vector2i = valid_positions.pick_random() - var point: Point = Point.new(position.x, position.y) - _trigger_card(point, blackboard, grid) \ No newline at end of file + _trigger_card(position, blackboard, grid) \ No newline at end of file diff --git a/shared/entities/point/scripts/Point.gd b/shared/entities/point/scripts/Point.gd deleted file mode 100644 index 6acdac1..0000000 --- a/shared/entities/point/scripts/Point.gd +++ /dev/null @@ -1,34 +0,0 @@ -## This whole class is not needed, as there is already something which can be used as a point. -## As this calls is used all over the code, it was refactored to extend the Vector2i class instead. -## This is therefore a wrapper, more or less. -class_name Point extends Node - -var position: Vector2i = Vector2i.ZERO - -func _init(x: int , y: int) -> void: - set_x_pos(x) - set_y_pos(y) - -func get_x_pos() -> int: - return position.x - -func get_y_pos() -> int: - return position.y - -func set_x_pos(x: int) -> void: - position.x = x - -func set_y_pos(y: int) -> void: - position.y = y - -func is_identical(other_point: Point) -> bool: - return other_point.get_x_pos() == get_x_pos() and other_point.get_y_pos() == get_y_pos() - -func get_distance(other_point: Point) -> float: - return sqrt(pow(get_x_pos() - other_point.get_x_pos(), 2) + pow(get_y_pos() - other_point.get_y_pos(), 2)) - -func get_network_data() -> Dictionary: - return { - "x": position.x, - "y": position.y - } \ No newline at end of file diff --git a/shared/entities/point/scripts/Point.gd.uid b/shared/entities/point/scripts/Point.gd.uid deleted file mode 100644 index 68a2630..0000000 --- a/shared/entities/point/scripts/Point.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://c5h7cdl4nr01y