fix: per-player phase state so 2nd player can still play after 1st played
This commit is contained in:
1 parent
78adeb7920
commit
25ab76c4ac
3 files changed
+25
-14
No files matched your search
@@ -72,11 +72,8 @@ class Room {
|
||||
const [card] = player.hand.splice(cardIndex, 1)
|
||||
this.pendingPlays.set(socketId, { player, card })
|
||||
|
||||
// Si tous ont joué → passer en "waiting" visible côté client
|
||||
if (this.pendingPlays.size === this.players.length) {
|
||||
this.phase = 'waiting'
|
||||
}
|
||||
|
||||
// La phase globale reste 'selecting' tant que tout le monde n'a pas joué
|
||||
// (seul le joueur qui vient de jouer passe en 'waiting' côté client via son état perso)
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -178,14 +175,19 @@ class Room {
|
||||
}))
|
||||
}
|
||||
|
||||
/** État envoyé à UN joueur spécifique (inclut sa main) */
|
||||
/** État envoyé à UN joueur spécifique (inclut sa main et sa phase personnelle) */
|
||||
getStateFor(socketId) {
|
||||
const player = this.players.find(p => p.socketId === socketId)
|
||||
// Si ce joueur a déjà joué ce tour → sa phase perso est 'waiting'
|
||||
// Sinon il est encore en 'selecting'
|
||||
const hasPlayed = this.pendingPlays.has(socketId)
|
||||
const personalPhase = this.phase === 'selecting' && hasPlayed ? 'waiting' : this.phase
|
||||
|
||||
return {
|
||||
players: this.getPlayersInfo(),
|
||||
currentTurn: this.currentTurn,
|
||||
maxTurns: this.maxTurns,
|
||||
phase: this.phase,
|
||||
phase: personalPhase,
|
||||
hand: player ? player.hand : [],
|
||||
myTeamIndex: player ? player.teamIndex : 0
|
||||
}
|
||||
|
||||
+5
-6
@@ -69,12 +69,11 @@ io.on('connection', (socket) => {
|
||||
return
|
||||
}
|
||||
|
||||
// Informer tous que quelqu'un a joué (sans révéler la carte)
|
||||
io.to(roomId).emit('game-state', {
|
||||
players: room.getPlayersInfo(),
|
||||
currentTurn: room.currentTurn,
|
||||
maxTurns: room.maxTurns,
|
||||
phase: room.phase
|
||||
// Envoyer à chaque joueur son état personnalisé :
|
||||
// - celui qui vient de jouer reçoit phase='waiting'
|
||||
// - les autres restent en phase='selecting'
|
||||
room.players.forEach(player => {
|
||||
io.to(player.socketId).emit('game-state', room.getStateFor(player.socketId))
|
||||
})
|
||||
|
||||
// Tous les joueurs ont joué → résolution automatique
|
||||
|
||||
Reference in new issue
Block a user