@hadoku/platform-wire 0.1.230 → 0.1.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/external-game-spec.d.ts +20 -0
- package/dist/external-game-spec.js +9 -0
- package/dist/game-type-spec.d.ts +67 -0
- package/dist/game-type-spec.js +35 -0
- package/package.json +11 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An external game as a room type: what the host decided about it (its id, whether it runs on the
|
|
3
|
+
* relay, its tier floor) together with what the game says about itself in its `manifest.json`
|
|
4
|
+
* (`external-game-manifest.ts`: its seat range and seat hold). The host's half
|
|
5
|
+
* never comes from the manifest, so a game cannot widen who may play it.
|
|
6
|
+
*
|
|
7
|
+
* The site builds every hosted external game's spec through this (`apps/server/src/plugins/external-games.ts`),
|
|
8
|
+
* and a test that needs a relay room type builds one the same way rather than re-typing the fields.
|
|
9
|
+
*/
|
|
10
|
+
import type { ExternalGameManifest } from './external-game-manifest.js';
|
|
11
|
+
import type { GameTypeSpec } from './game-type-spec.js';
|
|
12
|
+
import type { RoomFloorTier } from './tiers.js';
|
|
13
|
+
/** The host's own half of an external game. */
|
|
14
|
+
export interface HostedGame {
|
|
15
|
+
id: string;
|
|
16
|
+
/** `'relay'`: its match is cardtable's relay. Absent: the game plays on its own server, and the room has no match behind it. */
|
|
17
|
+
runtime?: 'relay';
|
|
18
|
+
minTier?: RoomFloorTier;
|
|
19
|
+
}
|
|
20
|
+
export declare function externalGameSpec(game: HostedGame, manifest: ExternalGameManifest): GameTypeSpec;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function externalGameSpec(game, manifest) {
|
|
2
|
+
return {
|
|
3
|
+
id: game.id,
|
|
4
|
+
...(game.runtime === undefined ? {} : { runtime: game.runtime }),
|
|
5
|
+
seatRejoinGraceMs: manifest.seatRejoinGraceMs,
|
|
6
|
+
...(game.minTier === undefined ? {} : { minTier: game.minTier }),
|
|
7
|
+
seats: manifest.seats,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GameTypeSpec — what a room needs to know about the game it plays, as data
|
|
3
|
+
* rather than a closed enum. A game that registers a spec can open a room
|
|
4
|
+
* and seat players through the same lobby mechanics Magic already uses,
|
|
5
|
+
* with no change to the lobby itself.
|
|
6
|
+
*
|
|
7
|
+
* Holds what something reads of a game type on its own, with no server
|
|
8
|
+
* instance or runtime service standing behind it: its seat range, the table
|
|
9
|
+
* it plays a match at, whether its match runs on the relay, how long a
|
|
10
|
+
* relay seat that drops is held, and its tier floor. A game's DEEPER rules
|
|
11
|
+
* (deck legality, a draft's own completion, a tournament's locked decks,
|
|
12
|
+
* who may seat a bot mid-round, when it may start, …) stay that game's own
|
|
13
|
+
* business: Magic's are `GameHooks` (`games/magic/server/src/room/pods.ts`,
|
|
14
|
+
* wired in for every Magic room through `Lobby.useGameHooks`), because they
|
|
15
|
+
* need a running server's `draftRooms`/gate to answer — this file never
|
|
16
|
+
* reaches for them.
|
|
17
|
+
*
|
|
18
|
+
* Imports nothing from any game, and registers nothing itself. Magic
|
|
19
|
+
* registers its own two game types from `@hadoku/shared`'s `room-modes.ts`;
|
|
20
|
+
* the site registers each hosted external game (`external-game-spec.ts`);
|
|
21
|
+
* a test registers its own (`game-type-spec.test.ts`).
|
|
22
|
+
*/
|
|
23
|
+
import type { RoomFloorTier } from './tiers.js';
|
|
24
|
+
export interface SeatRange {
|
|
25
|
+
/** Fewest seats this game ever plays with. */
|
|
26
|
+
min: number;
|
|
27
|
+
/** Most seats a ROOM of this type ever grows to — one meaning across every registered type. */
|
|
28
|
+
max: number;
|
|
29
|
+
}
|
|
30
|
+
export interface GameTypeSpec {
|
|
31
|
+
id: string;
|
|
32
|
+
seats: SeatRange;
|
|
33
|
+
/**
|
|
34
|
+
* A room plays in tables of this many seats; absent means the whole room
|
|
35
|
+
* is one table of `seats.max` (Magic's own two types each name 2 here,
|
|
36
|
+
* win or lose, however many sit in the room — a `draft` pod of 30 still
|
|
37
|
+
* plays its rounds two at a table).
|
|
38
|
+
*/
|
|
39
|
+
table?: {
|
|
40
|
+
seats: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* This game type's match runs on the relay runtime — the host has no engine of its own for it,
|
|
44
|
+
* only seats, watchers and a channel each seat's bundle speaks over
|
|
45
|
+
* (`packages/game-server/src/play/runtimes/relay.ts`'s `RelaySession`, `packages/game-ui/src/rooms/relay-channel.ts`
|
|
46
|
+
* on the client). Absent is a game with an engine or server of its own: no channel.
|
|
47
|
+
*/
|
|
48
|
+
runtime?: 'relay';
|
|
49
|
+
/**
|
|
50
|
+
* A relay match's seat that drops is held this long for its player to come back; past it the
|
|
51
|
+
* seat leaves the match (`runtimes/relay-match.ts`'s `seatRejoinGraceMs`). Absent or 0: a seat
|
|
52
|
+
* that drops is held for as long as the match lasts. Read only for `runtime: 'relay'`.
|
|
53
|
+
*/
|
|
54
|
+
seatRejoinGraceMs?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Every room of this type is restricted to this tier and above, whatever its creator chose
|
|
57
|
+
* (`packages/game-server/src/room/tier-floor.ts`): the server hides and refuses it below that, and
|
|
58
|
+
* Create room offers the type only to a viewer who holds it. Absent: the app's own floor.
|
|
59
|
+
*/
|
|
60
|
+
minTier?: RoomFloorTier;
|
|
61
|
+
}
|
|
62
|
+
/** Registers (or replaces) a game type's spec. Idempotent: the same id registered twice keeps the latest registration. */
|
|
63
|
+
export declare function registerGameType(spec: GameTypeSpec): void;
|
|
64
|
+
/** The registered spec for `id`, or `undefined` for a game type this process does not know. */
|
|
65
|
+
export declare function gameTypeSpec(id: string): GameTypeSpec | undefined;
|
|
66
|
+
/** Whether `id` is a game type this process knows how to play at all — the open replacement for the old closed `GAME_TYPES` union. */
|
|
67
|
+
export declare function isRegisteredGameType(id: string): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GameTypeSpec — what a room needs to know about the game it plays, as data
|
|
3
|
+
* rather than a closed enum. A game that registers a spec can open a room
|
|
4
|
+
* and seat players through the same lobby mechanics Magic already uses,
|
|
5
|
+
* with no change to the lobby itself.
|
|
6
|
+
*
|
|
7
|
+
* Holds what something reads of a game type on its own, with no server
|
|
8
|
+
* instance or runtime service standing behind it: its seat range, the table
|
|
9
|
+
* it plays a match at, whether its match runs on the relay, how long a
|
|
10
|
+
* relay seat that drops is held, and its tier floor. A game's DEEPER rules
|
|
11
|
+
* (deck legality, a draft's own completion, a tournament's locked decks,
|
|
12
|
+
* who may seat a bot mid-round, when it may start, …) stay that game's own
|
|
13
|
+
* business: Magic's are `GameHooks` (`games/magic/server/src/room/pods.ts`,
|
|
14
|
+
* wired in for every Magic room through `Lobby.useGameHooks`), because they
|
|
15
|
+
* need a running server's `draftRooms`/gate to answer — this file never
|
|
16
|
+
* reaches for them.
|
|
17
|
+
*
|
|
18
|
+
* Imports nothing from any game, and registers nothing itself. Magic
|
|
19
|
+
* registers its own two game types from `@hadoku/shared`'s `room-modes.ts`;
|
|
20
|
+
* the site registers each hosted external game (`external-game-spec.ts`);
|
|
21
|
+
* a test registers its own (`game-type-spec.test.ts`).
|
|
22
|
+
*/
|
|
23
|
+
const registry = new Map();
|
|
24
|
+
/** Registers (or replaces) a game type's spec. Idempotent: the same id registered twice keeps the latest registration. */
|
|
25
|
+
export function registerGameType(spec) {
|
|
26
|
+
registry.set(spec.id, spec);
|
|
27
|
+
}
|
|
28
|
+
/** The registered spec for `id`, or `undefined` for a game type this process does not know. */
|
|
29
|
+
export function gameTypeSpec(id) {
|
|
30
|
+
return registry.get(id);
|
|
31
|
+
}
|
|
32
|
+
/** Whether `id` is a game type this process knows how to play at all — the open replacement for the old closed `GAME_TYPES` union. */
|
|
33
|
+
export function isRegisteredGameType(id) {
|
|
34
|
+
return registry.has(id);
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/platform-wire",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.232",
|
|
4
|
+
"gitHead": "9a4bbf57b928ce97f231236cd229ab27320e3095",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"description": "The wire any game speaks: room ids, telemetry, presence, events and tables, the Discord relay, looks, room settings, the restart notice, secure random and a generic server envelope. Knows no game; a game's own part rides as a type parameter. MIT; imports only zod.",
|
|
7
|
+
"description": "The wire any game speaks: room ids, telemetry, presence, events and tables, the Discord relay, looks, room settings, the game-type registry, the restart notice, secure random and a generic server envelope. Knows no game; a game's own part rides as a type parameter. MIT; imports only zod.",
|
|
8
8
|
"exports": {
|
|
9
9
|
"./room-feed": {
|
|
10
10
|
"types": "./dist/room-feed.d.ts",
|
|
@@ -61,6 +61,14 @@
|
|
|
61
61
|
"./external-game-manifest": {
|
|
62
62
|
"types": "./dist/external-game-manifest.d.ts",
|
|
63
63
|
"import": "./dist/external-game-manifest.js"
|
|
64
|
+
},
|
|
65
|
+
"./external-game-spec": {
|
|
66
|
+
"types": "./dist/external-game-spec.d.ts",
|
|
67
|
+
"import": "./dist/external-game-spec.js"
|
|
68
|
+
},
|
|
69
|
+
"./game-type-spec": {
|
|
70
|
+
"types": "./dist/game-type-spec.d.ts",
|
|
71
|
+
"import": "./dist/game-type-spec.js"
|
|
64
72
|
}
|
|
65
73
|
},
|
|
66
74
|
"dependencies": {
|