@genex-ai/multiplayer 0.4.0 → 0.4.1
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/README.md +9 -4
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -181,13 +181,18 @@ onKey('right', () => { me.x += 1; });
|
|
|
181
181
|
|
|
182
182
|
## Persistent worlds (optional)
|
|
183
183
|
|
|
184
|
-
The relay is in-memory — room state is gone when everyone leaves or the server restarts. To persist world state across restarts,
|
|
184
|
+
The relay is in-memory — room state is gone when everyone leaves or the server restarts. To persist world state across restarts, use `@genex-ai/embed-sdk`'s state helpers (they own auth tokens, guest handling, and write-conflict decoding):
|
|
185
185
|
|
|
186
186
|
```ts
|
|
187
|
+
import { loadWorldState, saveWorldState } from '@genex-ai/embed-sdk';
|
|
188
|
+
|
|
187
189
|
// load on boot
|
|
188
|
-
const { data } = await
|
|
190
|
+
const { data, version } = await loadWorldState();
|
|
189
191
|
initWorld(data ?? defaultWorld());
|
|
190
192
|
|
|
191
|
-
// save
|
|
192
|
-
|
|
193
|
+
// save (from ONE authority — the elected host — debounced, with ifVersion so
|
|
194
|
+
// races surface as { conflict: true } instead of silently clobbering)
|
|
195
|
+
if (room.isHost) await saveWorldState(world, { ifVersion: version });
|
|
193
196
|
```
|
|
197
|
+
|
|
198
|
+
The relay prefers signed-in players when electing the host (guests cannot write saves), so host-driven persistence works whenever any account is in the room. Per-player progression belongs in `savePlayerState()` (each player's own slot), never in the shared world blob.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genex-ai/multiplayer",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "The multiplayer client wrapper + shared room schema for genex.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,6 +20,12 @@
|
|
|
20
20
|
"files": [
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"check": "pnpm build && publint && attw --pack . --profile esm-only",
|
|
27
|
+
"prepack": "pnpm build && publint"
|
|
28
|
+
},
|
|
23
29
|
"publishConfig": {
|
|
24
30
|
"access": "public"
|
|
25
31
|
},
|
|
@@ -45,10 +51,5 @@
|
|
|
45
51
|
"url": "git+https://github.com/me-ai-org/genex-demo.git",
|
|
46
52
|
"directory": "packages/multiplayer"
|
|
47
53
|
},
|
|
48
|
-
"license": "MIT"
|
|
49
|
-
|
|
50
|
-
"build": "tsup",
|
|
51
|
-
"typecheck": "tsc --noEmit",
|
|
52
|
-
"check": "pnpm build && publint && attw --pack . --profile esm-only"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
54
|
+
"license": "MIT"
|
|
55
|
+
}
|