cards are now distributed and displayed among all clients
This commit is contained in:
+24
-20
@@ -1,8 +1,10 @@
|
||||
class_name EnvironmentManager
|
||||
extends Node3D
|
||||
|
||||
var hand_associations: Dictionary[String, PlayerHand]
|
||||
|
||||
# In gameplay order
|
||||
var hand_associations: Dictionary[int, PlayerHandAssociation]
|
||||
#var hand_associations: Dictionary[int, PlayerHandAssociation]
|
||||
var _own_client_id: String
|
||||
@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]
|
||||
if own_index == 0:
|
||||
print("ïndex was 0 " + _own_client_id)
|
||||
# no change necessary!
|
||||
new_ids = client_ids
|
||||
elif own_index == client_ids.size() - 1:
|
||||
print("index was last " + _own_client_id)
|
||||
# you are at the end of the array
|
||||
new_ids = client_ids
|
||||
# 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
|
||||
new_ids.insert(0, _own_client_id)
|
||||
else:
|
||||
print("index was middle " + _own_client_id)
|
||||
# you are somewhere in the middle of the array
|
||||
# create array with you at the start
|
||||
new_ids = client_ids.slice(own_index)
|
||||
# add the rest of the original array
|
||||
new_ids.append_array(client_ids.slice(0, own_index))
|
||||
|
||||
print("playing order! -- !")
|
||||
print(new_ids)
|
||||
|
||||
for index in client_ids.size():
|
||||
for index in new_ids.size():
|
||||
var hand: PlayerHand
|
||||
if client_ids[index] == _own_client_id:
|
||||
hand_associations[index] = PlayerHandAssociation.new(
|
||||
_own_client_id,
|
||||
own_player_hand.get_path(),
|
||||
)
|
||||
hand = own_player_hand
|
||||
else:
|
||||
var hand: PlayerHand = player_hand_scene.instantiate()
|
||||
|
||||
# TODO
|
||||
self.add_child(hand) # needs position!
|
||||
hand_associations[index] = PlayerHandAssociation.new(
|
||||
client_ids[index],
|
||||
hand.get_path(),
|
||||
)
|
||||
hand = player_hand_scene.instantiate()
|
||||
self.add_child(hand)
|
||||
var reference_marker = marker_positions[index - 1]
|
||||
hand.global_position = reference_marker.global_position
|
||||
hand.global_rotation = reference_marker.global_rotation
|
||||
|
||||
#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:
|
||||
_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)
|
||||
|
||||
Reference in New Issue
Block a user