@vibes.diy/prompts 14.3.249 → 14.3.250
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/generation-variety.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/llms/backend.js +1 -0
- package/llms/backend.js.map +1 -1
- package/llms/blockly.js +1 -0
- package/llms/blockly.js.map +1 -1
- package/llms/blockly.md +2 -3
- package/llms/board-games.js +9 -4
- package/llms/board-games.js.map +1 -1
- package/llms/board-games.md +3 -153
- package/llms/callai.js +1 -0
- package/llms/callai.js.map +1 -1
- package/llms/callai.md +1 -1
- package/llms/canvas-theme-colors.d.ts +2 -0
- package/llms/canvas-theme-colors.js +7 -0
- package/llms/canvas-theme-colors.js.map +1 -0
- package/llms/canvas-theme-colors.md +70 -0
- package/llms/image-gen.js +1 -0
- package/llms/image-gen.js.map +1 -1
- package/llms/image-gen.md +1 -1
- package/llms/index.d.ts +20 -1
- package/llms/index.js +55 -0
- package/llms/index.js.map +1 -1
- package/llms/keepsake.d.ts +2 -0
- package/llms/keepsake.js +9 -0
- package/llms/keepsake.js.map +1 -0
- package/llms/keepsake.md +74 -0
- package/llms/live-rooms.d.ts +2 -0
- package/llms/live-rooms.js +28 -0
- package/llms/live-rooms.js.map +1 -0
- package/llms/live-rooms.md +288 -0
- package/llms/media-capture.d.ts +2 -0
- package/llms/media-capture.js +27 -0
- package/llms/media-capture.js.map +1 -0
- package/llms/media-capture.md +190 -0
- package/llms/mic-capture.d.ts +2 -0
- package/llms/mic-capture.js +7 -0
- package/llms/mic-capture.js.map +1 -0
- package/llms/mic-capture.md +76 -0
- package/llms/needs.d.ts +12 -0
- package/llms/needs.js +71 -0
- package/llms/needs.js.map +1 -0
- package/llms/p5.js +1 -0
- package/llms/p5.js.map +1 -1
- package/llms/p5.md +15 -69
- package/llms/photo-input.d.ts +2 -0
- package/llms/photo-input.js +7 -0
- package/llms/photo-input.js.map +1 -0
- package/llms/photo-input.md +141 -0
- package/llms/physics.js +1 -0
- package/llms/physics.js.map +1 -1
- package/llms/physics.md +7 -16
- package/llms/reskin.js +3 -8
- package/llms/reskin.js.map +1 -1
- package/llms/reskin.md +4 -72
- package/llms/richtext.md +2 -0
- package/llms/social-post.js +1 -0
- package/llms/social-post.js.map +1 -1
- package/llms/social-post.md +22 -4
- package/llms/sound-core.d.ts +2 -0
- package/llms/sound-core.js +7 -0
- package/llms/sound-core.js.map +1 -0
- package/llms/sound-core.md +131 -0
- package/llms/strudel.js +2 -0
- package/llms/strudel.js.map +1 -1
- package/llms/strudel.md +24 -25
- package/llms/surface-board.d.ts +2 -0
- package/llms/surface-board.js +8 -0
- package/llms/surface-board.js.map +1 -0
- package/llms/surface-board.md +140 -0
- package/llms/surface-play-area.d.ts +2 -0
- package/llms/surface-play-area.js +8 -0
- package/llms/surface-play-area.js.map +1 -0
- package/llms/surface-play-area.md +51 -0
- package/llms/surface-presence.d.ts +2 -0
- package/llms/surface-presence.js +9 -0
- package/llms/surface-presence.js.map +1 -0
- package/llms/surface-presence.md +118 -0
- package/llms/three-js.js +1 -1
- package/llms/three-js.js.map +1 -1
- package/llms/three-js.md +52 -18
- package/llms/touch-games.js +11 -11
- package/llms/touch-games.js.map +1 -1
- package/llms/touch-games.md +59 -354
- package/llms/types.d.ts +5 -0
- package/llms/ui-chat.js +2 -1
- package/llms/ui-chat.js.map +1 -1
- package/llms/ui-chat.md +25 -14
- package/llms/use-vibe.js +1 -0
- package/llms/use-vibe.js.map +1 -1
- package/llms/use-viewer.js +1 -0
- package/llms/use-viewer.js.map +1 -1
- package/llms/voxel.js +1 -0
- package/llms/voxel.js.map +1 -1
- package/llms/voxel.md +33 -109
- package/llms/web-audio.js +4 -21
- package/llms/web-audio.js.map +1 -1
- package/llms/web-audio.md +19 -951
- package/llms/web-music.d.ts +2 -0
- package/llms/web-music.js +8 -0
- package/llms/web-music.js.map +1 -0
- package/llms/web-music.md +895 -0
- package/llms/world-controls.d.ts +2 -0
- package/llms/world-controls.js +14 -0
- package/llms/world-controls.js.map +1 -0
- package/llms/world-controls.md +262 -0
- package/llms/worlds.js +2 -1
- package/llms/worlds.js.map +1 -1
- package/llms/worlds.md +5 -14
- package/package.json +5 -5
- package/prompts.js +5 -19
- package/prompts.js.map +1 -1
package/llms/ui-chat.md
CHANGED
|
@@ -15,6 +15,8 @@ import { useFireproof } from "use-fireproof";
|
|
|
15
15
|
import { useViewer, useVibe } from "use-vibes";
|
|
16
16
|
import { Button, Card, Empty, Field, Heading, Icon, IconButton, Input, Row, RowCard, Skeleton, Stack, Text } from "@vibes.diy/ui";
|
|
17
17
|
import { ScrollArea } from "@vibes.diy/ui/interactive";
|
|
18
|
+
import { Presence, newRoomId, roomLink, useHere, useRoomId } from "./lib/room.js";
|
|
19
|
+
import { HereBar } from "./lib/here.jsx";
|
|
18
20
|
|
|
19
21
|
const when = (ms) => new Date(ms).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });
|
|
20
22
|
|
|
@@ -24,14 +26,16 @@ function Author({ handle }) {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
function Thread({ room, onBack }) {
|
|
27
|
-
const { database, useLiveQuery } = useFireproof("chat");
|
|
29
|
+
const { database, useDocument, useLiveQuery } = useFireproof("chat");
|
|
28
30
|
const { can, me } = useVibe("chat");
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
+
// One query on the room returns its messages and the presence of whoever has it open.
|
|
32
|
+
const { docs } = useLiveQuery("roomId", { key: room.roomId });
|
|
33
|
+
const messages = docs.filter((d) => d.type === "message").sort((a, b) => a.createdAt - b.createdAt);
|
|
34
|
+
const here = useHere(room.roomId, useLiveQuery, me?.userHandle);
|
|
31
35
|
const [draft, setDraft] = useState("");
|
|
32
36
|
const endRef = useRef(null);
|
|
33
37
|
// The verdict for the doc send writes, carrying the same fields it stamps.
|
|
34
|
-
const canSend = can.create({ type: "message", roomId: room.
|
|
38
|
+
const canSend = can.create({ type: "message", roomId: room.roomId, authorHandle: me?.userHandle });
|
|
35
39
|
|
|
36
40
|
useEffect(() => {
|
|
37
41
|
endRef.current?.scrollIntoView({ block: "nearest" });
|
|
@@ -43,16 +47,18 @@ function Thread({ room, onBack }) {
|
|
|
43
47
|
if (text === "") return;
|
|
44
48
|
// The field is ready for the next one at once; a save that does not land hands the words back.
|
|
45
49
|
setDraft("");
|
|
46
|
-
const { ok } = await database.put({ type: "message", roomId: room.
|
|
50
|
+
const { ok } = await database.put({ type: "message", roomId: room.roomId, text, authorHandle: me?.userHandle, createdAt: Date.now() });
|
|
47
51
|
if (!ok) setDraft((now) => now || text);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
return (
|
|
51
55
|
<Stack gap={4}>
|
|
56
|
+
{me?.userHandle && <Presence key={`${room.roomId}:${me.userHandle}`} roomId={room.roomId} handle={me.userHandle} useDocument={useDocument} />}
|
|
52
57
|
<Row gap={2} wrap={false}>
|
|
53
58
|
<IconButton size="sm" onClick={onBack} label="Back to rooms" icon={<Icon name="prev" size="sm" />} />
|
|
54
59
|
<Heading level={1}>{room.name}</Heading>
|
|
55
60
|
</Row>
|
|
61
|
+
<HereBar people={here} onInvite={() => navigator.clipboard.writeText(roomLink(room.roomId))} />
|
|
56
62
|
|
|
57
63
|
<Card>
|
|
58
64
|
<Stack gap={4}>
|
|
@@ -114,12 +120,15 @@ export default function App() {
|
|
|
114
120
|
const { docs: messages } = useLiveQuery("type", { key: "message" });
|
|
115
121
|
const rooms = [...roomDocs].sort((a, b) => a.createdAt - b.createdAt);
|
|
116
122
|
|
|
117
|
-
const [activeId,
|
|
123
|
+
const [activeId, go] = useRoomId(); // the open room is in the link, so a shared link opens it
|
|
118
124
|
const [name, setName] = useState("");
|
|
119
125
|
const [error, setError] = useState(undefined);
|
|
120
|
-
const active = rooms.find((r) => r.
|
|
121
|
-
// The verdict for the doc startRoom writes, carrying the same fields it stamps
|
|
122
|
-
|
|
126
|
+
const active = rooms.find((r) => r.roomId === activeId);
|
|
127
|
+
// The verdict for the doc startRoom writes, carrying the same fields it stamps; the next room's
|
|
128
|
+
// id is drawn up front so the verdict reads that very document.
|
|
129
|
+
const [nextId, setNextId] = useState(newRoomId);
|
|
130
|
+
const roomDraft = { _id: `room:${nextId}`, type: "room", roomId: nextId, hostHandle: me?.userHandle };
|
|
131
|
+
const canStart = can.create(roomDraft);
|
|
123
132
|
|
|
124
133
|
async function startRoom(e) {
|
|
125
134
|
e.preventDefault();
|
|
@@ -130,8 +139,9 @@ export default function App() {
|
|
|
130
139
|
}
|
|
131
140
|
setError(undefined);
|
|
132
141
|
setName(""); // ready for the next room name at once
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
setNextId(newRoomId());
|
|
143
|
+
const { ok } = await database.put({ ...roomDraft, name: text, createdAt: Date.now() });
|
|
144
|
+
if (ok) go(roomDraft.roomId);
|
|
135
145
|
else setName((now) => now || text);
|
|
136
146
|
}
|
|
137
147
|
|
|
@@ -144,7 +154,7 @@ export default function App() {
|
|
|
144
154
|
return (
|
|
145
155
|
<main className="mx-auto max-w-2xl px-4 py-8">
|
|
146
156
|
{active ? (
|
|
147
|
-
<Thread room={active} onBack={() =>
|
|
157
|
+
<Thread room={active} onBack={() => go(null)} />
|
|
148
158
|
) : (
|
|
149
159
|
<Stack gap={5}>
|
|
150
160
|
<Stack gap={1}>
|
|
@@ -159,11 +169,11 @@ export default function App() {
|
|
|
159
169
|
) : (
|
|
160
170
|
<Stack gap={2}>
|
|
161
171
|
{rooms.map((room) => (
|
|
162
|
-
<RowCard key={room._id} onClick={() =>
|
|
172
|
+
<RowCard key={room._id} onClick={() => go(room.roomId)}>
|
|
163
173
|
<Stack gap={1}>
|
|
164
174
|
<Text truncate>{room.name}</Text>
|
|
165
175
|
<Text size="sm" muted truncate>
|
|
166
|
-
{latest(room.
|
|
176
|
+
{latest(room.roomId)}
|
|
167
177
|
</Text>
|
|
168
178
|
</Stack>
|
|
169
179
|
</RowCard>
|
|
@@ -214,6 +224,7 @@ export default function App() {
|
|
|
214
224
|
## Adapting
|
|
215
225
|
|
|
216
226
|
- Rename rooms and messages to the app's own nouns (`trip`, `song`, `channel`) in the `type` key, the headings and the copy; keep one document per message, linked to its room by `roomId`.
|
|
227
|
+
- Who has a room open is the live-rooms presence above: the thread mounts the visitor's presence draft and shows the faces, the count and the Invite in its header, and the open room rides the link as `#room=`, so an invite opens straight into the thread. A "typing" line is a `typing: true` field in the same presence state, set while the composer has text and cleared on send.
|
|
217
228
|
- An unread marker is per person, not per message: keep it as a `lastRead:<room>:<person>` document with a time, and show the count as a `Badge tone="info"`.
|
|
218
229
|
- A side-by-side list and thread on a wide screen is a `Grid cols="sidebar"` with the thread first; keep the back button for phones.
|
|
219
230
|
- Authors are always `ViewerTag` with the stored handle; the visitor's own messages are told apart by `me.userHandle`, never by a stored name.
|
package/llms/use-vibe.js
CHANGED
package/llms/use-vibe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-vibe.js","sourceRoot":"","sources":["../../jsr/llms/use-vibe.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAc;IACtC,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,mBAAmB;IAC1B,WAAW,EAAE,kEAAkE;IAC/E,YAAY,EAAE,WAAW;IACzB,UAAU,EAAE,SAAS;CACtB,CAAC"}
|
|
1
|
+
{"version":3,"file":"use-vibe.js","sourceRoot":"","sources":["../../jsr/llms/use-vibe.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAc;IACtC,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,mBAAmB;IAC1B,WAAW,EAAE,kEAAkE;IAC/E,SAAS,EAAE,QAAQ;IACnB,YAAY,EAAE,WAAW;IACzB,UAAU,EAAE,SAAS;CACtB,CAAC"}
|
package/llms/use-viewer.js
CHANGED
package/llms/use-viewer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-viewer.js","sourceRoot":"","sources":["../../jsr/llms/use-viewer.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAc;IACxC,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE,iBAAiB;IACxB,WAAW,EAAE,wDAAwD;IACrE,YAAY,EAAE,WAAW;IACzB,UAAU,EAAE,WAAW;CACxB,CAAC"}
|
|
1
|
+
{"version":3,"file":"use-viewer.js","sourceRoot":"","sources":["../../jsr/llms/use-viewer.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAc;IACxC,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE,iBAAiB;IACxB,WAAW,EAAE,wDAAwD;IACrE,SAAS,EAAE,QAAQ;IACnB,YAAY,EAAE,WAAW;IACzB,UAAU,EAAE,WAAW;CACxB,CAAC"}
|
package/llms/voxel.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const voxelConfig = {
|
|
2
2
|
name: "voxel",
|
|
3
|
+
needs: ["world-controls", "live-rooms"],
|
|
3
4
|
label: "Voxel",
|
|
4
5
|
description: "Any voxel or block world — Minecraft-style, an island, a city, a sandbox — walked, flown or built in. " +
|
|
5
6
|
"Build a Minecraft-style first-person voxel sandbox with Three.js: chunked block world, " +
|
package/llms/voxel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"voxel.js","sourceRoot":"","sources":["../../jsr/llms/voxel.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAc;IACpC,IAAI,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"voxel.js","sourceRoot":"","sources":["../../jsr/llms/voxel.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAc;IACpC,IAAI,EAAE,OAAO;IAEb,KAAK,EAAE,CAAC,gBAAgB,EAAE,YAAY,CAAC;IACvC,KAAK,EAAE,OAAO;IACd,WAAW,EACT,wGAAwG;QACtG,yFAAyF;QAC3F,6FAA6F;QAC7F,4FAA4F;QAC5F,0HAA0H;QAC1H,uFAAuF;QACvF,gGAAgG;QAChG,2FAA2F;QAC3F,yFAAyF;QACzF,6CAA6C;QAC7C,2FAA2F;QAC3F,+JAA+J;IACjK,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,CAAC;IAG/E,YAAY,EAAE,OAAO;IACrB,UAAU,EAAE,OAAO;IACnB,UAAU,EAAE,WAAW;CACxB,CAAC"}
|
package/llms/voxel.md
CHANGED
|
@@ -140,7 +140,7 @@ colors in one named table, shared by material swatches and HUD controls. Add
|
|
|
140
140
|
game-specific materials to that table; preserve these colors for matching
|
|
141
141
|
materials. The surrounding app retains its supplied theme's surfaces and text, and the world
|
|
142
142
|
around the blocks wears the look too: the sky, fog and light come from the theme tokens through
|
|
143
|
-
`readLook` (the
|
|
143
|
+
`readLook` (the play-area surface and canvas theme colours above), and the title, hotbar and
|
|
144
144
|
panels are kit components on the look's surfaces. This table colours the blocks and the accent.
|
|
145
145
|
|
|
146
146
|
```js
|
|
@@ -409,8 +409,8 @@ when the engine unmounts.
|
|
|
409
409
|
|
|
410
410
|
Controls come from `useWorldControls`; voxel adds what the acts mean: a tap builds on the targeted block, a hold breaks it, the block chip and hotbar pick the material, G toggles flying, and a flick down sinks while flying.
|
|
411
411
|
|
|
412
|
-
The hook, its usage example and its desktop twin
|
|
413
|
-
|
|
412
|
+
The hook, its usage example and its desktop twin are in the world controls above. In a block
|
|
413
|
+
world the hook's callbacks become:
|
|
414
414
|
|
|
415
415
|
- `onTap(x, y)` builds and `onHold(x, y)` breaks, through the DDA raycast below — from that point
|
|
416
416
|
(client coordinates) on a phone, from screen centre under the crosshair while the mouse is locked.
|
|
@@ -423,7 +423,7 @@ Pointer lock is the number-one confusion in browser voxel games: players click
|
|
|
423
423
|
and nothing happens, or they don't know the mouse controls the camera at all.
|
|
424
424
|
**Always** show an explicit "Click to play" overlay with the control legend,
|
|
425
425
|
and only request lock from that click: its button calls the hook's `requestLock()`, and the hook's
|
|
426
|
-
`locked` brings the overlay back when the player presses Esc. The overlay JSX is in
|
|
426
|
+
`locked` brings the overlay back when the player presses Esc. The overlay JSX is in the world controls;
|
|
427
427
|
the voxel legend reads "WASD move · Mouse look · Shift sprint · Space jump · Click build ·
|
|
428
428
|
Right-click break · G fly · V views · 1–9 blocks".
|
|
429
429
|
|
|
@@ -432,7 +432,7 @@ Right-click break · G fly · V views · 1–9 blocks".
|
|
|
432
432
|
Include a view switcher between first-person and third-person so players can see their own avatar.
|
|
433
433
|
The 🎥 camera button outside the menu cycles **Free cam → First person → Shoulder view**, and the V key cycles them the same way on a keyboard, named in the control legend as `V views`.
|
|
434
434
|
Toggle once per press, ignoring key repeat. On a phone the world opens in Free cam, an overview that frames the island;
|
|
435
|
-
back its radius off on a narrow screen as
|
|
435
|
+
back its radius off on a narrow screen as the world controls show.
|
|
436
436
|
Render a simple blocky local-player avatar in third-person, following
|
|
437
437
|
the player's position and heading, and hide it in first-person so it does not
|
|
438
438
|
cover the camera. Keep the same player physics and position when switching:
|
|
@@ -465,7 +465,7 @@ belongs to the platform. A smaller boxed world is only for when the person asks
|
|
|
465
465
|
|
|
466
466
|
### No text selection on the game surface
|
|
467
467
|
|
|
468
|
-
The phone controls themselves come from `useWorldControls`, taught in the
|
|
468
|
+
The phone controls themselves come from `useWorldControls`, taught in the world controls above.
|
|
469
469
|
|
|
470
470
|
Two things separate "works on my laptop" from "works", and both are easy to
|
|
471
471
|
forget because the desktop build hides them:
|
|
@@ -512,12 +512,12 @@ when a block breaks — cheap, and it makes mining feel real.
|
|
|
512
512
|
|
|
513
513
|
## Multiplayer: live block edits over Fireproof
|
|
514
514
|
|
|
515
|
-
|
|
515
|
+
A shared world is a live room: the room in the URL, presence, who is here and
|
|
516
|
+
the room's access branches come from the live-rooms doc above, with the world
|
|
517
|
+
as the room (`roomId` is the `worldId`). This section is what a block world
|
|
518
|
+
adds on top.
|
|
516
519
|
|
|
517
|
-
|
|
518
|
-
merged snapshot** to authorized connected peers when it has an `_id`.
|
|
519
|
-
It is a shallow merge, not a durable field-patch API; `save()` persists through
|
|
520
|
-
`database.put()`. The app-facing database has no `database.merge()` method.
|
|
520
|
+
### Keep saved edits separate from temporary movement
|
|
521
521
|
|
|
522
522
|
Use small, separate documents for different lifetimes:
|
|
523
523
|
|
|
@@ -529,100 +529,35 @@ Use small, separate documents for different lifetimes:
|
|
|
529
529
|
stays gone after reload. Use the consistency model below for concurrent edits.
|
|
530
530
|
- **Inventory, health, and resume checkpoints:** persist per world and player,
|
|
531
531
|
with change detection and an explicit commit/checkpoint cadence. Commit
|
|
532
|
-
important collected items when the action completes;
|
|
533
|
-
|
|
532
|
+
important collected items when the action completes; the pose heartbeat
|
|
533
|
+
carries only pose. `save()` still creates a durable write. To commit in
|
|
534
534
|
the same callback as a draft update, pass the complete next snapshot to
|
|
535
535
|
`save(snapshot)`; a bare `save()` can read the previous render's draft.
|
|
536
536
|
A nested object replaces that entire field rather than merging individual
|
|
537
537
|
coordinates.
|
|
538
|
-
- **Live pose/aim:**
|
|
539
|
-
`
|
|
540
|
-
|
|
541
|
-
|
|
538
|
+
- **Live pose/aim:** the player's presence draft. Point the presence state ref
|
|
539
|
+
at the engine's latest `{ x, y, z, theta }` snapshot (`poseRef`), which
|
|
540
|
+
animation updates without React state or database writes; the heartbeat
|
|
541
|
+
sends it, and peers draw each fresh pose as an avatar in the scene. It is not
|
|
542
|
+
a durable resume position or an offline edit log.
|
|
542
543
|
- **Activity feed:** use a bounded/coalesced recent-action summary unless a
|
|
543
544
|
durable audit trail is required. Showing only eight results does not bound
|
|
544
545
|
storage when every block placement appends a new activity document.
|
|
545
546
|
|
|
546
547
|
Blocktopia's per-coordinate writes already avoid saving an entire world for
|
|
547
|
-
each block
|
|
548
|
-
|
|
548
|
+
each block; its recurring presence write is the one to move onto the presence
|
|
549
|
+
draft. Block Craft's whole-world snapshot every two seconds combines edits,
|
|
549
550
|
inventory, vitals, and pose; split those lifetimes before adopting its survival
|
|
550
551
|
systems. Fewer durable commits and smaller documents reduce persistence work;
|
|
551
552
|
measure wire bytes and delivery latency separately before claiming faster sync.
|
|
552
553
|
|
|
553
|
-
For a world whose membership is already established, mount this component
|
|
554
|
-
with `key={worldId + ":" + handle}`. Its hook stays at component scope and
|
|
555
|
-
starts a new draft when the player changes worlds. `poseRef` is the engine's
|
|
556
|
-
latest `{ x, y, z, theta }` snapshot; animation updates that ref without React
|
|
557
|
-
state or database writes:
|
|
558
|
-
|
|
559
|
-
```jsx
|
|
560
|
-
function PlayerPresence({ worldId, handle, poseRef, useDocument }) {
|
|
561
|
-
const { merge } = useDocument({
|
|
562
|
-
_id: `presence:${worldId}:${handle}`, type: "presence",
|
|
563
|
-
worldId, userHandle: handle,
|
|
564
|
-
});
|
|
565
|
-
React.useEffect(() => {
|
|
566
|
-
let previous = "";
|
|
567
|
-
let lastSent = 0;
|
|
568
|
-
const timer = setInterval(() => {
|
|
569
|
-
const p = poseRef.current;
|
|
570
|
-
if (!p) return;
|
|
571
|
-
const pose = { x: p.x, y: p.y, z: p.z, theta: p.theta };
|
|
572
|
-
const stamp = JSON.stringify(pose);
|
|
573
|
-
const now = Date.now();
|
|
574
|
-
if (stamp === previous && now - lastSent < 5000) return;
|
|
575
|
-
merge({ ...pose, at: now });
|
|
576
|
-
previous = stamp;
|
|
577
|
-
lastSent = now;
|
|
578
|
-
}, 350);
|
|
579
|
-
return () => clearInterval(timer);
|
|
580
|
-
}, [merge, poseRef]);
|
|
581
|
-
return null;
|
|
582
|
-
}
|
|
583
|
-
```
|
|
584
|
-
|
|
585
|
-
Peers can receive this never-saved row through a live query on `worldId`;
|
|
586
|
-
the temporary overlay supplies the index fields. The access function must
|
|
587
|
-
validate the sender's identity, bind `_id` to its world/player, validate finite
|
|
588
|
-
pose coordinates, and require world membership before returning the existing
|
|
589
|
-
world channel. Persist the world/invitation that grants that membership first:
|
|
590
|
-
a presence broadcast does not create grants. Use this matching branch in the
|
|
591
|
-
multi-world access function (the single-world example later uses different IDs
|
|
592
|
-
and `authorHandle`):
|
|
593
|
-
|
|
594
|
-
```js
|
|
595
|
-
if (doc.type === "presence") {
|
|
596
|
-
if (!user || doc.userHandle !== user.userHandle) throw { forbidden: "not you" };
|
|
597
|
-
if (typeof doc.worldId !== "string" || !doc.worldId) throw { forbidden: "world required" };
|
|
598
|
-
if (doc._id !== `presence:${doc.worldId}:${user.userHandle}`) throw { forbidden: "presence ID" };
|
|
599
|
-
if (![doc.x, doc.y, doc.z, doc.theta, doc.at].every(Number.isFinite)) throw { forbidden: "invalid pose" };
|
|
600
|
-
const channel = `world:${doc.worldId}`;
|
|
601
|
-
ctx.requireAccess(channel);
|
|
602
|
-
return { channels: [channel] };
|
|
603
|
-
}
|
|
604
|
-
```
|
|
605
|
-
|
|
606
|
-
A hidden or disconnected tab may miss its heartbeat, so peers expire it rather
|
|
607
|
-
than treating it as saved state. Use receiver arrival time for update freshness.
|
|
608
|
-
Rely on disconnect/expiry for departure:
|
|
609
|
-
an unmount-time `merge()` can be canceled before broadcast. This example uses
|
|
610
|
-
one presence ID per handle; independent same-handle tabs need a session suffix
|
|
611
|
-
and access rules that validate that ID. During migration from saved presence,
|
|
612
|
-
admit old durable rows only if their timestamps are plausibly fresh; their
|
|
613
|
-
first query arrival or reappearance after overlay expiry is not a heartbeat.
|
|
614
|
-
Alternatively, use a distinct ephemeral namespace with matching access rules.
|
|
615
|
-
|
|
616
554
|
### Choose the durable edit conflict model
|
|
617
555
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
timestamp.** That last fact is the one that bites: a client-side fold can order
|
|
624
|
-
what a session *observes*, but it cannot change which revision the server keeps,
|
|
625
|
-
so **there is no free lunch here.** Pick a model with eyes open:
|
|
556
|
+
Many players editing the same coordinates is the case the live-rooms substrate
|
|
557
|
+
rules do not settle on their own: deliveries are unordered and the server keeps
|
|
558
|
+
the last ARRIVAL per `_id`, so a client-side fold can order what a session
|
|
559
|
+
*observes*, but it cannot change which revision the server keeps, so **there is
|
|
560
|
+
no free lunch here.** Pick a model with eyes open:
|
|
626
561
|
|
|
627
562
|
- **Model A — one doc per coordinate (bounded, eventually-consistent-per-session).**
|
|
628
563
|
Deterministic `_id: block:<key>`, so each edit *overwrites* the same doc and the
|
|
@@ -905,15 +840,12 @@ Ordering rules, each load-bearing (both models):
|
|
|
905
840
|
derived map; if you only apply the keys that are present, everything mined
|
|
906
841
|
before the reset stays rendered. Diff against the previous key set and
|
|
907
842
|
apply `null` (revert-to-terrain) for keys that vanished.
|
|
908
|
-
- **
|
|
909
|
-
|
|
910
|
-
so key-presence clears the overlay against stale data — the same refill bug
|
|
911
|
-
through a different door. `if (blocks.get(k) === pending.get(k)) pending.delete(k)`.
|
|
843
|
+
- **An optimistic overlay clears on agreement** (the live-rooms rule), keyed by
|
|
844
|
+
coordinate: `if (blocks.get(k) === pending.get(k)) pending.delete(k)`.
|
|
912
845
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
callbacks or refs, never the closure).
|
|
846
|
+
Read live handles/permissions through refs (a value captured in the engine
|
|
847
|
+
closure at load time goes stale — bind live state via `state.on*` callbacks or
|
|
848
|
+
refs, never the closure).
|
|
917
849
|
|
|
918
850
|
The `access.js` keeps the shared world **open** — block docs channel publicly
|
|
919
851
|
with anonymous writers allowed — while survival doc types each get a branch
|
|
@@ -950,14 +882,7 @@ export default function (doc, oldDoc, user, ctx) {
|
|
|
950
882
|
if (oldDoc && oldDoc.authorHandle !== user.userHandle) throw { forbidden: "not your inventory" };
|
|
951
883
|
return { channels: [WORLD], grant: { public: [WORLD] } };
|
|
952
884
|
}
|
|
953
|
-
|
|
954
|
-
// Roster heartbeat — same self-only rule and _id binding, create AND update.
|
|
955
|
-
if (!user) throw { forbidden: "sign in" };
|
|
956
|
-
if (doc._id !== `presence:${user.userHandle}`) throw { forbidden: "not you" };
|
|
957
|
-
if (doc.authorHandle !== user.userHandle) throw { forbidden: "not you" };
|
|
958
|
-
if (oldDoc && oldDoc.authorHandle !== user.userHandle) throw { forbidden: "not you" };
|
|
959
|
-
return { channels: [WORLD], grant: { public: [WORLD] } };
|
|
960
|
-
}
|
|
885
|
+
// The room and presence branches are the live-rooms ones, with the world's channel as the room's.
|
|
961
886
|
if (doc.type === "worldReset") {
|
|
962
887
|
// Singleton at a FIXED _id, owner only — destructive for the whole group.
|
|
963
888
|
// Clients ignore voxel edits older than doc.at, so "reset" deletes
|
|
@@ -980,9 +905,8 @@ The pattern generalizes: **self-owned docs bind their `_id` to the writer's
|
|
|
980
905
|
handle and check ownership on both create and update**; group-destructive
|
|
981
906
|
singletons gate on the owner role.
|
|
982
907
|
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
`can.create(...)` so a slow or stale rule binding can never freeze the game.
|
|
908
|
+
`applyBlock` always runs locally, whatever the write verdict says; only the
|
|
909
|
+
sync waits on `can.create(...)`.
|
|
986
910
|
|
|
987
911
|
## The survival layer: data tables first, systems second
|
|
988
912
|
|
package/llms/web-audio.js
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
export const webAudioConfig = {
|
|
2
2
|
name: "web-audio",
|
|
3
|
+
needs: ["sound-core"],
|
|
3
4
|
label: "Web Audio API",
|
|
4
|
-
description: "Web Audio fundamentals
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"sound",
|
|
8
|
-
"sounds",
|
|
9
|
-
"music",
|
|
10
|
-
"synth",
|
|
11
|
-
"synthesizer",
|
|
12
|
-
"oscillator",
|
|
13
|
-
"metronome",
|
|
14
|
-
"drum machine",
|
|
15
|
-
"drum",
|
|
16
|
-
"drums",
|
|
17
|
-
"midi",
|
|
18
|
-
"melody",
|
|
19
|
-
"web audio",
|
|
20
|
-
"samples",
|
|
21
|
-
"sampled",
|
|
22
|
-
"sampled sounds",
|
|
23
|
-
"audio engine",
|
|
24
|
-
],
|
|
5
|
+
description: "Web Audio fundamentals: the AudioContext from the gesture unlock, oscillators, decoded-file playback, gain and filters, and heavyweight engines (Tone.js and the like) imported at runtime from a pinned URL in a memoized loader, with one Stop that silences every voice. A music toy (a drum machine, a synth, a sequencer, a metronome) names \"web-music\", which brings this with it.",
|
|
6
|
+
teaches: ["AudioContext", "WebAudio", "Web Audio"],
|
|
7
|
+
cues: ["audio", "sound", "sounds", "oscillator", "web audio", "samples", "sampled", "sampled sounds", "audio engine"],
|
|
25
8
|
};
|
|
26
9
|
//# sourceMappingURL=web-audio.js.map
|
package/llms/web-audio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-audio.js","sourceRoot":"","sources":["../../jsr/llms/web-audio.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web-audio.js","sourceRoot":"","sources":["../../jsr/llms/web-audio.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,cAAc,GAAc;IACvC,IAAI,EAAE,WAAW;IAEjB,KAAK,EAAE,CAAC,YAAY,CAAC;IACrB,KAAK,EAAE,eAAe;IACtB,WAAW,EACT,6XAA6X;IAE/X,OAAO,EAAE,CAAC,cAAc,EAAE,UAAU,EAAE,WAAW,CAAC;IAClD,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,CAAC;CACtH,CAAC"}
|