started adding player hand creation

This commit is contained in:
2025-07-08 17:40:13 +02:00
parent e0693725ea
commit 898c0d21ea
6 changed files with 71 additions and 10 deletions
+12
View File
@@ -0,0 +1,12 @@
class_name PlayerHandAssociation
extends Resource
@export var client_id: String
@export var player_hand: NodePath
func _init(
client_id: String,
player_hand: NodePath,
) -> void:
self.client_id = client_id
self.player_hand = player_hand
@@ -0,0 +1 @@
uid://b7jhvapb5344t
+13
View File
@@ -26,6 +26,7 @@ signal disconnected_from_server()
signal connected_to_lobby(lobby_id: String) signal connected_to_lobby(lobby_id: String)
signal disconnected_from_lobby() signal disconnected_from_lobby()
signal received_client_id(client_id: String)
signal client_joined_lobby(client_name: String, connected_client_names: Array[String]) signal client_joined_lobby(client_name: String, connected_client_names: Array[String])
signal client_left_lobby(client_name: String, connected_client_names: Array[String]) signal client_left_lobby(client_name: String, connected_client_names: Array[String])
@@ -35,6 +36,9 @@ signal received_chat_message(client_name: String, message: String)
signal connection_status_changed(new_status: ConnectionStatus) signal connection_status_changed(new_status: ConnectionStatus)
signal client_order_received(client_ids: Array[String])
signal cards_received(card_ids: Array[int])
enum ConnectionStatus { enum ConnectionStatus {
DISCONNECTED, DISCONNECTED,
ATTEMPTING_CONNECTION, ATTEMPTING_CONNECTION,
@@ -117,6 +121,14 @@ func _handle_response(response: String) -> void:
"new_round_started": "new_round_started":
print(data) print(data)
if data["current_round"] == 1:
var playing_order: Array[String] = []
playing_order.assign(data["playing_order"])
client_order_received.emit.call_deferred(playing_order)
var received_cards: Array[int] = []
received_cards.assign(data["cards"])
cards_received.emit.call_deferred(received_cards)
"client_submitted_bet": "client_submitted_bet":
print(data) print(data)
"client_played_card": "client_played_card":
@@ -133,6 +145,7 @@ func _handle_join(data) -> void:
"ok": "ok":
_client_id = data["client_id"] _client_id = data["client_id"]
connected_to_lobby.emit.call_deferred(_lobby_id) connected_to_lobby.emit.call_deferred(_lobby_id)
received_client_id.emit.call_deferred(_client_id)
connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED) connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED)
func _exit_tree() -> void: func _exit_tree() -> void:
+28
View File
@@ -0,0 +1,28 @@
class_name EnvironmentManager
extends Node3D
var player_hands: Dictionary[int, PlayerHandAssociation]
var _own_client_id: String
@export var own_player_hand: PlayerHand
@export var player_hand_scene: PackedScene
func _on_web_client_tcp_client_order_received(client_ids: Array[String]) -> void:
for index in client_ids.size():
if client_ids[index] == _own_client_id:
player_hands[index] = PlayerHandAssociation.new(
_own_client_id,
own_player_hand.get_path(),
)
else:
var hand: PlayerHand = player_hand_scene.instantiate()
# TODO
self.add_child(hand) # needs position!
player_hands[index] = PlayerHandAssociation.new(
client_ids[index],
hand.get_path(),
)
func _on_web_client_tcp_received_client_id(client_id: String) -> void:
_own_client_id = client_id
+1
View File
@@ -0,0 +1 @@
uid://bipfa366flrfa
+16 -10
View File
@@ -1,8 +1,9 @@
[gd_scene load_steps=8 format=3 uid="uid://gqrdpjslr4np"] [gd_scene load_steps=9 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://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://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="Script" uid="uid://utt8atbh7b2a" path="res://game_client.gd" id="3_feb5d"]
[ext_resource type="Script" uid="uid://bipfa366flrfa" path="res://environment_manager.gd" id="4_7jktm"]
[ext_resource type="PackedScene" uid="uid://jlovgr2iojrg" path="res://elements/player_hand.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"] [sub_resource type="SystemFont" id="SystemFont_80nbo"]
@@ -181,31 +182,35 @@ grow_vertical = 0
disabled = true disabled = true
text = "Play Card" text = "Play Card"
[node name="Node3D" type="Node3D" parent="."] [node name="EnvironmentManager" type="Node3D" parent="." node_paths=PackedStringArray("own_player_hand")]
script = ExtResource("4_7jktm")
own_player_hand = NodePath("PlayerHand")
player_hand_scene = ExtResource("4_fc0e3")
[node name="Camera3D" type="Camera3D" parent="Node3D"] [node name="Camera3D" type="Camera3D" parent="EnvironmentManager"]
transform = Transform3D(1, 0, 0, 0, 0.997882, 0.0650548, 0, -0.0650548, 0.997882, 0, 0.171315, 1.65638) transform = Transform3D(1, 0, 0, 0, 0.997882, 0.0650548, 0, -0.0650548, 0.997882, 0, 0.171315, 1.65638)
[node name="Label3D" type="Label3D" parent="Node3D"] [node name="Label3D" type="Label3D" parent="EnvironmentManager"]
billboard = 1 billboard = 1
text = "Magician Online!" text = "Magician Online!"
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="Node3D"] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="EnvironmentManager"]
transform = Transform3D(0.970511, 0, 0.241058, -0.137972, 0.820002, 0.555482, -0.197668, -0.572361, 0.795821, 2.41581, 2.80426, 0) 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"] [node name="WorldEnvironment" type="WorldEnvironment" parent="EnvironmentManager"]
environment = SubResource("Environment_fc0e3") environment = SubResource("Environment_fc0e3")
[node name="PlayerHand" parent="Node3D" instance=ExtResource("4_fc0e3")] [node name="PlayerHand" parent="EnvironmentManager" instance=ExtResource("4_fc0e3")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.91793) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.91793)
[node name="MeshInstance3D" type="MeshInstance3D" parent="Node3D"] [node name="MeshInstance3D" type="MeshInstance3D" parent="EnvironmentManager"]
mesh = SubResource("BoxMesh_fc0e3") 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/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_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"] [connection signal="client_left_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_client_left_lobby"]
[connection signal="client_left_lobby" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_client_left_lobby"] [connection signal="client_left_lobby" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_client_left_lobby"]
[connection signal="client_order_received" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_client_order_received"]
[connection signal="connected_to_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connected_to_lobby"] [connection signal="connected_to_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connected_to_lobby"]
[connection signal="connected_to_server" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connected_to_server"] [connection signal="connected_to_server" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connected_to_server"]
[connection signal="connection_error_occurred" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connection_error_occurred"] [connection signal="connection_error_occurred" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connection_error_occurred"]
@@ -213,6 +218,7 @@ mesh = SubResource("BoxMesh_fc0e3")
[connection signal="disconnected_from_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_lobby"] [connection signal="disconnected_from_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_lobby"]
[connection signal="disconnected_from_server" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_server"] [connection signal="disconnected_from_server" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_server"]
[connection signal="received_chat_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_chat_message"] [connection signal="received_chat_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
[connection signal="received_client_id" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_client_id"]
[connection signal="received_connection_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_connection_message"] [connection signal="received_connection_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_connection_message"]
[connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/ConnectButton" to="HBoxContainer/ClientInterface" method="_on_connect_button_pressed"] [connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/ConnectButton" to="HBoxContainer/ClientInterface" method="_on_connect_button_pressed"]
[connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/CreateLobbyButton" to="HBoxContainer/ClientInterface" method="_on_create_lobby_button_pressed"] [connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/CreateLobbyButton" to="HBoxContainer/ClientInterface" method="_on_create_lobby_button_pressed"]
@@ -222,5 +228,5 @@ mesh = SubResource("BoxMesh_fc0e3")
[connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/LeaveLobbyButton" to="HBoxContainer/ClientInterface" method="_on_disconnect_lobby_button_pressed"] [connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/LeaveLobbyButton" to="HBoxContainer/ClientInterface" method="_on_disconnect_lobby_button_pressed"]
[connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ChatContainer/SendMessageButton" to="HBoxContainer/ClientInterface" method="_on_send_message_button_pressed"] [connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ChatContainer/SendMessageButton" to="HBoxContainer/ClientInterface" method="_on_send_message_button_pressed"]
[connection signal="pressed" from="HBoxContainer/GameUI/StartGameButton" to="HBoxContainer/GameUI" method="_on_start_game_button_pressed"] [connection signal="pressed" from="HBoxContainer/GameUI/StartGameButton" to="HBoxContainer/GameUI" method="_on_start_game_button_pressed"]
[connection signal="pressed" from="HBoxContainer/GameUI/PlayCardButton" to="Node3D/PlayerHand" method="_on_play_card_button_pressed"] [connection signal="pressed" from="HBoxContainer/GameUI/PlayCardButton" to="EnvironmentManager/PlayerHand" method="_on_play_card_button_pressed"]
[connection signal="card_selected" from="Node3D/PlayerHand" to="HBoxContainer/GameUI" method="_on_player_hand_card_selected"] [connection signal="card_selected" from="EnvironmentManager/PlayerHand" to="HBoxContainer/GameUI" method="_on_player_hand_card_selected"]