feat(web client): ask nickname when joining a room
This commit is contained in:
parent
d24f850882
commit
2c3281cc34
7 changed files with 268 additions and 50 deletions
|
|
@ -202,6 +202,16 @@ impl BackEndArchitecture<PlayerAction, GameDelta, ViewState> for TrictracBackend
|
|||
}
|
||||
|
||||
fn inform_rpc(&mut self, mp_player: u16, action: PlayerAction) {
|
||||
// SetName is always accepted regardless of game stage or whose turn it is.
|
||||
if let PlayerAction::SetName(name) = action {
|
||||
let store_id = if mp_player == 0 { HOST_PLAYER_ID } else { GUEST_PLAYER_ID };
|
||||
if let Some(p) = self.game.players.get_mut(&store_id) {
|
||||
p.name = name;
|
||||
}
|
||||
self.broadcast_state();
|
||||
return;
|
||||
}
|
||||
|
||||
// During the first-player ceremony only PreGameRoll actions are accepted.
|
||||
if self.ceremony_started {
|
||||
if matches!(action, PlayerAction::PreGameRoll) {
|
||||
|
|
@ -262,6 +272,7 @@ impl BackEndArchitecture<PlayerAction, GameDelta, ViewState> for TrictracBackend
|
|||
}
|
||||
}
|
||||
PlayerAction::PreGameRoll => {} // ignored outside ceremony
|
||||
PlayerAction::SetName(_) => {} // handled at the top of inform_rpc
|
||||
}
|
||||
|
||||
self.broadcast_state();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ pub enum PlayerAction {
|
|||
Mark,
|
||||
/// Roll a single die during the pre-game ceremony to decide who goes first.
|
||||
PreGameRoll,
|
||||
/// Declare the player's display name; sent once immediately after connecting.
|
||||
SetName(String),
|
||||
}
|
||||
|
||||
// ── Incremental state update broadcast to all clients ────────────────────────
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue