castle-web-cli 0.4.229 → 0.4.231
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/dist/agent-prompts.d.ts +2 -0
- package/dist/agent-prompts.js +16 -8
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +21 -21
- package/dist/api.d.ts +28 -2
- package/dist/api.js +74 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +860 -3
- package/dist/castleJson.d.ts +44 -0
- package/dist/castleJson.js +131 -0
- package/dist/check.js +27 -1
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +25 -13
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +237 -46
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +141 -31
- package/dist/index.js +3 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +126 -9
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +142 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +99 -14
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/webSourceSync.d.ts +2 -0
- package/dist/webSourceSync.js +2 -0
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +406 -53
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +9 -0
- package/kits/base/sdk/castle.js +5 -0
- package/kits/base/sdk/commands.d.ts +223 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +45 -1
- package/kits/base/sdk/multiplayer.js +158 -8
- package/kits/base/sdk/save.d.ts +197 -0
- package/kits/base/sdk/save.js +525 -0
- package/kits/base/sdk/saveCoordinator.d.ts +39 -0
- package/kits/base/sdk/saveCoordinator.js +252 -0
- package/kits/base/sdk/server/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +42 -1
- package/kits/base/sdk/server/storage.d.ts +58 -4
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +36 -2
- package/kits/base/sdk/server/wrapper.js +92 -11
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +149 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1035 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +376 -0
- package/kits/hub-game/code/client/hookLayer.js +236 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +143 -0
- package/kits/hub-game/code/client/talk.js +233 -0
- package/kits/hub-game/code/client/tiers.js +480 -0
- package/kits/hub-game/code/client/together.js +440 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +248 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1998 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +554 -0
- package/kits/hub-game/code/server/npcs.js +733 -0
- package/kits/hub-game/code/server/party.js +439 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2347 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1209 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +328 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1518 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +270 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +724 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +369 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-tiers.mjs +666 -0
- package/kits/hub-game/scripts/test-together.mjs +215 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +117 -5
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
- package/kits/physics-3d/CLAUDE.md +285 -1
- package/kits/physics-3d/behaviors/Player.jsx +74 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -5
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +527 -5
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
- package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
- package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
- package/kits/physics-3d/systems/physics3d.js +187 -5
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// The terms of `"engine": { "skipUnchangedActors": true }`:
|
|
2
|
+
//
|
|
3
|
+
// With the key absent, a scene runs the engine exactly as before. With the key
|
|
4
|
+
// present, each frame equals what the engine would have produced without it
|
|
5
|
+
// PROVIDED the scene's components are plain stored data (no accessors, Proxies,
|
|
6
|
+
// toJSON, custom iterators) and three.js objects under actors are changed only
|
|
7
|
+
// through position/rotation/quaternion/scale/visible/parenting. A scene that does
|
|
8
|
+
// not meet that is unsupported under the key and must not set it.
|
|
9
|
+
//
|
|
10
|
+
// "Is this component still what it was?" answered without building a string.
|
|
11
|
+
// Used only by scenes that set `"engine": { "skipUnchangedActors": true }`.
|
|
12
|
+
//
|
|
13
|
+
// The engine decides whether to rebuild an actor's mesh or its physics body by
|
|
14
|
+
// comparing a signature: `JSON.stringify` of the components that shape it.
|
|
15
|
+
// Building that string for every actor on every frame costs more than drawing
|
|
16
|
+
// a small scene. `remember(value)` keeps what the string was built from, and
|
|
17
|
+
// `sameAs(value, memory)` says whether `JSON.stringify(value)` would come out
|
|
18
|
+
// the same again, by reading the value's own fields against the memory: the
|
|
19
|
+
// same object with the same prototype, the same keys in the same order, the
|
|
20
|
+
// same primitive under each. It says no more often than the string would (a
|
|
21
|
+
// different object holding equal values, a NaN), and the caller then builds
|
|
22
|
+
// the string and compares that, as it always did.
|
|
23
|
+
//
|
|
24
|
+
// Only plain data is read this way: objects whose prototype is Object's (or
|
|
25
|
+
// none) and arrays whose prototype is Array's, holding stored values. Anything
|
|
26
|
+
// that computes what it hands out is never "the same" and takes the string
|
|
27
|
+
// path every frame, read exactly as often and in the order it always was:
|
|
28
|
+
// an object or array with an accessor property, with a `toJSON` (its own or
|
|
29
|
+
// inherited, enumerable or not, stored or itself a getter), of any other class
|
|
30
|
+
// (a Date, a Map), and a bigint, which `JSON.stringify` throws on. `remember`
|
|
31
|
+
// and `sameAs` find that out from property descriptors and `in`, without
|
|
32
|
+
// calling a getter. An array is read by index up to its length, as JSON reads
|
|
33
|
+
// it, whatever its iterator does.
|
|
34
|
+
//
|
|
35
|
+
// That last paragraph is protection, not part of the terms: a component that is
|
|
36
|
+
// not plain stored data is unsupported under the key. Other reads of such a
|
|
37
|
+
// component elsewhere in the skipping path (a Transform's fields, `Shape.solid`)
|
|
38
|
+
// are not guarded, a Proxy cannot be told from the object it stands in for, and
|
|
39
|
+
// a stored field redefined as an accessor in place is read once here before
|
|
40
|
+
// the string path reads it again.
|
|
41
|
+
const NEVER = { never: true };
|
|
42
|
+
|
|
43
|
+
// `'toJSON' in value`, not `value.toJSON`: asking whether there is one, on the
|
|
44
|
+
// value or anything it inherits from, calls no getter.
|
|
45
|
+
function holdsOnlyStoredValues(value) {
|
|
46
|
+
if ('toJSON' in value) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
50
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
51
|
+
if (!('value' in descriptors[key])) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// How deep a value is read. Past this it is "never the same": the walk here
|
|
59
|
+
// goes down by calling itself, and a value JSON.stringify can still write may
|
|
60
|
+
// be deeper than a call stack allows. Components are a few levels deep.
|
|
61
|
+
const DEEPEST = 32;
|
|
62
|
+
|
|
63
|
+
export function remember(value, depth = 0) {
|
|
64
|
+
if (typeof value === 'bigint') {
|
|
65
|
+
return NEVER;
|
|
66
|
+
}
|
|
67
|
+
if (typeof value !== 'object' || value === null) {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
if (depth >= DEEPEST) {
|
|
71
|
+
return NEVER;
|
|
72
|
+
}
|
|
73
|
+
const proto = Object.getPrototypeOf(value);
|
|
74
|
+
const isArray = Array.isArray(value);
|
|
75
|
+
const plain = isArray ? proto === Array.prototype : proto === Object.prototype || proto === null;
|
|
76
|
+
if (!plain || !holdsOnlyStoredValues(value)) {
|
|
77
|
+
return NEVER;
|
|
78
|
+
}
|
|
79
|
+
if (isArray) {
|
|
80
|
+
// By index up to `length`, which is how JSON reads an array; not by its
|
|
81
|
+
// iterator, which can be anyone's.
|
|
82
|
+
const values = [];
|
|
83
|
+
for (let i = 0; i < value.length; i++) {
|
|
84
|
+
values.push(remember(value[i], depth + 1));
|
|
85
|
+
}
|
|
86
|
+
return { of: value, proto, keys: null, values };
|
|
87
|
+
}
|
|
88
|
+
const keys = Object.keys(value);
|
|
89
|
+
return { of: value, proto, keys, values: keys.map((key) => remember(value[key], depth + 1)) };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function sameAs(value, memory) {
|
|
93
|
+
if (typeof value !== 'object' || value === null) {
|
|
94
|
+
// A primitive is never `===` a memory of an object, NEVER included, and
|
|
95
|
+
// NaN is not `===` itself.
|
|
96
|
+
return value === memory;
|
|
97
|
+
}
|
|
98
|
+
if (typeof memory !== 'object' || memory === null || memory.of !== value) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (Object.getPrototypeOf(value) !== memory.proto || 'toJSON' in value) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return memory.keys === null ? sameItems(value, memory.values) : sameFields(value, memory);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Most fields are primitives that are simply still equal; only what is not
|
|
108
|
+
// `===` (an object, a NaN, a changed value) is looked at further.
|
|
109
|
+
function sameFields(value, { keys, values }) {
|
|
110
|
+
let i = 0;
|
|
111
|
+
for (const key in value) {
|
|
112
|
+
if (key !== keys[i]) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
const now = value[key];
|
|
116
|
+
if (now !== values[i] && !sameAs(now, values[i])) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
i += 1;
|
|
120
|
+
}
|
|
121
|
+
return i === keys.length;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function sameItems(value, values) {
|
|
125
|
+
if (value.length !== values.length) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
for (let i = 0; i < values.length; i++) {
|
|
129
|
+
const now = value[i];
|
|
130
|
+
if (now !== values[i] && !sameAs(now, values[i])) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// An object that reads like `target` and writes down each read as `key, value`
|
|
138
|
+
// in `reads`, so a signature built from a lookup table (`sprites`, the deck's
|
|
139
|
+
// files) can be checked later by making the same reads again. A missing table
|
|
140
|
+
// reads as an empty one, which is what `table?.[key]` gives.
|
|
141
|
+
const EMPTY = Object.freeze({});
|
|
142
|
+
|
|
143
|
+
export function recordReads(target, reads) {
|
|
144
|
+
return new Proxy(target ?? EMPTY, {
|
|
145
|
+
get(table, key) {
|
|
146
|
+
const value = table[key];
|
|
147
|
+
if (typeof key === 'string') {
|
|
148
|
+
reads.push(key, value);
|
|
149
|
+
}
|
|
150
|
+
return value;
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|