[wip] configs are synced but gameplay is broken

This commit is contained in:
2025-09-07 22:56:56 -04:00
parent 46002403c8
commit ae6a79aadd
9 changed files with 239 additions and 154 deletions

View File

@@ -26,6 +26,9 @@ export const WsOut = t.Union([
export type TWsOut = typeof WsOut.static;
export const WsIn = t.Union([
t.Object({ name: t.String() }),
t.Object({
gameConfig: t.Object({ game: t.String(), players: t.Array(t.String()) }),
}),
t.Object({ ready: t.Boolean() }),
t.Object({ action: t.Any() }),
t.Object({ quit: t.Literal(true) }),
@@ -138,8 +141,14 @@ export const liveTable = <
});
});
const { name, ready, action, quit } = partition(
["name", "ready", "action", "quit"],
const {
name,
ready,
action,
quit,
gameConfig: clientGameConfigs,
} = partition(
["name", "ready", "action", "quit", "gameConfig"],
messages
) as unknown as {
// yuck
@@ -147,6 +156,7 @@ export const liveTable = <
ready: Observable<Attributed & { ready: boolean }, any>;
action: Observable<Attributed & { action: GameAction }, any>;
quit: Observable<Attributed, any>;
gameConfig: Observable<Attributed & { gameConfig: GameConfig }, any>;
};
const gameEnds = quit.map((_) => null);
@@ -265,13 +275,19 @@ export const liveTable = <
players: [] as string[],
},
[
playersPresent.filterBy(gameIsActive.map((active) => !active)),
playersPresent.filterBy(gameIsActive.thru(invert)),
(prev, players) => ({
...prev,
players,
}),
],
[
clientGameConfigs
// .filterBy(gameIsActive.thru(invert))
.map(({ gameConfig }) => gameConfig),
// @ts-ignore
(prev, config) => ({ ...config, players: prev.players }),
]
// TODO: Add player defined config changes
) as unknown as Observable<GameConfig, any>
);