diff --git a/cards/card_manager.gd b/cards/card_manager.gd index 35f29b9..5eb63dd 100644 --- a/cards/card_manager.gd +++ b/cards/card_manager.gd @@ -1,6 +1,8 @@ extends Node @export var full_deck: Dictionary[int, Card] +@export var card_textures: Dictionary[int, Texture] +@export var card_fallback_texture: Texture func get_shuffled_cards(client_ids: Array[String], cards_to_pick: int) -> Dictionary: # Dictionary[String, Array[int]] var dict: Dictionary = {} @@ -21,3 +23,9 @@ func get_shuffled_cards(client_ids: Array[String], cards_to_pick: int) -> Dictio dict["trump"] = deck[card_index] return dict + +func get_card_texture(card_id: int) -> Texture: + if card_textures.has(card_id): + return card_textures[card_id] + + return card_fallback_texture diff --git a/cards/card_manager.tscn b/cards/card_manager.tscn index 9f46145..8a21e67 100644 --- a/cards/card_manager.tscn +++ b/cards/card_manager.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=63 format=3 uid="uid://hr727kw8y2hb"] +[gd_scene load_steps=64 format=3 uid="uid://hr727kw8y2hb"] [ext_resource type="Script" uid="uid://c5yx2hpj6lifp" path="res://cards/card_manager.gd" id="1_de166"] [ext_resource type="Script" uid="uid://dx4cl2rk0a8a0" path="res://cards/card.gd" id="2_vmpa3"] +[ext_resource type="Texture2D" uid="uid://i0wpcxpk7g2c" path="res://cards/textures/front_test.webp" id="3_hq606"] [sub_resource type="Resource" id="Resource_hq606"] script = ExtResource("2_vmpa3") @@ -548,3 +549,4 @@ full_deck = Dictionary[int, ExtResource("2_vmpa3")]({ 58: SubResource("Resource_slqcy"), 59: SubResource("Resource_rxi2e") }) +card_fallback_texture = ExtResource("3_hq606") diff --git a/cards/playing_card.gd b/cards/playing_card.gd index aad099c..d65b72d 100644 --- a/cards/playing_card.gd +++ b/cards/playing_card.gd @@ -1,12 +1,31 @@ class_name PlayingCard -extends StaticBody3D +extends Area3D @export var card_mesh: MeshInstance3D @export var front_texture: Texture +@export var move_duration: float = 0.2 + var card_details: Card +signal card_clicked(playing_card: PlayingCard) + func _ready() -> void: - set_front_texture(front_texture) + if card_details: + set_front_texture(CardManager.get_card_texture(card_details.card_id)) + else: + set_front_texture(CardManager.get_card_texture(-1)) + +func move_to(new_x_position: float) -> void: + #self.position.x = new_x_position + var tween = create_tween() + tween.set_trans(Tween.TRANS_BACK) + tween.set_ease(Tween.EASE_OUT) + tween.tween_property(self, "position:x", new_x_position, move_duration) func set_front_texture(texture: Texture) -> void: card_mesh.get_surface_override_material(0).albedo_texture = front_texture + +func _on_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void: + if event.is_action_pressed("left_mouse_button"): + print("yahaha!") + card_clicked.emit(self) diff --git a/cards/playing_card.tscn b/cards/playing_card.tscn index 462d43a..fac8401 100644 --- a/cards/playing_card.tscn +++ b/cards/playing_card.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://b55xpcxk7g5ph"] +[gd_scene load_steps=9 format=3 uid="uid://b55xpcxk7g5ph"] [ext_resource type="Script" uid="uid://c2odugkbbppxn" path="res://cards/playing_card.gd" id="1_t6o5d"] [ext_resource type="PackedScene" uid="uid://dxiv47be5dsll" path="res://cards/playing_card.glb" id="2_enav7"] @@ -14,17 +14,27 @@ albedo_color = Color(0, 0, 0, 1) [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_auvip"] albedo_texture = ExtResource("4_exvuq") -[node name="PlayingCard" type="StaticBody3D" node_paths=PackedStringArray("card_mesh")] +[sub_resource type="BoxShape3D" id="BoxShape3D_t6o5d"] +size = Vector3(2.38, 3.7, 0.05) + +[node name="PlayingCard" type="Area3D" node_paths=PackedStringArray("card_mesh")] transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0) +collision_layer = 8 +collision_mask = 0 script = ExtResource("1_t6o5d") -card_mesh = NodePath("PlayingCard/Cube") +card_mesh = NodePath("Model/Cube") front_texture = ExtResource("3_jeoeb") -[node name="PlayingCard" parent="." instance=ExtResource("2_enav7")] +[node name="Model" parent="." instance=ExtResource("2_enav7")] -[node name="Cube" parent="PlayingCard" index="0"] +[node name="Cube" parent="Model" index="0"] surface_material_override/0 = SubResource("StandardMaterial3D_nwj5s") surface_material_override/1 = SubResource("StandardMaterial3D_hel13") surface_material_override/2 = SubResource("StandardMaterial3D_auvip") -[editable path="PlayingCard"] +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("BoxShape3D_t6o5d") + +[connection signal="input_event" from="." to="." method="_on_input_event"] + +[editable path="Model"] diff --git a/elements/player_hand.gd b/elements/player_hand.gd new file mode 100644 index 0000000..916ddcd --- /dev/null +++ b/elements/player_hand.gd @@ -0,0 +1,53 @@ +class_name PlayerHand +extends Node3D + +@export var card_width: float = 2.35 + +## Distance cards will be apart when there is a small amount of them +@export var card_distance_max: float = 0.8 + +## Distance cards will be apart when there is a large amount of them +@export var card_distance_min: float = 0.32 + +## How many test cards to add +@export_range(0, 20) var test_card_count: int = 0 + +@export var card_scene: PackedScene + +@export_range(0, 20, 0.1, "radians_as_degrees") var card_angle: float + +func _ready() -> void: + _arrange_cards() + for i in test_card_count: + var card: PlayingCard = card_scene.instantiate() + card.card_clicked.connect(_on_card_clicked) + add_card(card) + await get_tree().create_timer(0.24).timeout + +func add_card(card: PlayingCard) -> void: + self.add_child(card) + _arrange_cards() + +func remove_card(card: PlayingCard) -> void: + self.remove_child(card) + _arrange_cards() + +func _arrange_cards() -> void: + var cards = self.get_children() + # Only arrange cards if there are any! + if cards.size() > 0: + var card_distance: float = _get_card_distance(cards.size() - 1) + print(card_distance) + var desired_width: float = (card_distance * (cards.size() - 1)) + var card_position = -desired_width / 2.0 + for card in cards: + #card.position.x = card_position + card.move_to(card_position) + card_position += card_distance + card.rotation.y = card_angle + +func _get_card_distance(card_count: int) -> float: + return card_distance_min + ((card_distance_max - card_distance_min) * (1.0 - (float(card_count) / 19.0))) + +func _on_card_clicked(playing_card: PlayingCard) -> void: + pass diff --git a/elements/player_hand.gd.uid b/elements/player_hand.gd.uid new file mode 100644 index 0000000..f2603d4 --- /dev/null +++ b/elements/player_hand.gd.uid @@ -0,0 +1 @@ +uid://b5b5cl2qlhywv diff --git a/elements/player_hand.tscn b/elements/player_hand.tscn new file mode 100644 index 0000000..2358909 --- /dev/null +++ b/elements/player_hand.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=3 uid="uid://jlovgr2iojrg"] + +[ext_resource type="Script" uid="uid://b5b5cl2qlhywv" path="res://elements/player_hand.gd" id="1_ank64"] +[ext_resource type="PackedScene" uid="uid://b55xpcxk7g5ph" path="res://cards/playing_card.tscn" id="2_11xsc"] + +[node name="PlayerHand" type="Node3D"] +script = ExtResource("1_ank64") +test_card_count = 20 +card_scene = ExtResource("2_11xsc") +card_angle = 0.125664 diff --git a/game.tscn b/game.tscn index 84603ce..555f4d4 100644 --- a/game.tscn +++ b/game.tscn @@ -1,9 +1,9 @@ -[gd_scene load_steps=7 format=3 uid="uid://gqrdpjslr4np"] +[gd_scene load_steps=8 format=3 uid="uid://gqrdpjslr4np"] [ext_resource type="Script" uid="uid://p5gvnyhjqe6o" path="res://components/web_client_tcp.gd" id="1_feb5d"] [ext_resource type="Script" uid="uid://c0cqkatyo4uj1" path="res://components/client_interface.gd" id="2_e2o6t"] [ext_resource type="Script" uid="uid://utt8atbh7b2a" path="res://game_client.gd" id="3_feb5d"] -[ext_resource type="PackedScene" uid="uid://b55xpcxk7g5ph" path="res://cards/playing_card.tscn" id="4_fc0e3"] +[ext_resource type="PackedScene" uid="uid://jlovgr2iojrg" path="res://elements/player_hand.tscn" id="4_fc0e3"] [sub_resource type="SystemFont" id="SystemFont_80nbo"] font_names = PackedStringArray("IBM Plex Mono") @@ -14,6 +14,9 @@ ambient_light_source = 2 ambient_light_color = Color(1, 1, 1, 1) ambient_light_energy = 0.15 +[sub_resource type="BoxMesh" id="BoxMesh_fc0e3"] +size = Vector3(0.2, 0.2, 0.2) + [node name="Game" type="Node"] [node name="WebClientTCP" type="Node" parent="."] @@ -23,6 +26,7 @@ script = ExtResource("1_feb5d") anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +offset_right = -1591.0 grow_horizontal = 2 grow_vertical = 2 @@ -139,6 +143,7 @@ layout_mode = 2 text = "Send" [node name="GameUI" type="Control" parent="HBoxContainer" node_paths=PackedStringArray("web_client", "start_game_button")] +visible = false layout_mode = 2 size_flags_horizontal = 3 script = ExtResource("3_feb5d") @@ -170,15 +175,18 @@ transform = Transform3D(1, 0, 0, 0, 0.997882, 0.0650548, 0, -0.0650548, 0.997882 billboard = 1 text = "Magician Online!" -[node name="PlayingCard" parent="Node3D" instance=ExtResource("4_fc0e3")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.6767) - [node name="DirectionalLight3D" type="DirectionalLight3D" parent="Node3D"] transform = Transform3D(0.970511, 0, 0.241058, -0.137972, 0.820002, 0.555482, -0.197668, -0.572361, 0.795821, 2.41581, 2.80426, 0) [node name="WorldEnvironment" type="WorldEnvironment" parent="Node3D"] environment = SubResource("Environment_fc0e3") +[node name="PlayerHand" parent="Node3D" instance=ExtResource("4_fc0e3")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.91793) + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Node3D"] +mesh = SubResource("BoxMesh_fc0e3") + [connection signal="client_joined_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_client_joined_lobby"] [connection signal="client_joined_lobby" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_client_joined_lobby"] [connection signal="client_left_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_client_left_lobby"] diff --git a/project.godot b/project.godot index 15f2edd..5050ef3 100644 --- a/project.godot +++ b/project.godot @@ -25,6 +25,18 @@ CardManager="*res://cards/card_manager.tscn" window/size/viewport_width=1920 window/size/viewport_height=1080 +[input] + +left_mouse_button={ +"deadzone": 0.2, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(217, 46),"global_position":Vector2(233, 130),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} + +[layer_names] + +3d_physics/layer_4="mouse" + [rendering] renderer/rendering_method="gl_compatibility"