result states
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import simple from "./simple";
|
||||
|
||||
export type Game<
|
||||
S = unknown,
|
||||
A = unknown,
|
||||
E extends { error: any } = { error: any },
|
||||
V = unknown
|
||||
S = unknown, // state
|
||||
A = unknown, // action
|
||||
E extends { error: any } = { error: any }, // error
|
||||
V = unknown, // view
|
||||
R = unknown // results
|
||||
> = {
|
||||
title: string;
|
||||
rules: string;
|
||||
@@ -12,6 +13,7 @@ export type Game<
|
||||
resolveAction: (p: { state: S; action: A; humanKey: string }) => S | E;
|
||||
getView: (p: { state: S; humanKey: string }) => V;
|
||||
resolveQuit: (p: { state: S; humanKey: string }) => S;
|
||||
getResult: (state: S) => R | undefined;
|
||||
};
|
||||
|
||||
export const GAMES: {
|
||||
|
||||
@@ -101,6 +101,8 @@ export const resolveSimpleAction = ({
|
||||
}
|
||||
};
|
||||
|
||||
export type SimpleResult = string;
|
||||
|
||||
type SimpleError = { error: "whoops!" };
|
||||
|
||||
export default (config: SimpleConfiguration) =>
|
||||
@@ -112,9 +114,14 @@ export default (config: SimpleConfiguration) =>
|
||||
getView: ({ state, humanKey }) =>
|
||||
getSimplePlayerView(config, state, humanKey),
|
||||
resolveQuit: () => null,
|
||||
getResult: (state) =>
|
||||
Object.entries(state.playerHands).find(
|
||||
([_, hand]) => hand.length === 2
|
||||
)?.[0],
|
||||
} satisfies Game<
|
||||
SimpleGameState,
|
||||
SimpleAction,
|
||||
SimpleError,
|
||||
SimplePlayerView
|
||||
SimplePlayerView,
|
||||
SimpleResult
|
||||
>);
|
||||
|
||||
@@ -50,3 +50,5 @@ export const setDiff = <T>(
|
||||
});
|
||||
|
||||
export const set = <T>(arr: T[]) => new Set<T>(arr);
|
||||
|
||||
export const invert = <E>(obs: Observable<boolean, E>) => obs.map((o) => !o);
|
||||
|
||||
Reference in New Issue
Block a user