bugs bashed
This commit is contained in:
@@ -1,21 +1,9 @@
|
||||
import { Game } from "@games/shared/games";
|
||||
import { Human } from "@prisma/client";
|
||||
import dayjs from "dayjs";
|
||||
import { Elysia, t } from "elysia";
|
||||
import { combine } from "kefir";
|
||||
import Bus from "kefir-bus";
|
||||
import { liveTable, WsIn, WsOut } from "./table";
|
||||
import { Elysia } from "elysia";
|
||||
import { generateTokenAndKey, resolveToken } from "./human";
|
||||
import { err } from "./logging";
|
||||
import { generateTokenAndKey, resolveToken, tokenExists } from "./human";
|
||||
|
||||
export const WS = Bus<
|
||||
{
|
||||
type: "open" | "message" | "error" | "close";
|
||||
humanKey: string;
|
||||
tableKey: string;
|
||||
},
|
||||
unknown
|
||||
>();
|
||||
import { liveTable, WsIn, WsOut } from "./table";
|
||||
import type { ExtractPropertyType, UnionKeys } from "@games/shared/types";
|
||||
|
||||
const api = new Elysia({ prefix: "/api" })
|
||||
.post("/whoami", async ({ cookie: { token } }) => {
|
||||
@@ -57,6 +45,7 @@ const api = new Elysia({ prefix: "/api" })
|
||||
...table.outputs.global,
|
||||
...(table.outputs.player[humanKey] ?? {}),
|
||||
}).forEach(([type, stream]) =>
|
||||
// @ts-ignore
|
||||
stream.onValue((v) => send({ [type]: v }))
|
||||
);
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ new Elysia()
|
||||
})
|
||||
)
|
||||
|
||||
.onError(({ error }) => console.error(error))
|
||||
// .onError(({ error }) => console.error(error))
|
||||
|
||||
.get("/ping", () => "pong")
|
||||
.use(api)
|
||||
|
||||
@@ -10,7 +10,7 @@ export const log = (value: unknown) => LogBus.emit(value);
|
||||
export const err = (value: unknown) =>
|
||||
LogBus.emitEvent({ type: "error", value });
|
||||
|
||||
LogStream.log();
|
||||
LogStream.onError((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
// LogStream.log();
|
||||
// LogStream.onError((err) => {
|
||||
// console.error(err);
|
||||
// });
|
||||
|
||||
@@ -12,6 +12,9 @@ import { t } from "elysia";
|
||||
import { combine, constant, merge, Observable, pool, Property } from "kefir";
|
||||
import Bus, { type Bus as TBus } from "kefir-bus";
|
||||
import { log } from "./logging";
|
||||
import simple from "@games/shared/games/simple";
|
||||
|
||||
const DEFAULT_GAME_CONFIG = simple.defaultConfig;
|
||||
|
||||
export const WsOut = t.Union([
|
||||
t.Object({ playersPresent: t.Array(t.String()) }),
|
||||
@@ -270,10 +273,7 @@ export const liveTable = <
|
||||
|
||||
gameConfigPool.plug(
|
||||
multiScan(
|
||||
{
|
||||
game: "simple",
|
||||
players: [] as string[],
|
||||
},
|
||||
DEFAULT_GAME_CONFIG,
|
||||
[
|
||||
playersPresent.filterBy(gameIsActive.thru(invert)),
|
||||
(prev, players) => ({
|
||||
@@ -282,11 +282,9 @@ export const liveTable = <
|
||||
}),
|
||||
],
|
||||
[
|
||||
clientGameConfigs
|
||||
// .filterBy(gameIsActive.thru(invert))
|
||||
.map(({ gameConfig }) => gameConfig),
|
||||
clientGameConfigs.filterBy(gameIsActive.thru(invert)),
|
||||
// @ts-ignore
|
||||
(prev, config) => ({ ...config, players: prev.players }),
|
||||
(prev, { gameConfig }) => ({ ...gameConfig, players: prev.players }),
|
||||
]
|
||||
) as unknown as Observable<GameConfig, any>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user