Synced the all playerboards, but there's still bugged while new player connected

This commit is contained in:
2025-02-11 16:21:23 +08:00
parent 7d022775d3
commit 39979b8e58
43 changed files with 3237 additions and 453 deletions
+76
View File
@@ -518,6 +518,82 @@ func end_current_turn():
next_turn()
rpc("sync_turn_index", current_turn_index)
func update_all_players_boards():
if not game_started:
return
var all_players = get_tree().get_nodes_in_group("Players")
var local_id = multiplayer.get_unique_id()
# Sort players by relative position to local player
all_players.sort_custom(func(a, b):
var a_id = int(String(a.name))
var b_id = int(String(b.name))
# Calculate relative positions
var a_rel = (a_id - local_id + max_players) % max_players
var b_rel = (b_id - local_id + max_players) % max_players
return a_rel < b_rel
)
# Update each player's board in AllPlayerBoards
for i in range(min(all_players.size() - 1, 3)): # Skip local player, max 3 other players
var player = all_players[i + 1] # +1 to skip local player
var board = $AllPlayerBoards.get_child(i) # "2", "3", "4"
var board_ui = board.get_node("PlayerboardUI")
# Update each slot
for slot_idx in range(25):
var slot = board_ui.get_node("Slot%d" % (slot_idx + 1))
var value = player.playerboard[slot_idx]
# Hide all tiles first
slot.get_node("TileHeart").hide()
slot.get_node("TileDiamond").hide()
slot.get_node("TileStar").hide()
slot.get_node("TileCoin").hide()
# Show correct tile based on value
match value:
7: slot.get_node("TileHeart").show()
8: slot.get_node("TileDiamond").show()
9: slot.get_node("TileStar").show()
10: slot.get_node("TileCoin").show()
@rpc("any_peer", "call_local")
func sync_playerboard(player_id: int, new_playerboard: Array):
# Update local player's board if it's their board
if player_id == multiplayer.get_unique_id() and local_player_character:
update_playerboard_ui()
# Important: Always update all boards when any board changes
update_all_players_boards()
# Update specific board in AllPlayerBoards UI
var board_index = players.find(player_id)
if board_index >= 0 and board_index < max_players:
var target_board_index = board_index + 1
if target_board_index != 1: # Skip local player's board
var container = $AllPlayerBoards.get_node_or_null(str(target_board_index))
if container and container.has_node("PlayerboardUI"):
var board_ui = container.get_node("PlayerboardUI")
for slot_idx in range(25):
update_board_slot(board_ui, slot_idx, new_playerboard[slot_idx])
func update_board_slot(board_ui: Node, slot_idx: int, value: int):
var slot_node = board_ui.get_node_or_null("Slot%d" % (slot_idx + 1))
if slot_node:
# Hide all tiles first
for tile in ["TileHeart", "TileDiamond", "TileStar", "TileCoin"]:
slot_node.get_node(tile).hide()
# Show appropriate tile
match value:
7: slot_node.get_node("TileHeart").show()
8: slot_node.get_node("TileDiamond").show()
9: slot_node.get_node("TileStar").show()
10: slot_node.get_node("TileCoin").show()
func update_all_players_goals():
if not game_started:
return