on client side work playerboards
This commit is contained in:
+41
-20
@@ -322,24 +322,27 @@ func add_player_character(peer_id):
|
|||||||
# Set goals based on player ID if server
|
# Set goals based on player ID if server
|
||||||
if multiplayer.is_server():
|
if multiplayer.is_server():
|
||||||
var goal_index = peer_id - 1
|
var goal_index = peer_id - 1
|
||||||
# Verify index is valid
|
|
||||||
if goal_index >= 0 and goal_index < preset_goals.size():
|
if goal_index >= 0 and goal_index < preset_goals.size():
|
||||||
# Convert to int array before assigning
|
# Convert to int array before assigning
|
||||||
var goals: Array[int] = []
|
var goals: Array[int] = []
|
||||||
for g in preset_goals[goal_index]:
|
for g in preset_goals[goal_index]:
|
||||||
goals.append(g)
|
goals.append(g)
|
||||||
player_character.goals = goals
|
player_character.goals = goals
|
||||||
|
# Force sync goals to everyone, including host
|
||||||
rpc("sync_player_goals", peer_id, goals)
|
rpc("sync_player_goals", peer_id, goals)
|
||||||
|
# Update UI immediately for server
|
||||||
|
update_all_players_goals()
|
||||||
|
|
||||||
|
# Local player setup
|
||||||
if peer_id == multiplayer.get_unique_id():
|
if peer_id == multiplayer.get_unique_id():
|
||||||
local_player_character = player_character
|
local_player_character = player_character
|
||||||
update_button_states()
|
update_button_states()
|
||||||
update_playerboard_ui()
|
update_playerboard_ui()
|
||||||
#update_goals_ui()
|
update_all_players_goals() # Force UI update for local player
|
||||||
|
|
||||||
# Sync this player's goals to everyone
|
# Request goals from server if we're a client
|
||||||
if multiplayer.is_server():
|
if not multiplayer.is_server():
|
||||||
rpc("sync_player_goals", peer_id, player_character.goals)
|
rpc_id(1, "request_goals_from_server", peer_id)
|
||||||
|
|
||||||
if multiplayer.is_server():
|
if multiplayer.is_server():
|
||||||
if peer_id > 1: # Not the host
|
if peer_id > 1: # Not the host
|
||||||
@@ -658,25 +661,43 @@ func update_all_players_goals():
|
|||||||
|
|
||||||
@rpc("any_peer", "call_local")
|
@rpc("any_peer", "call_local")
|
||||||
func sync_player_goals(player_id: int, goals: Array):
|
func sync_player_goals(player_id: int, goals: Array):
|
||||||
|
# Update the player's goals first
|
||||||
|
var player = get_node_or_null(str(player_id))
|
||||||
|
if player:
|
||||||
|
player.goals = goals.duplicate()
|
||||||
|
|
||||||
|
# Then update UI
|
||||||
|
update_all_players_goals()
|
||||||
|
|
||||||
|
# Force update for specific player in AllPlayerGoals
|
||||||
var player_idx = players.find(player_id)
|
var player_idx = players.find(player_id)
|
||||||
if player_idx >= 0 and player_idx < 4:
|
if player_idx >= 0 and player_idx < 4:
|
||||||
var goals_grid = $AllPlayerGoals.get_child(player_idx)
|
_update_player_goals_ui(player_idx, goals)
|
||||||
for slot_idx in range(9):
|
|
||||||
var slot = goals_grid.get_child(slot_idx)
|
|
||||||
var goal_value = goals[slot_idx]
|
|
||||||
|
|
||||||
# Hide all tiles
|
# Helper function to update specific player's goals UI
|
||||||
slot.get_node("TileHeart").hide()
|
func _update_player_goals_ui(player_idx: int, goals: Array):
|
||||||
slot.get_node("TileDiamond").hide()
|
var goals_grid = $AllPlayerGoals.get_child(player_idx)
|
||||||
slot.get_node("TileStar").hide()
|
for slot_idx in range(9):
|
||||||
slot.get_node("TileCoin").hide()
|
var slot = goals_grid.get_child(slot_idx)
|
||||||
|
var goal_value = goals[slot_idx] if slot_idx < goals.size() else -1
|
||||||
|
|
||||||
# Show appropriate tile
|
# Hide all tiles first
|
||||||
match goal_value:
|
for tile in ["TileHeart", "TileDiamond", "TileStar", "TileCoin"]:
|
||||||
7: slot.get_node("TileHeart").show()
|
slot.get_node(tile).hide()
|
||||||
8: slot.get_node("TileDiamond").show()
|
|
||||||
9: slot.get_node("TileStar").show()
|
# Show appropriate tile
|
||||||
10: slot.get_node("TileCoin").show()
|
match goal_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")
|
||||||
|
func request_goals_from_server(requesting_peer_id: int):
|
||||||
|
if multiplayer.is_server():
|
||||||
|
var goal_index = requesting_peer_id - 1
|
||||||
|
if goal_index >= 0 and goal_index < preset_goals.size():
|
||||||
|
rpc("sync_player_goals", requesting_peer_id, preset_goals[goal_index])
|
||||||
|
|
||||||
# Add this function near the top with other helper functions
|
# Add this function near the top with other helper functions
|
||||||
func initialize_random_goals(_size:int, min_value:int, max_value:int, null_count:float) -> Array:
|
func initialize_random_goals(_size:int, min_value:int, max_value:int, null_count:float) -> Array:
|
||||||
|
|||||||
Reference in New Issue
Block a user