cards are now distributed and displayed among all clients

This commit is contained in:
2025-07-15 11:31:01 +02:00
parent e7b53601c0
commit 3a22a4e95d
6 changed files with 40 additions and 39 deletions
+1 -7
View File
@@ -28,18 +28,12 @@ func get_shuffled_cards(client_ids: Array[String], cards_to_pick: int) -> Dictio
return dict return dict
func get_card_texture(card_id: int, style: CardStyle = CardStyle.STICKMAN) -> Texture: func get_card_texture(card_id: int, style: CardStyle = CardStyle.STICKMAN) -> Texture:
#if card_textures.has(card_id):
#return card_textures[card_id]
var style_name: String = "" var style_name: String = ""
match style: match style:
CardStyle.STICKMAN: CardStyle.STICKMAN:
style_name = "stickman" style_name = "stickman"
var a = "res://cards/textures/" + style_name + "/" + _get_card_name(card_id) + ".webp" return load("res://cards/textures/" + style_name + "/" + _get_card_name(card_id) + ".webp")
print(a)
return load(a)
#return card_fallback_texture
func _get_card_name(card_id: int) -> String: func _get_card_name(card_id: int) -> String:
var color: String var color: String
var suffix: String var suffix: String
+3 -3
View File
@@ -37,7 +37,7 @@ 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 client_order_received(client_ids: Array[String])
signal cards_received(card_ids: Array[int]) signal cards_received(cards: Dictionary)
enum ConnectionStatus { enum ConnectionStatus {
DISCONNECTED, DISCONNECTED,
@@ -127,8 +127,8 @@ func _handle_response(response: String) -> void:
playing_order.assign(data["playing_order"]) playing_order.assign(data["playing_order"])
client_order_received.emit.call_deferred(playing_order) client_order_received.emit.call_deferred(playing_order)
var received_cards: Array[int] = [] var received_cards = data["cards"]
received_cards.assign(data["cards"]) print(received_cards)
cards_received.emit.call_deferred(received_cards) cards_received.emit.call_deferred(received_cards)
"client_submitted_bet": "client_submitted_bet":
print(data) print(data)
+7 -7
View File
@@ -17,13 +17,13 @@ var _selected_card: PlayingCard = null
signal card_selected(card_id: int) signal card_selected(card_id: int)
signal card_played(card_id: int) signal card_played(card_id: int)
func _ready() -> void: #func _ready() -> void:
_arrange_cards() #_arrange_cards()
var test_array: Array[int] #var test_array: Array[int]
for i in range(10): #for i in range(10):
test_array.append(randi_range(0, 59)) #test_array.append(randi_range(0, 59))
#
add_cards(test_array, "") #add_cards(test_array, "")
func add_card(card: PlayingCard) -> void: func add_card(card: PlayingCard) -> void:
self.add_child(card) self.add_child(card)
+24 -20
View File
@@ -1,8 +1,10 @@
class_name EnvironmentManager class_name EnvironmentManager
extends Node3D extends Node3D
var hand_associations: Dictionary[String, PlayerHand]
# In gameplay order # In gameplay order
var hand_associations: Dictionary[int, PlayerHandAssociation] #var hand_associations: Dictionary[int, PlayerHandAssociation]
var _own_client_id: String var _own_client_id: String
@export var own_player_hand: PlayerHand @export var own_player_hand: PlayerHand
@@ -36,11 +38,9 @@ func _on_web_client_tcp_client_order_received(client_ids: Array[String]) -> void
var new_ids: Array[String] var new_ids: Array[String]
if own_index == 0: if own_index == 0:
print("ïndex was 0 " + _own_client_id)
# no change necessary! # no change necessary!
new_ids = client_ids new_ids = client_ids
elif own_index == client_ids.size() - 1: elif own_index == client_ids.size() - 1:
print("index was last " + _own_client_id)
# you are at the end of the array # you are at the end of the array
new_ids = client_ids new_ids = client_ids
# take away own client id # take away own client id
@@ -48,31 +48,35 @@ func _on_web_client_tcp_client_order_received(client_ids: Array[String]) -> void
# add it to the start of the array # add it to the start of the array
new_ids.insert(0, _own_client_id) new_ids.insert(0, _own_client_id)
else: else:
print("index was middle " + _own_client_id)
# you are somewhere in the middle of the array # you are somewhere in the middle of the array
# create array with you at the start # create array with you at the start
new_ids = client_ids.slice(own_index) new_ids = client_ids.slice(own_index)
# add the rest of the original array # add the rest of the original array
new_ids.append_array(client_ids.slice(0, own_index)) new_ids.append_array(client_ids.slice(0, own_index))
print("playing order! -- !") for index in new_ids.size():
print(new_ids) var hand: PlayerHand
for index in client_ids.size():
if client_ids[index] == _own_client_id: if client_ids[index] == _own_client_id:
hand_associations[index] = PlayerHandAssociation.new( hand = own_player_hand
_own_client_id,
own_player_hand.get_path(),
)
else: else:
var hand: PlayerHand = player_hand_scene.instantiate() hand = player_hand_scene.instantiate()
self.add_child(hand)
# TODO var reference_marker = marker_positions[index - 1]
self.add_child(hand) # needs position! hand.global_position = reference_marker.global_position
hand_associations[index] = PlayerHandAssociation.new( hand.global_rotation = reference_marker.global_rotation
client_ids[index],
hand.get_path(), #hand_associations[index] = PlayerHandAssociation.new(
) #client_ids[index],
#hand.get_path(),
#)
hand_associations[client_ids[index]] = hand
func _on_web_client_tcp_received_client_id(client_id: String) -> void: func _on_web_client_tcp_received_client_id(client_id: String) -> void:
_own_client_id = client_id _own_client_id = client_id
func _on_web_client_tcp_cards_received(cards: Dictionary) -> void:
for client_id in cards.keys():
var card_ids: Array[int]
card_ids.assign(cards[client_id])
hand_associations[client_id].add_cards(card_ids, client_id)
+1
View File
@@ -235,6 +235,7 @@ transform = Transform3D(-0.5, 0, 0.866025, 0, 1, 0, -0.866025, 0, -0.5, 3.2, 0.4
[node name="Table" parent="EnvironmentManager" instance=ExtResource("7_eow3j")] [node name="Table" parent="EnvironmentManager" instance=ExtResource("7_eow3j")]
[connection signal="cards_received" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_cards_received"]
[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"]
+4 -2
View File
@@ -179,16 +179,18 @@ class LobbyManager:
trump = None trump = None
if cards["trump"]: if cards["trump"]:
trump = cards["trump"] trump = cards["trump"]
cards.pop("trump")
for client_id in client_ids: for client_id in client_ids:
client_cards = cards[client_id] # client_cards = cards[client_id]
print(cards)
await self.send_message( await self.send_message(
lobby_id, lobby_id,
client_id, client_id,
json.dumps({ json.dumps({
"response": "new_round_started", "response": "new_round_started",
"current_round": round, "current_round": round,
"cards": client_cards, "cards": cards,
"trump": trump, "trump": trump,
"playing_order": playing_order, "playing_order": playing_order,
}) })