create-dreamer-app 1.0.10 → 1.0.11
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
|
# Disco Dreamer reference
|
|
2
2
|
|
|
3
|
-
A practical guide to building browser games with `discodreamer`. Examples use the public API in version 1.0.
|
|
3
|
+
A practical guide to building browser games with `discodreamer`. Examples use the public API in version 1.0.8 and TypeScript with JSX.
|
|
4
4
|
|
|
5
5
|
## How a game runs
|
|
6
6
|
|
|
@@ -88,9 +88,21 @@ setScore((previous) => previous + 1);
|
|
|
88
88
|
|
|
89
89
|
Keys identify persistent data across frames. Give each stateful hook and each body instance a stable, descriptive key. For repeated entities, include an entity ID, such as `` `enemy.${id}.health` ``.
|
|
90
90
|
|
|
91
|
-
Internally, consecutive stateful calls using the same key
|
|
91
|
+
Internally, ordinary keys receive numbered slots for consecutive stateful calls using the same key. Their order must stay consistent. Reusing a key after a different ordinary key starts its numbering again, which can alias an earlier slot. The simplest application pattern is to use a distinct key for each hook and avoid sharing keys with component internals. Keep stateful hook calls in a consistent order each frame.
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
Prefix a `gameState` key with `$` to use it literally, bypassing numbering. The `$` remains part of the stored key. Every call with the same literal key shares one state slot, regardless of call location or loop iteration:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
const [, setScore] = gameState("$score", 0);
|
|
97
|
+
setScore((previous) => previous + 1);
|
|
98
|
+
|
|
99
|
+
// Elsewhere in the same frame:
|
|
100
|
+
const [score] = gameState("$score", 0); // Reads the incremented score.
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The first call initializes the shared slot; later calls do not reset it. Literal keys do not advance or reset ordinary-key numbering. The `$` rule is implemented in `gameState`, so helpers that call it internally also inherit it. Use ordinary keys for those helpers, especially `gameAnimation`, which needs multiple numbered slots for a single key. Hooks that resolve keys directly, such as `gameEffect`, retain normal numbering.
|
|
104
|
+
|
|
105
|
+
State that is no longer used is removed during frame cleanup. This also applies to `$` keys: sharing a slot does not make it permanent. If an entity disappears for a frame and returns later, expect its state to initialize again.
|
|
94
106
|
|
|
95
107
|
### `createDynamicId()`
|
|
96
108
|
|