castle-web-sdk 0.4.29 → 0.4.30

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 CHANGED
@@ -735,24 +735,6 @@ if (isEdit()) {
735
735
  }
736
736
  ```
737
737
 
738
- ### `registerParams(path, params)`
739
-
740
- Decks never write this call. While `castle-web serve` is running, the
741
- dev server appends it to every module that declares a `PARAMS` object,
742
- so a value tuned in the editor's Parameters panel is assigned into that
743
- object in the deck that is already running instead of restarting it. A
744
- published deck never gets the call.
745
-
746
- For a tune to be visible, read a param at the use site rather than
747
- destructuring it at module load:
748
-
749
- ```js
750
- export const PARAMS = { jumpHeight: 4.2 };
751
-
752
- // reads the tuned value every jump
753
- function jump() { player.vy = -PARAMS.jumpHeight; }
754
- ```
755
-
756
738
  ### `writeFile(path, contents): Promise<void>`
757
739
 
758
740
  Writes a file in the deck directory. `path` is relative to the deck
@@ -22,9 +22,11 @@ export interface AppliedNotice {
22
22
  */
23
23
  export declare function appliedNotice(path: string, seq: unknown, ok: boolean): AppliedNotice;
24
24
  /**
25
- * Write tuned values into the module's live `PARAMS`. False when any of them
26
- * could not land -- an unregistered path, a key the object does not have, a
27
- * frozen object -- and the rest are still written, because a slot that cannot
28
- * be applied is no reason to withhold the ones that can.
25
+ * Write tuned values into every live `PARAMS` registered under the path. False
26
+ * unless every slot landed on every object -- an unregistered path, a key one
27
+ * object does not have, a frozen object -- and the rest are still written,
28
+ * because a slot that cannot be applied is no reason to withhold the ones that
29
+ * can. An older instance missing a key a later code edit added reports false
30
+ * too: the run may be reading it, so the editor offers a restart.
29
31
  */
30
32
  export declare function applyTunedParams(path: string, slots: TunedParam[]): boolean;
@@ -8,7 +8,15 @@
8
8
  // path rather than on anything the module says about itself: the path is what
9
9
  // the serve's broadcast names, and the module never had to agree to anything.
10
10
  //
11
- // The object is mutated IN PLACE, never replaced. Deck code holds the same
11
+ // A path holds EVERY object ever registered under it, not the latest. The serve
12
+ // appends the call to every transform of the module, including a kit's
13
+ // cache-busting `?t=` re-import, which evaluates a fresh module instance with a
14
+ // fresh `PARAMS` under the same path. An older instance can still be the one
15
+ // running -- physics-2d's play frame keeps the classes it started with and never
16
+ // adopts swapped ones -- and the registry cannot tell which instance a run reads,
17
+ // so the only honest answer is to write the tune into all of them.
18
+ //
19
+ // Each object is mutated IN PLACE, never replaced. Deck code holds the same
12
20
  // reference (`PARAMS.jumpHeight` at the use site is the documented way to read
13
21
  // one), so handing back a new object would leave every reader on the old one.
14
22
  const registered = new Map();
@@ -17,7 +25,12 @@ export function registerParams(path, params) {
17
25
  return;
18
26
  if (typeof params !== "object" || params === null)
19
27
  return;
20
- registered.set(path, params);
28
+ let instances = registered.get(path);
29
+ if (!instances) {
30
+ instances = new Set();
31
+ registered.set(path, instances);
32
+ }
33
+ instances.add(params);
21
34
  }
22
35
  // Own properties only, at every level. A `ParamSlot.id` comes from a key the
23
36
  // file wrote in an object literal, so an inherited name (`constructor`,
@@ -65,19 +78,23 @@ export function appliedNotice(path, seq, ok) {
65
78
  };
66
79
  }
67
80
  /**
68
- * Write tuned values into the module's live `PARAMS`. False when any of them
69
- * could not land -- an unregistered path, a key the object does not have, a
70
- * frozen object -- and the rest are still written, because a slot that cannot
71
- * be applied is no reason to withhold the ones that can.
81
+ * Write tuned values into every live `PARAMS` registered under the path. False
82
+ * unless every slot landed on every object -- an unregistered path, a key one
83
+ * object does not have, a frozen object -- and the rest are still written,
84
+ * because a slot that cannot be applied is no reason to withhold the ones that
85
+ * can. An older instance missing a key a later code edit added reports false
86
+ * too: the run may be reading it, so the editor offers a restart.
72
87
  */
73
88
  export function applyTunedParams(path, slots) {
74
- const target = registered.get(path);
75
- if (!target)
89
+ const instances = registered.get(path);
90
+ if (!instances || instances.size === 0)
76
91
  return false;
77
92
  let applied = true;
78
- for (const slot of slots) {
79
- if (!assign(target, slot.id, slot.after))
80
- applied = false;
93
+ for (const target of instances) {
94
+ for (const slot of slots) {
95
+ if (!assign(target, slot.id, slot.after))
96
+ applied = false;
97
+ }
81
98
  }
82
99
  return applied;
83
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-sdk",
3
- "version": "0.4.29",
3
+ "version": "0.4.30",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"