@jgengine/ws 0.10.0 → 0.12.0

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.
@@ -0,0 +1,131 @@
1
+ <!-- GENERATED by scripts/gen-capability-index.ts — do not edit. Regenerate: bun run gen:capabilities -->
2
+
3
+ # jgengine — capability index
4
+
5
+ Reach for these before hand-rolling. Each row is *the thing you need* → *the primitive that already does it*.
6
+
7
+ ## authored-spawn — read spawn points and markers from the editor document
8
+
9
+ - `authoredSpawnPosition` (function) · `import { authoredSpawnPosition } from "@jgengine/shell/gameKit"`
10
+
11
+ ## authored-triggers — schema'd on/action vocabulary on volumes and markers with runtime dispatch
12
+
13
+ - `collectAuthoredTriggers` (function) · `import { collectAuthoredTriggers } from "@jgengine/shell/gameKit"`
14
+
15
+ ## collider-autofit — hitboxes and physical bodies fit each kind's rendered model bounds automatically — no hand-tuned sizes
16
+
17
+ - `GameContextModels` (interface) · `import { GameContextModels } from "@jgengine/core/runtime/gameContext"`
18
+
19
+ ## define-game — single public game-authoring path — compose systems, world, presentation, and authored scene in one definition
20
+
21
+ - `defineGame` (function) · `import { defineGame } from "@jgengine/shell/gameKit"`
22
+
23
+ ## define-system — composable game behavior — pure data + hooks the engine schedules; pass via `defineGame({ systems })`
24
+
25
+ - `defineSystem` (function) · `import { defineSystem } from "@jgengine/shell/gameKit"`
26
+
27
+ ## editor-catalogs — Export typed gameplay catalogs for in-editor tuning.
28
+
29
+ - `EditorCatalogDefinition` (interface) · `import { EditorCatalogDefinition } from "@jgengine/shell/gameKit"`
30
+
31
+ ## game-system — declare a composable capability with its own schedule and lifecycle
32
+
33
+ - `SystemDefinition` (interface) · `import { SystemDefinition } from "@jgengine/shell/gameKit"`
34
+
35
+ ## headless-runner — play a real game loop with no renderer — tick, feed input, read the world snapshot
36
+
37
+ - `HeadlessRunner` (interface) · `import { HeadlessRunner } from "@jgengine/core/runtime/headlessRunner"`
38
+
39
+ ## host-join-code-gate — membership-or-code gate for private hosted servers
40
+
41
+ - `canJoinPrivateServer` (function) · `import { canJoinPrivateServer } from "@jgengine/core/runtime/hostPolicy"`
42
+
43
+ ## host-listing-filter — exclude private sessions from public browse results
44
+
45
+ - `isListablePublicly` (function) · `import { isListablePublicly } from "@jgengine/core/runtime/hostPolicy"`
46
+
47
+ ## hud-canvas — the HUD root surface — design-resolution scaling plus live panel-placement editing (F2+C)
48
+
49
+ - `HudCanvas` (function) · `import { HudCanvas } from "@jgengine/shell/gameKit"`
50
+
51
+ ## hud-clock — in-game time-of-day readout bound to the sim clock
52
+
53
+ - `Clock` (function) · `import { Clock } from "@jgengine/shell/gameKit"`
54
+
55
+ ## hud-coins — currency counter widget bound to a currency id
56
+
57
+ - `Coins` (function) · `import { Coins } from "@jgengine/shell/gameKit"`
58
+
59
+ ## hud-hotbar — optional inventory hotbar building block — games own slot chrome
60
+
61
+ - `Hotbar` (function) · `import { Hotbar } from "@jgengine/shell/gameKit"`
62
+
63
+ ## hud-layout — persistent, live-editable HUD panel layout state for `HudCanvas`
64
+
65
+ - `useHudLayout` (function) · `import { useHudLayout } from "@jgengine/shell/gameKit"`
66
+
67
+ ## hud-panel — anchored HUD slot — drop any widget in a named, player-movable panel
68
+
69
+ - `HudPanel` (function) · `import { HudPanel } from "@jgengine/shell/gameKit"`
70
+
71
+ ## hud-stat-bar — optional stat-bound bar building block (health, mana, stamina) — prefer game-owned chrome
72
+
73
+ - `StatBar` (function) · `import { StatBar } from "@jgengine/shell/gameKit"`
74
+
75
+ ## loot-table — validate a loot table definition for use with the registry
76
+
77
+ - `lootTable` (function) · `import { lootTable } from "@jgengine/core/authoring"`
78
+
79
+ ## mount-game — mount a defined game in the browser — `<GameHost playable={game} editor={() => import("@jgengine/editor")} />`
80
+
81
+ - `GameHost` (function) · `import { GameHost } from "@jgengine/shell/gameKit"`
82
+
83
+ ## multiplayer-offline — explicit solo adapter — omit `multiplayer` instead; offline is the shell default
84
+
85
+ - `offline` (function) · `import { offline } from "@jgengine/shell/gameKit"`
86
+
87
+ ## multiplayer-p2p — serverless co-op over WebRTC — `multiplayer: p2p({ room })`
88
+
89
+ - `p2p` (function) · `import { p2p } from "@jgengine/core/runtime/adapter"`
90
+
91
+ ## multiplayer-ws — server-hosted shared world over WebSocket — `multiplayer: ws({ authority: "server" })`
92
+
93
+ - `ws` (function) · `import { ws } from "@jgengine/core/runtime/adapter"`
94
+
95
+ ## render-fallback-diagnostics — Enable/disable the dev-only placeholder-fallback probe.
96
+
97
+ - `armFallbackSeams` (function) · `import { armFallbackSeams } from "@jgengine/core/devtools/fallbackSeams"`
98
+ - `fallbackSeamsSnapshot` (function) · `import { fallbackSeamsSnapshot } from "@jgengine/core/devtools/fallbackSeams"`
99
+ - `reportFallbackSeam` (function) · `import { reportFallbackSeam } from "@jgengine/core/devtools/fallbackSeams"`
100
+
101
+ ## runtime-save — save/load the whole game world through a pluggable backend, autosave or save points
102
+
103
+ - `createRuntimeSave` (function) · `import { createRuntimeSave } from "@jgengine/core/runtime/runtimeSave"`
104
+
105
+ ## scene-ownership — audit a whole ownership manifest for boundary violations
106
+
107
+ - `auditManifest` (function) · `import { auditManifest } from "@jgengine/core/authoring"`
108
+ - `classifyOwnership` (function) · `import { classifyOwnership } from "@jgengine/core/authoring"`
109
+ - `collectOwnershipDiagnostics` (function) · `import { collectOwnershipDiagnostics } from "@jgengine/core/authoring"`
110
+ - `isSceneOwnershipManifest` (function) · `import { isSceneOwnershipManifest } from "@jgengine/core/authoring"`
111
+ - `ownershipKey` (function) · `import { ownershipKey } from "@jgengine/core/authoring"`
112
+
113
+ ## seeded-random — injected deterministic randomness for game logic — never `Math.random` in a simulation
114
+
115
+ - `seededRng` (function) · `import { seededRng } from "@jgengine/shell/gameKit"`
116
+
117
+ ## typed-keyed-store — a cast-free typed handle onto a per-owner keyed family of reactive game-store slots, replayable and host-authoritative
118
+
119
+ - `defineKeyedStore` (function) · `import { defineKeyedStore } from "@jgengine/shell/gameKit"`
120
+
121
+ ## typed-store — a cast-free typed handle onto one reactive game-store slot, replayable and host-authoritative
122
+
123
+ - `defineStore` (function) · `import { defineStore } from "@jgengine/shell/gameKit"`
124
+
125
+ ## world-convergence — derive environment coordinate content from the scene document
126
+
127
+ - `environmentContentFromDocument` (function) · `import { environmentContentFromDocument } from "@jgengine/shell/gameKit"`
128
+
129
+ ## world-environment — compose editor/preset-derived outdoor dressing — terrain, weather, water, structures — into a legacy environment feature
130
+
131
+ - `environment` (function) · `import { environment } from "@jgengine/shell/gameKit"`
@@ -0,0 +1,88 @@
1
+ # Recipe — minimal game (scaffold → authored scene → win)
2
+
3
+ **What this wires:** the default end-to-end path from nothing to a complete, genre-free
4
+ walk/interact/win game: a scaffold, one `defineGame` config off the happy-path kit, an
5
+ authored scene edited in the browser, one system, one store slot, an empty-canvas HUD,
6
+ and a win condition. Every new game starts here; add combat, multiplayer, or deeper
7
+ world features only after this loop plays.
8
+
9
+ ## 1. Scaffold
10
+
11
+ `npx jgengine create <name>` (inside the engine monorepo: `bun run new:game "<id-or-title>"`).
12
+ The file set is thin and already runs:
13
+
14
+ - `src/main.tsx` — mounts `GameHost` with `editor={() => import("@jgengine/editor")}`; the
15
+ host owns the F2+E / `?mode=editor` editor summon and the dev save endpoint.
16
+ - `src/game.config.ts` — the whole game definition (below).
17
+ - `src/editor.scene.json` + `src/editorLayers.ts` — the authored scene document, normalized
18
+ with `normalizeEditorLayers`. All placement lives here, never as coordinates in code.
19
+ - `src/loop.ts` and `src/game/ui/GameUI.tsx` — systems and HUD.
20
+
21
+ ## 2. Define the game — one import surface
22
+
23
+ ```ts
24
+ // game.config.ts — everything below comes from the kit; deeper paths are for outgrowing it.
25
+ import { defineGame } from "@jgengine/shell/gameKit";
26
+
27
+ import { editorLayers } from "./editorLayers";
28
+ import { GameUI } from "./game/ui/GameUI";
29
+ import { onNewPlayer, systems } from "./loop";
30
+
31
+ export const game = defineGame({
32
+ name: "my-game",
33
+ // Binding movement actions makes the shell drive the walk controller — the game walks day one.
34
+ input: { moveForward: ["KeyW"], moveBack: ["KeyS"], moveLeft: ["KeyA"], moveRight: ["KeyD"], interact: ["KeyE"] },
35
+ systems,
36
+ loop: { onNewPlayer },
37
+ GameUI,
38
+ editorLayers, // the authored scene auto-mounts; the player spawns at its player_spawn marker
39
+ });
40
+ // Solo game: omit `multiplayer` entirely — offline is the shell default.
41
+ ```
42
+
43
+ **World is optional and thin.** Omitting `world` is valid — a pure UI/rules game is not a
44
+ spatial place. When the game *is* a place, declare only substrate + laws with `world()` from
45
+ `@jgengine/core/world/place` (e.g. `{ id, ground: { mode: "flat", size: { x: Infinity, z: Infinity } }, physics: { gravity: -24 } }`,
46
+ or `mode: "board"` for 2D). Never seed, sky, or vegetation in `world` — the engine renders its
47
+ default sky until you author one in the editor, and foliage is editor scatter over the ground.
48
+
49
+
50
+ ```ts
51
+ // loop.ts — one store slot for run state, one system for the rules tick.
52
+ import { defineStore, defineSystem, authoredSpawnPosition, type GameContext } from "@jgengine/shell/gameKit";
53
+
54
+ import { editorLayers } from "./editorLayers";
55
+
56
+ export const run = defineStore("run", { collected: 0, won: false });
57
+
58
+ export const systems = [
59
+ defineSystem({
60
+ id: "rules",
61
+ tick: { type: "fixed" },
62
+ update(ctx: GameContext) {
63
+ // System-check win alternative: read/update `run` here (e.g. win at collected >= 3).
64
+ if (run.read(ctx).collected >= 3) run.update(ctx, (s) => ({ ...s, won: true }));
65
+ },
66
+ }),
67
+ ];
68
+
69
+ export function onNewPlayer(ctx: GameContext): void {
70
+ ctx.scene.entity.spawn("player", { id: ctx.player.userId, position: authoredSpawnPosition(editorLayers) ?? [0, 0, 0] });
71
+ }
72
+ ```
73
+
74
+ `GameUI` starts as an empty `HudCanvas` (`useHudLayout` + `HudCanvas` from the kit). That is
75
+ intentional: **every game owns its UI**. Write a short UI art direction, then build custom
76
+ panels for this pitch — do not ship stock drop-in widgets (`StatBar`, `Hotbar`, `Coins`, glass
77
+ frames) as the product face. Reach for engine pieces only as headless data, layout, or
78
+ interaction models under game-owned chrome (see `jgengine-ui`).
79
+
80
+ ## 3. Author, play, win
81
+
82
+ 1. `bun dev`, then F2+E opens the editor on `editor.scene.json` — move the spawn, place
83
+ props and trigger markers, Ctrl+S saves back to the document.
84
+ 2. The starter scene ships a goal marker with `{ on: "enter", action: "win" }` — walking
85
+ into it wins with zero game code. Author more rules the same way (triggers in the
86
+ editor), or read volumes yourself via the kit's `collectAuthoredTriggers(editorLayers)`.
87
+ 3. Prove it: `bun test` asserts the document (spawn, goal), and `jgengine-verify` covers
88
+ screenshot and gameplay evidence before any "it works" claim.
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: jgengine-multiplayer
3
+ description: Design authority, transport, replication, sessions, and host persistence.
4
+ ---
5
+
6
+ # JGengine multiplayer
7
+
8
+ ## Do you need this skill at all?
9
+
10
+ | Situation | Answer |
11
+ | --- | --- |
12
+ | Solo / single-player | Do not load this skill; omit `multiplayer` entirely — offline is the shell default |
13
+ | Couch / same-screen play | Still solo — one client, no adapter |
14
+ | Friends co-op, no server | `p2p({ room })` |
15
+ | Hosted authoritative shared world | `ws({ authority: "server" })` + `@jgengine/node` host |
16
+ | Presence/ghosts only | `wsPresence()` |
17
+ | Cloud persistence | Convex adapters |
18
+
19
+ ## Ownership
20
+
21
+ This skill owns network topology, authority, transports, sessions/presence, replication/projection, reconnect, hosted runners, and persistence adapters. Serializable game state and save semantics stay in `jgengine-gameplay`.
22
+
23
+ Use [capabilities.md](capabilities.md) for intent-to-import discovery, [api.md](api.md) for signatures, and [reference.md](reference.md) for transport, host, projection, persistence, and deployment recipes.
24
+
25
+ ## Canonical workflow
26
+
27
+ 1. Choose authority and trust boundaries before transport.
28
+ 2. Keep commands/intents separate from authoritative state transitions.
29
+ 3. Define serializable snapshots/deltas and viewer-specific projection.
30
+ 4. Select a transport pipe and host adapter without changing game protocol.
31
+ 5. Add reconnect, idempotency, persistence cadence, and failure behavior.
32
+ 6. Test multiple clients, visibility boundaries, and restore/rejoin behavior.
33
+
34
+ ## Design rules
35
+
36
+ - Protocol and state contracts live below concrete server/browser adapters.
37
+ - Replication is bounded by rooms, interest, change detection, or projection—not global broadcast/full serialization.
38
+ - Private state is filtered authoritatively; UI hiding is not security.
39
+ - Persistence adapters accept structural interfaces and keep backend dependencies out of core.
40
+ - Deterministic ids and commands make retries/reconnect safe.
41
+
42
+ ## Traps
43
+
44
+ - Local loopback success does not prove authority or privacy.
45
+ - Presence/chat/voice are session channels, not game-state ownership.
46
+ - Do not couple a primitive to WebSocket, Convex, Postgres, or one deployment topology.
47
+ - Reward allocation, inventory mutation, and progression policy remain gameplay/combat concerns.