end to end!
This commit is contained in:
@@ -21,15 +21,16 @@ export const WsIn = t.Union([
|
||||
]);
|
||||
export type TWsIn = typeof WsIn.static;
|
||||
|
||||
type Attributed = { humanKey: string };
|
||||
type TablePayload<GameState, GameAction> = {
|
||||
inputs: {
|
||||
presenceChanges: TBus<
|
||||
{ humanKey: string; presence: "joined" | "left" },
|
||||
Attributed & { presence: "joined" | "left" },
|
||||
never
|
||||
>;
|
||||
gameProposals: TBus<{ proposeGame: string }, never>;
|
||||
gameStarts: TBus<{ startGame: true }, never>;
|
||||
gameActions: TBus<GameAction, never>;
|
||||
gameActions: TBus<Attributed & GameAction, never>;
|
||||
};
|
||||
outputs: {
|
||||
playersPresent: Property<string[], never>;
|
||||
@@ -63,26 +64,22 @@ export const liveTable = <GameState, GameAction>(key: string) => {
|
||||
}, [] as string[]);
|
||||
|
||||
const gameState = transform(
|
||||
null as GameState | null,
|
||||
null as SimpleGameState | null,
|
||||
[
|
||||
gameStarts.thru((Evt) =>
|
||||
combine([Evt], [playersPresent], (evt, players) => ({
|
||||
...evt,
|
||||
players,
|
||||
}))
|
||||
),
|
||||
combine([gameStarts], [playersPresent], (evt, players) => ({
|
||||
...evt,
|
||||
players,
|
||||
})),
|
||||
(prev, evt: { players: string[] }) =>
|
||||
prev == null ? (newGame(evt.players) as GameState) : prev,
|
||||
prev == null
|
||||
? (newGame(evt.players) as SimpleGameState)
|
||||
: prev,
|
||||
],
|
||||
[
|
||||
gameActions,
|
||||
(prev, evt: GameAction) =>
|
||||
(prev, evt: Attributed & SimpleAction) =>
|
||||
prev != null
|
||||
? (resolveAction(
|
||||
prev as unknown as SimpleGameState,
|
||||
"evt",
|
||||
evt as SimpleAction
|
||||
) as GameState)
|
||||
? resolveAction(prev, evt.humanKey, evt)
|
||||
: prev,
|
||||
]
|
||||
).toProperty();
|
||||
|
||||
Reference in New Issue
Block a user