fix(candy-survival): initialize local HUD badge text splits and synchronize Knock/Ghost charge counts reliably

This commit is contained in:
2026-07-08 16:42:59 +08:00
parent 8410679890
commit 37e5d96b55
@@ -89,6 +89,13 @@ func activate_client_side() -> void:
if hud_layer:
hud_layer.visible = true
set_process(true)
if hud_stack_badge:
hud_stack_badge.text = "Stack: 0 (x1.0)\nRed: 0x Blue: 0x Green: 0x Yellow: 0x"
if hud_knock_label:
hud_knock_label.text = "🥊 Knocks: 5"
if hud_ghost_label:
hud_ghost_label.text = "👻 Ghosts: 5"
# Per-player state
var player_candies: Dictionary = {} # pid -> int (stack count)
@@ -387,6 +394,7 @@ func try_knock(attacker: int, target: int) -> bool:
if target_candies == 0:
# Backfire: both lose a charge
player_knocks[attacker] = player_knocks.get(attacker, 0) - 1
rpc("sync_knock_charge_count", attacker, player_knocks[attacker])
# Attacker is also knocked down briefly (visual handled by caller)
rpc("sync_knock_result", attacker, target, 0)
return false
@@ -401,6 +409,7 @@ func try_knock(attacker: int, target: int) -> bool:
player_candies[target] = 0
player_knocks[attacker] = player_knocks.get(attacker, 0) - 1
rpc("sync_knock_charge_count", attacker, player_knocks[attacker])
player_last_knocked_by[target] = attacker
_add_score(attacker, target_candies * 100)
@@ -636,6 +645,10 @@ func sync_state_to_player(peer_id: int) -> void:
# Sync Ghost inventory to make the HUD button visible on player load
_update_special_inventory_for_ghosts(peer_id)
# Sync Knock and Ghost charges
rpc_id(peer_id, "sync_knock_charge_count", peer_id, player_knocks.get(peer_id, START_KNOCK))
rpc_id(peer_id, "sync_ghost_charge_count", peer_id, player_ghosts.get(peer_id, START_GHOST))
# Sync all players' candy stack heights and colors
for pid in player_candy_colors.keys():
var count = player_candies.get(pid, 0)
@@ -688,3 +701,13 @@ func sync_ghost_charge_count(pid: int, count: int) -> void:
if multiplayer.get_unique_id() == pid:
if hud_ghost_label:
hud_ghost_label.text = "👻 Ghosts: %d" % count
@rpc("authority", "call_local", "unreliable")
func sync_knock_charge_count(pid: int, count: int) -> void:
if not active:
activate_client_side()
if player_knocks.has(pid) or pid == multiplayer.get_unique_id():
player_knocks[pid] = count
if multiplayer.get_unique_id() == pid:
if hud_knock_label:
hud_knock_label.text = "🥊 Knocks: %d" % count