create-dreamer-app 1.0.6 → 1.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-dreamer-app",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "The scaffolding application for using Disco Dreamer.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -301,7 +301,7 @@ function PhysicsExample() {
301
301
 
302
302
  ### `gameRef<RigidBody2DSnapshot>(key)`
303
303
 
304
- Reads a body's live stored state. Pass the returned `key` to the body's `ref`, and check `ready` before calling `snapshot()`:
304
+ Reads and updates a body's live stored state. Pass the returned `key` to the body's `ref`, and check `ready` before calling `snapshot()`:
305
305
 
306
306
  ```tsx
307
307
  function TrackedBody() {
@@ -319,7 +319,31 @@ function TrackedBody() {
319
319
  }
320
320
  ```
321
321
 
322
- Import `RigidBody2DSnapshot` with `import type`. The ref normally becomes ready on a later frame after the body attaches. A snapshot contains local position, velocity, and mass; it is a read interface, not a setter.
322
+ Import `RigidBody2DSnapshot` with `import type`. The ref normally becomes ready on a later frame after the body attaches. A snapshot contains local `position`, `velocity`, `mass`, and an `update` method:
323
+
324
+ ```ts
325
+ update: (handler: (prev: BodyState) => BodyState) => void;
326
+ ```
327
+
328
+ The handler receives a deep copy of the latest stored body state and must return the complete next state. `BodyState` contains `{ x, y, velocity, mass }`: use local `x` and `y` when updating position, rather than the snapshot's `position` field. Spread `prev` to preserve fields you are not changing.
329
+
330
+ For example, when game logic needs to reposition a body and change its velocity:
331
+
332
+ ```ts
333
+ if (body.ready) {
334
+ const snapshot = body.snapshot();
335
+
336
+ snapshot.update(prev => ({ ...prev, x: 100, y: 200 }));
337
+ snapshot.update(prev => ({
338
+ ...prev,
339
+ velocity: { ...prev.velocity, y: -300 },
340
+ }));
341
+ }
342
+ ```
343
+
344
+ Updates write to storage synchronously. Each handler receives the latest state, including changes from earlier updates, so the second update above preserves the first update's position. The deep copy includes nested objects such as `velocity`; mutating the handler's `prev` does not mutate live state before the handler returns. Return the next state even if you modify that copy directly.
345
+
346
+ The snapshot's data fields remain the values captured when `snapshot()` was called. Changing those fields does not update the body; use `update`, then call `body.snapshot()` again to read fresh values. Normal physics continues from the updated state, and changing the body's `x`, `y`, `velocity`, or `mass` props can still reset it as described above.
323
347
 
324
348
  ## Update, effect, and input hooks
325
349
 
@@ -22,6 +22,6 @@
22
22
  "vite": "^8.3.2"
23
23
  },
24
24
  "dependencies": {
25
- "discodreamer": "^1.0.3"
25
+ "discodreamer": "^1.0.4"
26
26
  }
27
27
  }