This commit is contained in:
2026-03-24 15:25:40 +08:00
parent 292a4181ce
commit 58fe43607a
7 changed files with 757 additions and 9 deletions

View File

@@ -6,7 +6,13 @@ export type RoomStatus = 'waiting' | 'playing' | 'finished'
export interface RoomPlayerState {
index: number
playerId: string
displayName?: string
ready: boolean
handCount?: number
melds?: string[]
outTiles?: string[]
hasHu?: boolean
missingSuit?: string | null
}
export interface RuleState {
@@ -57,6 +63,7 @@ export interface RoomState {
game: GameState | null
players: RoomPlayerState[]
currentTurnIndex: number | null
myHand: string[]
}
function createInitialRoomState(): RoomState {
@@ -73,6 +80,7 @@ function createInitialRoomState(): RoomState {
game: null,
players: [],
currentTurnIndex: null,
myHand: [],
}
}
@@ -92,6 +100,7 @@ export function resetActiveRoomState(seed?: Partial<RoomState>): void {
...activeRoomState.value,
...seed,
players: seed.players ?? [],
myHand: seed.myHand ?? [],
}
}
@@ -103,10 +112,17 @@ export function mergeActiveRoomState(next: RoomState): void {
activeRoomState.value = {
...activeRoomState.value,
...next,
name: next.name || activeRoomState.value.name,
gameType: next.gameType || activeRoomState.value.gameType,
ownerId: next.ownerId || activeRoomState.value.ownerId,
status: next.status || activeRoomState.value.status,
createdAt: next.createdAt || activeRoomState.value.createdAt,
updatedAt: next.updatedAt || activeRoomState.value.updatedAt,
game: next.game ?? activeRoomState.value.game,
players: next.players.length > 0 ? next.players : activeRoomState.value.players,
currentTurnIndex:
next.currentTurnIndex !== null ? next.currentTurnIndex : activeRoomState.value.currentTurnIndex,
myHand: next.myHand.length > 0 ? next.myHand : activeRoomState.value.myHand,
}
}
@@ -122,6 +138,7 @@ export function hydrateActiveRoomFromSelection(input: {
updatedAt?: string
players?: RoomPlayerState[]
currentTurnIndex?: number | null
myHand?: string[]
}): void {
resetActiveRoomState({
id: input.roomId,
@@ -135,5 +152,6 @@ export function hydrateActiveRoomFromSelection(input: {
updatedAt: input.updatedAt ?? '',
players: input.players ?? [],
currentTurnIndex: input.currentTurnIndex ?? null,
myHand: input.myHand ?? [],
})
}