threedog 0.1.0 → 0.2.1
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 +4 -4
- package/core/Animator.js +1 -0
- package/core/Assets.js +28 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +14 -3
- package/core/Engine.js +44 -72
- package/core/Events.js +59 -1
- package/core/I18n.js +2 -2
- package/core/Inspect.js +12 -32
- package/core/InspectScene.js +7 -3
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +43 -59
- package/core/Saves.js +5 -4
- package/core/UrlState.js +3 -2
- package/core/Vars.js +1 -0
- package/core/Views.js +49 -0
- package/core/actor.js +2 -2
- package/core/assetReport.js +83 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +51 -0
- package/core/describeText.js +11 -4
- package/core/errorCodes.js +33 -0
- package/core/errorHints.js +6 -1
- package/core/grid.js +127 -0
- package/core/gridLoad.js +19 -0
- package/core/holds.js +106 -0
- package/core/lifecycle.js +1 -0
- package/core/lightWatch.js +23 -3
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +22 -16
- package/core/modules.js +19 -5
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +25 -14
- package/core/opsFail.js +20 -0
- package/core/opsHistory.js +6 -6
- package/core/opsRun.js +77 -0
- package/core/params.js +132 -0
- package/core/renamed.js +22 -0
- package/core/saveApply.js +2 -2
- package/core/sceneMethods.js +9 -34
- package/core/services.js +73 -0
- package/core/startup.js +3 -1
- package/core/styleParts.js +11 -9
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +35 -24
- package/core/things.js +15 -1
- package/core/util.js +11 -0
- package/core/validate.js +23 -7
- package/docs/AI.md +93 -114
- package/docs/API.md +8 -9
- package/docs/CODEMAP.md +67 -53
- package/docs/COMMANDS.md +21 -7
- package/docs/CONVENTIONS.md +22 -11
- package/docs/THREE.md +3 -3
- package/docs/api/assets.md +3 -0
- package/docs/api/characters.md +5 -2
- package/docs/api/collision.md +4 -0
- package/docs/api/content.md +1 -0
- package/docs/api/engine.md +23 -14
- package/docs/api/events.md +5 -1
- package/docs/api/post.md +5 -4
- package/docs/api/saves.md +2 -1
- package/docs/api/sky.md +3 -3
- package/docs/api/style.md +8 -8
- package/docs/api/tools.md +5 -2
- package/docs/api/vegetation.md +1 -0
- package/docs/api/weather.md +1 -1
- package/docs/recipes/01-new-game.md +41 -43
- package/docs/recipes/02-npc.md +38 -22
- package/docs/recipes/03-items-pickups.md +4 -4
- package/docs/recipes/04-quests.md +23 -23
- package/docs/recipes/05-props-bake.md +5 -5
- package/docs/recipes/06-clock-events.md +13 -0
- package/docs/recipes/07-flow-scenes-pause.md +6 -2
- package/docs/recipes/08-weather-sky.md +6 -6
- package/docs/recipes/09-style-pack.md +35 -100
- package/docs/recipes/12-navmesh.md +22 -0
- package/docs/recipes/13-animation.md +25 -6
- package/docs/recipes/14-custom-module.md +6 -7
- package/docs/recipes/15-perf.md +9 -1
- package/docs/recipes/16-dev-bridge.md +52 -18
- package/docs/recipes/18-world.md +5 -2
- package/docs/recipes/19-shooting-picking.md +9 -8
- package/docs/recipes/20-content-actions-save.md +10 -10
- package/docs/recipes/21-camera.md +51 -2
- package/docs/recipes/22-shop-gold.md +16 -16
- package/docs/recipes/23-ops.md +46 -10
- package/docs/recipes/27-net.md +3 -3
- package/docs/recipes/28-terrain.md +2 -2
- package/docs/recipes/29-grid.md +47 -27
- package/docs/recipes/34-environment-lighting.md +11 -10
- package/docs/recipes/35-style-from-reference.md +41 -46
- package/docs/recipes/36-sky-ground-plant-looks.md +22 -20
- package/docs/recipes/37-terrain-look-hooks.md +34 -13
- package/docs/recipes/38-environment-look-hooks.md +49 -42
- package/docs/recipes/40-scene.md +29 -0
- package/docs/recipes/41-thing-registry.md +29 -0
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/43-shader-patches-surface-looks.md +37 -20
- package/docs/recipes/44-water-weather-look-hooks.md +11 -9
- package/docs/recipes/45-cascaded-shadows.md +2 -2
- package/docs/recipes/46-blender-art-route.md +26 -4
- package/docs/recipes/47-island-snow-backdrop.md +4 -3
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +146 -0
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/examples/action/GAMEMAP.md +7 -7
- package/examples/action/content/index.js +2 -1
- package/examples/action/content/views.js +6 -0
- package/examples/action/main.js +3 -2
- package/examples/sheepisland/GAMEMAP.md +3 -4
- package/examples/styletest/GAMEMAP.md +3 -3
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/main.js +2 -2
- package/examples/styletest/panel.js +3 -3
- package/examples/world/GAMEMAP.md +3 -3
- package/examples/world/content/npcs.js +1 -1
- package/examples/world/main.js +1 -1
- package/index.d.ts +35 -2
- package/index.js +6 -3
- package/llms.txt +13 -7
- package/modules/ambience/Ambience.js +5 -2
- package/modules/camera/FirstPersonCamera.js +3 -5
- package/modules/camera/FixedCamera.js +19 -12
- package/modules/camera/FollowCamera.js +14 -8
- package/modules/camera/RtsCamera.js +3 -5
- package/modules/camera/common.js +40 -10
- package/modules/camera/index.js +1 -1
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +45 -31
- package/modules/characters/assetModel.js +35 -7
- package/modules/characters/astar.js +14 -7
- package/modules/characters/index.js +6 -3
- package/modules/characters/movers/simple.js +6 -1
- package/modules/characters/npcSim.js +8 -2
- package/modules/characters/pathAsync.js +12 -6
- package/modules/characters/pathJob.js +2 -1
- package/modules/characters/proceduralRig.js +50 -11
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +102 -4
- package/modules/content/explain.js +13 -0
- package/modules/content/index.js +3 -1
- package/modules/content/loader.js +3 -0
- package/modules/content/rules.js +1 -0
- package/modules/debug/DebugPanel.js +11 -5
- package/modules/entities/Entities.js +6 -2
- package/modules/flow/index.js +5 -2
- package/modules/gameplay/Dialogue.js +5 -2
- package/modules/gameplay/Interactions.js +12 -2
- package/modules/gameplay/Inventory.js +21 -11
- package/modules/gameplay/Quests.js +13 -3
- package/modules/gameplay/pickups.js +6 -4
- package/modules/grid/Layer.js +1 -1
- package/modules/grid/index.js +1 -1
- package/modules/grid/tiles.js +9 -5
- package/modules/hlod/index.js +5 -2
- package/modules/hud/index.js +5 -2
- package/modules/level/index.js +5 -3
- package/modules/lights/index.js +5 -2
- package/modules/music/Music.js +6 -2
- package/modules/nav/index.js +5 -3
- package/modules/net/Client.js +4 -3
- package/modules/net/Host.js +2 -2
- package/modules/net/index.js +5 -3
- package/modules/particles/Particles.js +1 -1
- package/modules/photo/Photo.js +10 -7
- package/modules/rigid/RigidBodies.js +5 -2
- package/modules/settings/Settings.js +6 -3
- package/modules/settings/apply.js +2 -1
- package/modules/sky/Sky.js +21 -19
- package/modules/sky/cascades.js +6 -6
- package/modules/sky/domeLayers.js +1 -1
- package/modules/sky/environment.js +39 -13
- package/modules/sky/fog.js +9 -6
- package/modules/sky/frame.js +4 -3
- package/modules/sky/look.js +3 -2
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/shader.js +2 -2
- package/modules/sky/shadow.js +4 -10
- package/modules/sky/skyModule.js +4 -3
- package/modules/terrain/ChunkManager.js +2 -33
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/index.js +10 -2
- package/modules/terrain/lookGround.js +61 -0
- package/modules/timeline/Timeline.js +7 -3
- package/modules/timeline/Tween.js +3 -7
- package/modules/timeline/shots.js +6 -4
- package/modules/triggers/index.js +9 -2
- package/modules/vegetation/Vegetation.js +17 -4
- package/modules/vegetation/index.js +7 -4
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/nearFade.js +39 -0
- package/modules/water/Water.js +19 -3
- package/modules/water/look.js +80 -0
- package/modules/weather/Weather.js +22 -31
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +1 -1
- package/modules/weather/strings.js +15 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +11 -4
- package/modules/world/thingSource.js +44 -0
- package/package.json +2 -1
- package/render/PostFX.js +48 -51
- package/render/detail.js +39 -15
- package/render/effects.js +4 -2
- package/render/fuse.js +12 -0
- package/render/lights.js +4 -2
- package/render/lookSurface.js +161 -0
- package/render/materials.js +27 -10
- package/render/postLook.js +86 -0
- package/render/surface.js +3 -1
- package/types/core.d.ts +223 -29
- package/types/gameplay.d.ts +22 -6
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +43 -0
- package/types/generated/core/Ops.d.ts +62 -21
- package/types/generated/core/Saves.d.ts +1 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Layer.d.ts +1 -0
- package/types/generated/modules/sky/Sky.d.ts +10 -17
- package/types/generated/modules/weather/Weather.d.ts +5 -15
- package/types/generated/render/PostFX.d.ts +20 -23
- package/types/generated/render/materials.d.ts +10 -0
- package/types/physics.d.ts +8 -0
- package/types/style.d.ts +35 -20
- package/types/world.d.ts +7 -1
- package/ui/Parts.js +6 -2
- package/ui/UI.js +1 -1
- package/ui/defaults.js +1 -1
- package/docs/api/debug.md +0 -10
package/core/thingOps.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { Things, snap, write } from './things.js';
|
|
7
7
|
import { closest } from './validate.js';
|
|
8
8
|
import { codedError } from './errorHints.js';
|
|
9
|
+
import { explainThing } from './thingExplain.js';
|
|
9
10
|
|
|
10
11
|
const SAY = {
|
|
11
12
|
record: { keeps: ['record fields and position (world save part)'], loses: ['the built model itself: it is rebuilt from its template / present after a load'] },
|
|
@@ -25,40 +26,43 @@ function editText(en, tier, rec) {
|
|
|
25
26
|
return `made during play${en.op ? ` by op ${en.op}` : ''}${at}: to keep it, make it a template and create it inside the op with engine.spawn(name, at)`;
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
/** thing.explain(): the whole story of the id in one object (thingExplain.js); a method, not a field, so the thing stays small */
|
|
30
|
+
const withExplain = (e, t) => Object.defineProperty(t, 'explain', { value: () => explainThing(e, t), enumerable: false });
|
|
31
|
+
|
|
28
32
|
/** A registered plain object as a thing (same shape as hit.thing); `object` is a non-enumerable getter so the result stays JSON-able */
|
|
29
33
|
function nativeThing(e, en, root) {
|
|
30
34
|
const tier = e._things.tier(en), say = SAY[tier];
|
|
31
35
|
const out = { id: en.id, kind: root.type, owner: en.owner, at: en.at, phase: en.phase, ...(en.op && { op: en.op, tick: en.tick }), saved: tier,
|
|
32
36
|
keeps: say.keeps, loses: say.loses, edit: editText(en, tier), removed: e._things.gone.has(en.id),
|
|
33
37
|
template: null, definedAt: null, model: null, fields: {} };
|
|
34
|
-
return Object.defineProperty(out, 'object', { get: () => root, enumerable: false });
|
|
38
|
+
return withExplain(e, Object.defineProperty(out, 'object', { get: () => root, enumerable: false }));
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
/**
|
|
38
|
-
* The thing for a
|
|
42
|
+
* The thing for a record id (from a source, see Things.addSource), a registered id / name, or any Object3D (its
|
|
39
43
|
* registered ancestor). null when nothing matches.
|
|
40
44
|
* @internal
|
|
41
45
|
*/
|
|
42
|
-
export function findThing(e, q
|
|
46
|
+
export function findThing(e, q) {
|
|
43
47
|
const T = e._things;
|
|
44
48
|
if (typeof q === 'string') {
|
|
45
|
-
if (
|
|
49
|
+
if (T.source(q)) return recordAsThing(e, q);
|
|
46
50
|
const o = T.live(q) ?? e.scene.getObjectByName(q);
|
|
47
51
|
return native(e, o && T.entryOf(o));
|
|
48
52
|
}
|
|
49
53
|
if (!q?.isObject3D) return null;
|
|
50
|
-
const id =
|
|
51
|
-
return id ? recordAsThing(e, id
|
|
54
|
+
const id = T.idOf(q);
|
|
55
|
+
return id ? recordAsThing(e, id) : native(e, T.entryOf(q));
|
|
52
56
|
}
|
|
53
57
|
/** A world-owned entry that world no longer answers for is a torn-down model (template models are only detached): not a thing */
|
|
54
58
|
const native = (e, hit) => hit && hit[0].owner !== 'world' ? nativeThing(e, hit[0], hit[1]) : null;
|
|
55
|
-
function recordAsThing(e, id
|
|
56
|
-
const
|
|
59
|
+
function recordAsThing(e, id) {
|
|
60
|
+
const src = e._things.source(id), r = src.explain(id);
|
|
57
61
|
const out = { ...r, owner: 'world', at: r.definedAt ?? null, phase: r.spawned ? 'play' : 'setup', saved: 'record', ...SAY.record, edit: editText(null, 'record', r.edit) };
|
|
58
|
-
return Object.defineProperty(out, 'object', { get: () =>
|
|
62
|
+
return withExplain(e, Object.defineProperty(out, 'object', { get: () => src.view(id), enumerable: false }));
|
|
59
63
|
}
|
|
60
64
|
/** Every id engine.thing knows (for "did you mean") */
|
|
61
|
-
function thingIds(e) { return [...
|
|
65
|
+
function thingIds(e) { return [...e._things.recordIds(), ...e._things.byId.keys()]; }
|
|
62
66
|
export const hintThing = (e, id) => { const c = closest(String(id), thingIds(e)); return c ? ` (did you mean '${c}'?)` : ''; };
|
|
63
67
|
|
|
64
68
|
/** Normalise thing.set args into a patch of arrays (rotation as a number = yaw; scale as a number = uniform) */
|
|
@@ -77,26 +81,32 @@ const uni = s => typeof s === 'number' ? s : s[0];
|
|
|
77
81
|
/** Register the registry, engine.thing's ops, the 'scene' save part and the session:start setup window (called once by the Engine constructor) */
|
|
78
82
|
export function installThings(e) {
|
|
79
83
|
const T = e._things = new Things(e);
|
|
84
|
+
T.explainers = []; // explain contributions from modules (see thingExplain.js)
|
|
85
|
+
/**
|
|
86
|
+
* Add a contribution to engine.thing(id).explain(): fn(engine, thing, out) may fill out.state / out.rules (or add keys) for the things its module owns.
|
|
87
|
+
* For module authors: core never reads another module's record or template shape, the module hands it over here. A throwing fn is skipped.
|
|
88
|
+
* @param {(e: any, t: any, out: any) => void} fn
|
|
89
|
+
* @example engine.explainWith((e, t, out) => { const r = e.myRecords.get(t.id); if (r) out.state = { ...r }; });
|
|
90
|
+
*/
|
|
91
|
+
e.explainWith = fn => { T.explainers.push(fn); };
|
|
80
92
|
// content() replaces this; without it a bare "spawn is not a function" would not say which module to install
|
|
81
93
|
e.spawn = () => { throw new Error("engine.spawn needs the content module: add content() to engine.use(...) (import { content } from 'threedog')"); };
|
|
82
|
-
e.saves.register('scene', { save: () => T.save(), load: d => T.load(d) });
|
|
83
|
-
const kindOf = id =>
|
|
94
|
+
e.saves.register('scene', { atomic: true, save: () => T.save(), load: d => T.load(d) });
|
|
95
|
+
const kindOf = id => T.source(id) ? 'record' : T.live(id) ? T.tier(T.byObj.get(T.live(id))) : null;
|
|
84
96
|
const reasons = {
|
|
85
97
|
noThing: 'no world record or engine.add object has this id (engine.thing(id) suggests the closest one)',
|
|
86
98
|
engineOwned: 'an engine module manages this object (water, particles, physics…); change it through that module',
|
|
87
99
|
recordVisible: 'a world record has no visible flag: hide its model with present({ show: rec => … }) and a field set by world.set',
|
|
88
100
|
};
|
|
89
101
|
e.ops.define('thing.set', {
|
|
102
|
+
targets: '*',
|
|
90
103
|
desc: 'Move / turn / scale / show or hide a thing: a world record (via world.set / move) or an engine.add object (saved as an override when it has an id)',
|
|
91
104
|
args: { id: 'string', position: 'any?', rotation: 'any?', scale: 'any?', visible: 'bool?' },
|
|
92
105
|
can: (_, a) => { const k = kindOf(a.id); return !k ? 'noThing' : k === 'engine' ? 'engineOwned' : k === 'record' && a.visible != null ? 'recordVisible' : true; },
|
|
93
106
|
run(eng, a) {
|
|
94
107
|
if (kindOf(a.id) === 'record') {
|
|
95
|
-
// rot / scale are the template instance fields (templates.js); a record without them reads as rot 0, scale 1
|
|
96
|
-
const rec = eng.world.get(a.id), before = { position: { ...rec.position }, ...(a.rotation != null && { rot: rec.rot ?? 0 }), ...(a.scale != null && { scale: rec.scale ?? 1 }) };
|
|
97
108
|
const patch = { ...(a.position && { position: xyz(a.position) }), ...(a.rotation != null && { rot: yaw(a.rotation) }), ...(a.scale != null && { scale: uni(a.scale) }) };
|
|
98
|
-
|
|
99
|
-
return { record: true, before };
|
|
109
|
+
return { record: true, before: T.source(a.id).set(a.id, patch) };
|
|
100
110
|
}
|
|
101
111
|
const obj = T.live(a.id), p = patchOf(obj, a);
|
|
102
112
|
if (T.tier(T.byObj.get(obj)) === 'code') return T.override(a.id, obj, p);
|
|
@@ -105,7 +115,7 @@ export function installThings(e) {
|
|
|
105
115
|
return before;
|
|
106
116
|
},
|
|
107
117
|
undo(eng, a, v) {
|
|
108
|
-
if (v.record) {
|
|
118
|
+
if (v.record) { T.source(a.id).set(a.id, v.before); return; }
|
|
109
119
|
const obj = T.live(a.id); if (!obj) return;
|
|
110
120
|
write(obj, v.patch);
|
|
111
121
|
if (v.session) return;
|
|
@@ -114,21 +124,21 @@ export function installThings(e) {
|
|
|
114
124
|
reasons,
|
|
115
125
|
});
|
|
116
126
|
e.ops.define('thing.remove', {
|
|
127
|
+
targets: '*',
|
|
117
128
|
desc: 'Remove a thing (undoable): a world record via world.remove, or an engine.add object (detached and kept; saved when it has an id)',
|
|
118
129
|
args: { id: 'string' },
|
|
119
130
|
can: (_, a) => { const k = kindOf(a.id); return !k || T.gone.has(a.id) ? 'noThing' : k === 'engine' ? 'engineOwned' : true; },
|
|
120
131
|
run(eng, a) {
|
|
121
132
|
if (kindOf(a.id) === 'record') {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
return { record: rec, authored };
|
|
133
|
+
const src = T.source(a.id);
|
|
134
|
+
return { record: src.remove(a.id), src };
|
|
125
135
|
}
|
|
126
136
|
T.hide(a.id, T.live(a.id), T.tier(T.byObj.get(T.live(a.id))) === 'code');
|
|
127
137
|
return {};
|
|
128
138
|
},
|
|
129
139
|
undo(eng, a, v) {
|
|
130
140
|
if (!v.record) { T.unhide(a.id); return; }
|
|
131
|
-
|
|
141
|
+
v.src.restore(v.record);
|
|
132
142
|
},
|
|
133
143
|
reasons,
|
|
134
144
|
});
|
|
@@ -142,15 +152,16 @@ export function describeScene(e) {
|
|
|
142
152
|
const en = T.byObj.get(o), tier = T.tier(en);
|
|
143
153
|
if (en.owner === 'game') { n.game++; n[tier]++; } else if (tier === 'record') { if (o.parent) n.world++; } else n.engine++;
|
|
144
154
|
}
|
|
145
|
-
const
|
|
155
|
+
const ov = e.debug.overrides();
|
|
156
|
+
const out = { ...n, ...(ov.length && { overrides: ov, overridesNote: 'diagnostic: the screen differs from the real state until engine.debug.clear(owner)' }), unsaved: T.lost().map(en => `${en.id} (${en.at ? en.at + ', ' : ''}${en.phase === 'play' ? 'made during play' : 'no stable id'}${en.op ? ` by op ${en.op}` : ''})`),
|
|
146
157
|
conflicts: [...T.conflicts], orphans: T.orphans() };
|
|
147
158
|
if (T.atCapped) out.atCapped = true; // dev stacks stopped: later objects have at: null
|
|
148
159
|
return out;
|
|
149
160
|
}
|
|
150
161
|
|
|
151
162
|
/** engine.thing(idOrObj): throws with the closest id when nothing matches @internal */
|
|
152
|
-
export function thing(e, q
|
|
153
|
-
const t = findThing(e, q
|
|
163
|
+
export function thing(e, q) {
|
|
164
|
+
const t = findThing(e, q);
|
|
154
165
|
if (t) return t;
|
|
155
166
|
const what = typeof q === 'string' ? `'${q}'` : q?.isObject3D ? `an unregistered ${q.type}` : JSON.stringify(q);
|
|
156
167
|
throw codedError('thing-id', `engine.thing(${what}): nothing has this id or name${typeof q === 'string' ? hintThing(e, q) : ''}. Pass a world record id, the id given to engine.add(obj, { id }), an object name or any Object3D added with engine.add (engine.scene.add does not register)`);
|
package/core/things.js
CHANGED
|
@@ -47,7 +47,7 @@ const pick = (o, keys) => Object.fromEntries(keys.filter(k => k in o).map(k => [
|
|
|
47
47
|
export function claimId(e, id, obj = null) {
|
|
48
48
|
const T = e._things, who = obj ? `engine.add(obj, { id: '${id}' })` : `world.add({ id: '${id}' })`;
|
|
49
49
|
if (obj && (typeof id !== 'string' || !id || id.includes('#'))) throw codedError('thing-id', `engine.add(obj, { id: ${JSON.stringify(id)} }): an id is a non-empty string without '#' ('#' marks runtime ids such as obj#3), e.g. { id: 'windmill' }`);
|
|
50
|
-
if (obj &&
|
|
50
|
+
if (obj && T.source(id)) throw codedError('thing-id', `${who}: '${id}' is a world record id (engine.thing('${id}') shows it). Ids are shared with world records: pick another`);
|
|
51
51
|
const other = T.live(id);
|
|
52
52
|
if (other && other !== obj && T.byObj.get(other).owner !== 'world') {
|
|
53
53
|
const at = T.byObj.get(other).at;
|
|
@@ -59,6 +59,7 @@ export function claimId(e, id, obj = null) {
|
|
|
59
59
|
export class Things {
|
|
60
60
|
constructor(e) {
|
|
61
61
|
this.e = e;
|
|
62
|
+
this.sources = []; // record stores (world) registered with addSource; core knows only their shape
|
|
62
63
|
this.byObj = new WeakMap();
|
|
63
64
|
this.byId = new Map(); // id -> WeakRef(root)
|
|
64
65
|
this.n = 0; // session ids obj#n
|
|
@@ -72,6 +73,19 @@ export class Things {
|
|
|
72
73
|
this.conflicts = []; // dev: "two systems manage one object" findings, newest last
|
|
73
74
|
e.events.on('session:start', () => { this.setup = true; queueMicrotask(() => { this.setup = false; }); });
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* A store of records that share the id space with engine.add objects (the world module registers itself at install). The shape core uses:
|
|
78
|
+
* { has(id), get(id) -> { position, ... }, ids(), idOf(obj) -> id | null (model -> record), view(id) -> Object3D | null,
|
|
79
|
+
* explain(id) -> the record as a thing, set(id, patch) -> undo values, remove(id) -> restore token, restore(token) }
|
|
80
|
+
* @param {any} src @returns {{ remove(): void }}
|
|
81
|
+
*/
|
|
82
|
+
addSource(src) { this.sources.push(src); return { remove: () => { this.sources = this.sources.filter(s => s !== src); } }; }
|
|
83
|
+
/** The source that has a record under id, else null */
|
|
84
|
+
source(id) { return this.sources.find(s => s.has(id)) ?? null; }
|
|
85
|
+
/** The record id whose model is obj, else null */
|
|
86
|
+
idOf(obj) { for (const s of this.sources) { const id = s.idOf?.(obj); if (id) return id; } return null; }
|
|
87
|
+
/** Every record id (for "did you mean") */
|
|
88
|
+
recordIds() { return this.sources.flatMap(s => s.ids?.() ?? []); }
|
|
75
89
|
/** Whether a dev stack should be taken for this add (cap reached = no) */
|
|
76
90
|
wantStack() { return this.stacks < STACK_CAP && ++this.stacks > 0; }
|
|
77
91
|
get atCapped() { return this.stacks >= STACK_CAP; }
|
package/core/util.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Small helpers several core files need. One definition each, so "what counts as a plain object" and "how a dotted path is read" cannot drift apart.
|
|
2
|
+
|
|
3
|
+
/** A plain data object: { } or Object.create(null); not an array, class instance, three.js object or function */
|
|
4
|
+
export const isPlainObject = v => v !== null && typeof v === 'object' && !Array.isArray(v) && [Object.prototype, null].includes(Object.getPrototypeOf(v));
|
|
5
|
+
|
|
6
|
+
/** Read a dotted path ('look.fog.color'); undefined as soon as a step is missing @param {any} obj @param {string} path */
|
|
7
|
+
export function getPath(obj, path) {
|
|
8
|
+
let v = obj;
|
|
9
|
+
for (const k of path.split('.')) v = v?.[k];
|
|
10
|
+
return v;
|
|
11
|
+
}
|
package/core/validate.js
CHANGED
|
@@ -92,16 +92,32 @@ export function warnMissing(kind, name, list) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
95
|
+
* The one unknown-option rule, shared by readParams (strict) and checkOptions (loose): text for a key not in known, or null when it is fine.
|
|
96
|
+
* Why one function: the "did you mean" search and the wording must not drift between the two readers.
|
|
97
|
+
* soft: a key with no close match is not reported (data like items and entities, where games add their own fields).
|
|
98
|
+
*/
|
|
99
|
+
export function unknownOptionText(where, key, known, { soft = false } = {}) {
|
|
100
|
+
if (known.includes(key)) return null;
|
|
101
|
+
const c = closest(key, known);
|
|
102
|
+
if (!c && soft) return null;
|
|
103
|
+
return fmt(STRINGS.unknownKey, { where, key, hint: c ? fmt(STRINGS.didYouMean, { name: c }) : fmt(STRINGS.available, { list: known.join(', ') }) });
|
|
104
|
+
}
|
|
105
|
+
/** Is options an object a game passed (not a Three.js object, array or missing)? */
|
|
106
|
+
export const isOptionsObject = o => !!o && typeof o === 'object' && !Array.isArray(o) && !o.isObject3D && !o.isVector3;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Check an options object for unknown keys (the loose mode of readParams: same detection, same hint, but nothing is read or filled in).
|
|
110
|
+
* where is the origin (such as 'npcs.add()'), known are the keys the code actually reads.
|
|
111
|
+
* It only warns (once), in every build: the callers are hand-written checks of data and style objects that games and tests deliberately feed
|
|
112
|
+
* misspellings, and their known lists can lag behind the code. The module factories that went through readParams (the strict mode: dev throws,
|
|
113
|
+
* release warns once, decision 2026-11-01) get the throw there. loose: report only near-misses (items and entities, where games add their own fields).
|
|
97
114
|
*/
|
|
98
115
|
export function checkOptions(where, opts, known, { loose = false } = {}) {
|
|
99
|
-
if (!enabled || !
|
|
116
|
+
if (!enabled || !isOptionsObject(opts)) return;
|
|
100
117
|
for (const k of Object.keys(opts)) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
warnOnce(fmt(STRINGS.unknownKey, { where, key: k, hint: c ? fmt(STRINGS.didYouMean, { name: c }) : fmt(STRINGS.available, { list: known.join(', ') }) }));
|
|
118
|
+
const msg = unknownOptionText(where, k, known, { soft: loose });
|
|
119
|
+
if (!msg) continue;
|
|
120
|
+
warnOnce(msg);
|
|
105
121
|
}
|
|
106
122
|
}
|
|
107
123
|
|
package/docs/AI.md
CHANGED
|
@@ -4,146 +4,125 @@ threedog.js is a web 3D game engine on top of three.js 0.187 (plain three.js, no
|
|
|
4
4
|
demand with `engine.use`) -> **style pack** (all art, an optional separate package; the engine ships none and draws gray placeholders without one).
|
|
5
5
|
This file is the index for the AI that builds a game on the engine. Paths are relative to this `docs/` folder (`node_modules/threedog/docs/`).
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
## Most common mistakes
|
|
8
|
+
- Hand-writing a system the table lists (inventory, saves, quests, grids, collision): find the row first.
|
|
9
|
+
- `Math.random()`, `setTimeout`, `performance.now()` in game logic: use `engine.random`, `engine.clock.after / every`, fixed `dt`.
|
|
10
|
+
- `addEventListener('keydown')` for gameplay: define an action with `input.define` and read it in the fixed step.
|
|
11
|
+
- Changing gameplay state from a frame hook or a raw callback: do it in `onFixed`, in an op, or via `engine.nextFixed(fn)`.
|
|
12
|
+
- Saving positions or object references: save stable ids; `await` every `saves.*` call.
|
|
13
|
+
- A mesh added with plain `scene.add` and no id: `engine.add(obj, { id })` is what makes it saveable and inspectable.
|
|
14
|
+
- Changing a look by editing `renderer` / `scene.fog` / materials directly, or in logic: `engine.look.<part>` (recipe 52), values in the style pack.
|
|
15
|
+
- Putting game content (dialogue, quests, items, layout) inside the engine package: it lives in the game's `content/`.
|
|
16
|
+
- Editing generated docs (GAMEMAP, API.md, api/, CODEMAP, `types/generated/`): change the code, run `npm run map`.
|
|
17
|
+
- Guessing a name: look it up in `api/<module>.md`; engine errors carry `err.code` / `fix` / `docs`.
|
|
9
18
|
|
|
10
19
|
## What to read, in order (stop when you have enough)
|
|
11
20
|
1. This file: find the task in the entry table below.
|
|
12
21
|
2. The recipe the row points to (`recipes/NN-*.md`): how to do the task, with a working pattern.
|
|
13
|
-
3. `api/<module>.md` for signatures, options and data shapes (
|
|
22
|
+
3. `api/<module>.md` for signatures, options and data shapes (`API.md` is the index, `api/events.md` the events).
|
|
14
23
|
4. The game's own `GAMEMAP.md` (generated): what this game has, and "Read for this game".
|
|
15
|
-
5. When needed: `CODEMAP.md`
|
|
16
|
-
`COMMANDS.md` (commands, scenarios, folders) · `CONVENTIONS.md` (the conventions below in detail).
|
|
17
|
-
|
|
18
|
-
Generated docs (GAMEMAP, API.md, api/, CODEMAP, `types/generated/`) are never edited by hand; after changing code run `npm run map`.
|
|
24
|
+
5. When needed: `CODEMAP.md` · `THREE.md` (what the engine lacks: use three.js) · `PERF.md` · `COMMANDS.md` · `CONVENTIONS.md`.
|
|
19
25
|
|
|
20
26
|
## One thing, one entry point (don't build another)
|
|
21
|
-
Three outward concepts: **Scene** (what is in the world
|
|
22
|
-
|
|
23
|
-
Patches, ops and world records are the scene's inner machinery.
|
|
27
|
+
Three outward concepts: **Scene** (what is in the world; content packs are part of it), **Assets** (models, textures, sounds, fonts),
|
|
28
|
+
**Style** (the look; material roles are labels inside it). Patches, ops and world records are the scene's inner machinery.
|
|
24
29
|
|
|
25
30
|
### Scene
|
|
26
31
|
| To do | Use | Recipe |
|
|
27
32
|
|---|---|---|
|
|
28
|
-
| New game, project layout | `npm run new-game name`, `createEngine({ canvas, style })`, `engine.use(...)`, `engine.start()` | `recipes/01-new-game.md` |
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
|
|
|
54
|
-
| Quests, objective markers | content `quests` (a step's `target` is marked automatically), `engine.quests`, `engine.hud.marker()` | `recipes/04-quests.md` |
|
|
55
|
-
| Player and characters | `engine.player`, `engine.characters.createPlayer({ ...presets.player.thirdPerson, model })` | `recipes/13-animation.md` |
|
|
56
|
-
| Camera | `openWorld({ camera })` (required), `engine.setCamera(...)`, `engine.cameraRig` | `recipes/21-camera.md` |
|
|
57
|
-
| Action game: hp, attacks, enemy AI, drops, death (no combat rules in the engine) | your ops (`player.attack`) + `world.simulate` + `inventory.spawnPickup`; `examples/action/` | `recipes/32-action-game.md` |
|
|
33
|
+
| New game, project layout, canvas inside a page or editor panel | `npm run new-game name`, `createEngine({ canvas, style })`, `engine.use(...)`, `engine.start()` | `recipes/01-new-game.md` |
|
|
34
|
+
| Preset parts on / off, blank game | `openWorld({ camera: 'follow', sky: {...}, debug: false })`, `new-game name --blank` | `recipes/01-new-game.md` |
|
|
35
|
+
| Put something in the scene | `engine.add(obj, { id })`, `engine.spawn(name, at)`, content props | `recipes/40-scene.md` |
|
|
36
|
+
| Game content data, content packs | `engine.content.load(data, { places })`, `load([base, dlc])`, rules in `content/rules.js` | `recipes/20-content-actions-save.md` |
|
|
37
|
+
| Reusable object definitions (prefabs) | content `templates`; props `{ template, x, z }` | `recipes/30-templates.md` |
|
|
38
|
+
| Props, many repeated objects, delete an object, static batching | content `props` / `vegetation`, `engine.remove(obj)`, `engine.batching` (`batch: false`, `tint`) | `recipes/05-props-bake.md` |
|
|
39
|
+
| What is this thing, where is it defined (point -> id) | `engine.pick(x, y).thing`, `engine.world.origin(id)`, `engine.thing(id).explain()` | `recipes/30-templates.md` §5 |
|
|
40
|
+
| Saved / far-away objects, the player record, stream in, teleport | `engine.world`, `player.placeAt()`, `engine.stream.add / teleport / source` | `recipes/18-world.md` |
|
|
41
|
+
| Blender level, grass and trees without terrain | `engine.level`, `npm run assets -- check`, `vegetation({ area })`, `engine.vegetation.rebuild()` | `recipes/10-blender-level.md` |
|
|
42
|
+
| Terrain generator, ground height, terrain editing | `terrain({ height, groundType })`, `terrainPreset()`, `engine.surface(x, z)`, `engine.ground`, `engine.terrain.edit()` | `recipes/28-terrain.md` |
|
|
43
|
+
| Ground up close: blurry ground, brush detail, near grass and its distance fade, blurry render scale (options, diagnosis) | `detail`, `colorResolution`, `fade`, `describe().render.scale` | `recipes/53-ground-up-close.md` |
|
|
44
|
+
| Ground color borders, mesh cut, lighting normals | `terrain({ shading: 'texture', colorResolution, normals, diagonal })` | `recipes/37-terrain-look-hooks.md` |
|
|
45
|
+
| Island, floating rock, world with an edge | `terrain({ shape: { mask, edge, side, bottom } })`, `engine.ground.has`, event `terrain:void` | `recipes/42-terrain-shape.md` |
|
|
46
|
+
| Grid placement, tile grid, player-changed ground, plots, dig, build on cells | `engine.grids.add / define`, `terrain.edit`, ops `grid.place / move / remove` | `recipes/29-grid.md` |
|
|
47
|
+
| Grid field as a function (height, moisture, density, walkable), read a grid from an image (PNG 8/16-bit) | `sampleGrid(data, { width, height, cellSize, origin, interp })`, `await engine.assets.gridFromImage(nameOrUrl, { channel, range, bits })` | `recipes/37-terrain-look-hooks.md` §7 |
|
|
48
|
+
| Collision, fences, rivers, physics, vehicles | `engine.collision` (`addSegment`, `addBlocked`, `lineClear`), `engine.rigid` | `recipes/11-vehicles.md` |
|
|
49
|
+
| Pathfinding, navmesh, "can walk there" | `engine.characters.findPath`, `engine.nav`, `createEngine({ movement })` | `recipes/12-navmesh.md` |
|
|
50
|
+
| Interaction prompts (talk, pick up, open a door or chest), trigger zones | `engine.interactions`, `interactions({ ...presets.interactions.nearest })`, `engine.triggers` | `recipes/20-content-actions-save.md` |
|
|
51
|
+
| Ray / mouse picking, shooting, lock-on | `engine.raycast / pick`, `engine.rays.addStatic`, `engine.entities`, `engine.particles` | `recipes/19-shooting-picking.md` |
|
|
52
|
+
| NPCs and what they do, dialogue | content `npcs` (`behavior`), `engine.npcs.behavior`, content `dialogues`, `engine.dialogue` | `recipes/02-npc.md` |
|
|
53
|
+
| Items, pickups, inventory, chests, shops, gold | content `items` / `pickups`, `engine.inventory` (`container`, `transfer`), currency item + ops | `recipes/03-items-pickups.md`, `22-shop-gold.md` |
|
|
54
|
+
| Quests, objective markers | content `quests`, `engine.quests`, `engine.hud.marker()` | `recipes/04-quests.md` |
|
|
55
|
+
| Player and characters (bodies are assets) | `engine.player`, `createPlayer({ ...presets.player.thirdPerson, model: 'humanoid' })` (a generator from an asset pack; a GLB name; `{ rig }`; none = gray capsule) | `recipes/13-animation.md` |
|
|
56
|
+
| Camera, orthographic camera | `openWorld({ camera })` (required), `engine.setCamera(...)`, `engine.cameraRig`, `engine.takeCamera` | `recipes/21-camera.md` |
|
|
57
|
+
| Action game: hp, attacks, enemy AI, drops | your ops + `world.simulate` + `inventory.spawnPickup`; `examples/action/` | `recipes/32-action-game.md` |
|
|
58
|
+
| Use three.js directly, own renderer, no default lights | `engine.scene / renderer / camera`, `createEngine({ lights: false, renderer })` | `recipes/40-scene.md` §8, `50-own-renderer.md` |
|
|
58
59
|
|
|
59
60
|
### Assets
|
|
60
61
|
| To do | Use | Recipe |
|
|
61
62
|
|---|---|---|
|
|
62
|
-
| Art assets, asset packs, fonts, loading, what failed | `engine.assets.manifest({ models, textures, sounds, fonts })
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
| Sound, buses, ambience
|
|
63
|
+
| Art assets, asset packs, fonts, loading, what failed | `engine.assets.manifest({ models, textures, sounds, fonts })`, `engine.loading`, `threedog loading` | `recipes/05-props-bake.md` |
|
|
64
|
+
| Real art assets: Blender -> GLB, baked textures | `threedog assets check [--against old.glb]`, `engine.assets.manifest({ models })` | `recipes/46-blender-art-route.md` |
|
|
65
|
+
| Skeletal animation, far detail (HLOD) | `engine.assets.animate(model, config)`, `anim.sync`, `character.onPose(fn)`, `engine.hlod` | `recipes/13-animation.md`, `15-perf.md` |
|
|
66
|
+
| Sound, buses, ambience, music, footsteps | `createEngine({ audio })`, `engine.audio.sfx(name)`, `engine.ambience`, `engine.music` | `recipes/31-audio.md` |
|
|
66
67
|
|
|
67
|
-
### Style
|
|
68
|
+
### Style and look
|
|
68
69
|
| To do | Use | Recipe |
|
|
69
70
|
|---|---|---|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
| Water depth
|
|
74
|
-
| Shadows too blurry near the camera | `
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
| Environment lighting (PBR reflections, ambient from the sky or an HDR) | `engine.sky.setEnvironment({ source: 'sky' \| asset name })` | `recipes/34-environment-lighting.md` |
|
|
82
|
-
| Color grading, grain, vignette, depth of field; outline modes | `@threedog/post-effects`: `bloom`, `ao`, `outline`, `dof`, `lut`… (`style: [lowpoly, postAdd(vignette({ enabled: true }), grain({ enabled: true }))]`); a style pack never imports another style pack, shared effects come from post-effects (R34) | `recipes/09-style-pack.md` |
|
|
83
|
-
| Many lights (torches, lamps, muzzle flashes) | `lightPool({ point })`, `engine.lightPool.add(obj, { color, intensity, distance, flicker, glow })` | `recipes/09-style-pack.md` |
|
|
84
|
-
| Day, night, seasons, sky, weather | `engine.sky` (`at / between / daily / onSeason`, `isDay`; fixed unless `sky({ dayLength })`), `engine.weather` (`weather({ types })`) | `recipes/08-weather-sky.md` |
|
|
85
|
-
| Water | `engine.water` | `recipes/08-weather-sky.md` |
|
|
86
|
-
| Shadow type and softness | `createEngine({ shadowType: 'basic' \| 'pcf' \| 'vsm' })`, `engine.sky.setShadow({ type, radius })`; switching recompiles materials | `recipes/15-perf.md` |
|
|
71
|
+
| Change any look at run time: tone, lights, fog, sky, clouds, shadow, wind, ground, water, weather, post | `engine.look.<part>.set / patch / replace` (`engine.catalog('look')`); own plain three.js: when to | `recipes/52-look.md`, `40-scene.md` §8 |
|
|
72
|
+
| Set the starting look: pack, materials, mixing packs, exposure, sky layers | style pack (`style: [basePack, { sky }]`), `engine.makeMaterial('role', {...})`, `style.palette`, `postAdd` / `postRemove` | `recipes/09-style-pack.md`, `36-sky-ground-plant-looks.md`, `48-make-material.md` |
|
|
73
|
+
| Material and lighting shader patches, toon ramp, surface detail (grain, paper, strokes, dabs, texture, own glsl), colored shadows (shadowTint, rim, wrap), wind, fog hooks | `applyEffects`, `look.surface.patch`, `look.wind.patch`, `look.fog.patch` | `recipes/43-shader-patches-surface-looks.md`, `38-environment-look-hooks.md` |
|
|
74
|
+
| Water depth / foam, rain and snow shapes, own weather particles, snow cover, backdrop | `look.water`, `look.weather`, `style.weather.snow.cover`, `style.sky.backdrop` | `recipes/44-water-weather-look-hooks.md`, `47-island-snow-backdrop.md` |
|
|
75
|
+
| Shadows too blurry near the camera; shadow type | `look.shadow.set({ cascades: 3, type })` | `recipes/45-cascaded-shadows.md`, `15-perf.md` |
|
|
76
|
+
| Environment lighting (PBR reflections, HDR) | `look.env.replace('sky' \| asset \| false)`, `look.env.set({ intensity, rotation })` | `recipes/34-environment-lighting.md` |
|
|
77
|
+
| Color grading, grain, vignette, DOF, outline, bloom | `@threedog/post-effects`, `postAdd(vignette())`, `engine.post`, `look.post.set` | `recipes/52-look.md#post-effect-chain` |
|
|
78
|
+
| Many lights (torches, lamps, muzzle flashes) | `lightPool({ point })`, `engine.lightPool.add(obj, { color, intensity, distance, flicker })` | `recipes/09-style-pack.md` §1b |
|
|
79
|
+
| Day, night, seasons, sky, weather, water, isDay | `engine.sky` (`at / between / daily / onSeason`), `engine.weather`, `engine.water` | `recipes/08-weather-sky.md` |
|
|
80
|
+
| Who set tone / post / lights; why does it look like this | `engine.describe().look` (value, by, at), `describe().render`, `debug.view('albedo'\|'lighting'\|'shadow'\|'normals')` | `recipes/52-look.md`, `16-dev-bridge.md` |
|
|
81
|
+
| New style from a reference image | `threedog style palette <image>`, `npm run new-style`, `style check`, `style compare <ref> <shot>` | `recipes/35-style-from-reference.md` |
|
|
87
82
|
|
|
88
83
|
### Rules and flow
|
|
89
84
|
| To do | Use | Recipe |
|
|
90
85
|
|---|---|---|
|
|
91
|
-
| Player actions, UI buttons that change state | `engine.ops.define('noun.verb', { can, run, undo })`, `ops.run(name, args)
|
|
92
|
-
|
|
|
86
|
+
| Player actions, UI buttons that change state | `engine.ops.define('noun.verb', { can, run, undo })`, `ops.run(name, args)` | `recipes/23-ops.md` |
|
|
87
|
+
| What can this game do (modules, ops, saves, time) | `engine.catalog(id?)`, `threedog catalog [id]` | `recipes/51-capability-catalog.md` |
|
|
88
|
+
| Why can't / what can the player do here | `engine.explain(...)`, `engine.inspect(at?)`, `describeText()`, scenario tests | `recipes/23-ops.md` |
|
|
93
89
|
| Story flags, counters | `engine.vars` (`setFlag / flag / bump / counter`, saved) | `recipes/20-content-actions-save.md` |
|
|
94
|
-
| Saves | `engine.saves.register(key, { save, load })
|
|
95
|
-
| New game / continue / back to title / retry | `await engine.session.newGame() / load(slot)`, `quit()
|
|
96
|
-
| Scene flow, fades, pausing
|
|
97
|
-
|
|
|
98
|
-
|
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
|
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
| Drive the game from an MCP client (Claude Code, Cursor) | `claude mcp add threedog -- npx threedog mcp` (`js` only with `--allow-js`) | `recipes/16-dev-bridge.md` §10 |
|
|
108
|
-
| Describe state for tests | `engine.describe()`, `engine.describe.add(name, fn)`, `describeText()` | `recipes/16-dev-bridge.md` |
|
|
109
|
-
| An engine error: what to do | `err.code` / `err.fix` / `err.docs` (also `engine.error`, `.threedog/errors.log`) | `recipes/16-dev-bridge.md` §8 |
|
|
110
|
-
| What is this thing / will a save keep it | `engine.add(obj, { id })` (only an id makes it saveable), `engine.thing(id \| obj)`, `pick().thing`, ops `thing.set` / `thing.remove` (undoable) | `recipes/41-thing-registry.md` |
|
|
111
|
-
| Your own module | `{ name, install, fixed, frame, describe, afterLoad }` + `engine.use` | `recipes/14-custom-module.md` |
|
|
112
|
-
| A module will not install, or runs in the wrong order | `engine.use(a, b)` installs a batch atomically; `before` / `after` sort inside one `stage`; `critical: true` | `recipes/14-custom-module.md` |
|
|
113
|
-
| Heavy loops, workers, background results | `engine.jobs.add(function* () {})`, `engine.threads.lane(...)`, `engine.commits` | `recipes/15-perf.md` |
|
|
114
|
-
| Performance budget, debug panel, where the time goes | `engine.budget`, `engine.debug`, `describe().perf`, `threedog capture` | `recipes/15-perf.md` |
|
|
115
|
-
| Random operation sequences, order-dependent bugs | the engine repository's `Properties` specs (fast-check) | `recipes/23-ops.md` |
|
|
90
|
+
| Saves: save game, load game, progress, slot, autosave, 存档 | `engine.saves.register(key, { save, load })`, `saves.autosave(minutes)` | `recipes/20-content-actions-save.md` |
|
|
91
|
+
| New game / continue / back to title / retry | `await engine.session.newGame() / load(slot)`, `quit()`, `session.track(h)` | `recipes/07-flow-scenes-pause.md` |
|
|
92
|
+
| Scene flow, fades, pausing, cutscenes, tweens | `engine.flow`, `fadeScreen(engine, to, s)`, flow `'paused'` (`engine.freeze(owner)`; not `engine.pause`, which stops rendering), `engine.timeline.tween` | `recipes/07-flow-scenes-pause.md` |
|
|
93
|
+
| Time, timers, skipping time | `engine.clock` (`after / every`), `await engine.skip({ to: '06:00' })`, `checkSkip`, `checkSave` | `recipes/06-clock-events.md` |
|
|
94
|
+
| Events, cause chain, randomness | `engine.events.on / emit`, `engine.random` (saved), `events.trace(name)`, `traceFocus(id)` | `recipes/06-clock-events.md` |
|
|
95
|
+
| Keys, input contexts, open / interact key; text and languages (`engine.t`, `engine.i18n`) | `input.define('action', keys, label)`, `engine.input.push('menu')`, `input.simulate` | `recipes/26-ui-parts.md` |
|
|
96
|
+
| Screen UI parts, Esc layering, settings menu, labels over the world, photo mode | `createEngine({ ui })`, `engine.ui.set`, `engine.hud`, `engine.settings`, `worldToScreen()`, `engine.photo` | `recipes/26-ui-parts.md` |
|
|
97
|
+
| Drive and test the running game | dev bridge: `applyState`, `defineState`, `status`, `verify <scenario>`, `scene --hidden`, `state`, `step`, `skip` | `recipes/16-dev-bridge.md` |
|
|
98
|
+
| Fixed camera views, same shot before / after | `engine.views.define`, `shot --view name --compare` | `recipes/46-blender-art-route.md` |
|
|
99
|
+
| Drive the game from an MCP client | `claude mcp add threedog -- npx threedog mcp` | `recipes/16-dev-bridge.md` §10 |
|
|
100
|
+
| Will a save keep it; hide / recolor on screen only | `engine.add(obj, { id })`, `engine.thing(id)`, ops `thing.set / remove`, `debug.override(owner, id, {...})` | `recipes/41-thing-registry.md` |
|
|
101
|
+
| Your own module, own game system (crafting, spawner, machine, crop growth) | `{ name, install, fixed, frame, describe, afterLoad }`, `engine.use`; `before` / `after`, `critical`; save, `skip` hook, ops `can` | `recipes/14-custom-module.md`, `49-game-module-contract.md` |
|
|
102
|
+
| Heavy loops, workers; performance budget, debug panel | `engine.jobs.add`, `engine.threads.lane`, `engine.commits`, `engine.budget`, `engine.debug.panel`, `threedog capture` | `recipes/15-perf.md` |
|
|
116
103
|
| Co-op multiplayer | `engine.use(net({ role, transport }))`, `engine.net` | `recipes/27-net.md` |
|
|
117
104
|
|
|
118
|
-
##
|
|
119
|
-
`npm run
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
105
|
+
## When something happens -> which tool
|
|
106
|
+
Tools via MCP or `node node_modules/@threedog/tools/bin/threedog.mjs <cmd>` (not npx: +2.5 s a call); every command is in `COMMANDS.md`. Order: `npm run map` -> `npm run check` (each change) -> related tests (`npm test -- name`). Errors: `.threedog/errors.log`, **read first when something breaks**.
|
|
107
|
+
- Not sure the engine has X -> `threedog how "<task in English>"`, `threedog catalog [id]`.
|
|
108
|
+
- What is this object / why can't I click it -> `thing(id).explain()`.
|
|
109
|
+
- An action failed -> the failure's `code`, `facts`, `nextActions`; `engine.explain({ op })` for what blocks it.
|
|
110
|
+
- The picture looks wrong -> `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')`, `describe().look`.
|
|
111
|
+
- Matching a reference image -> `style palette <ref>`, `style compare <ref> <shot>`, `shot --view name --compare`.
|
|
112
|
+
- The game seems stuck -> `runState`, `describe().time.heldBy`.
|
|
113
|
+
- What caused this -> `events.trace(name)`, `traceFocus(id)`.
|
|
114
|
+
- Verifying a change -> `describeText()` for logic, screenshots only for looks; `threedog js --file steps.js` with asserts; `threedog verify <scenario>` (read its "not proven" part).
|
|
115
|
+
- Saves or time skips broken -> `checkSave`, `checkSkip`.
|
|
116
|
+
- Move a placed thing for good -> `threedog content set <id> x=12` (edits `content/*.js`; bridge ops last this session only).
|
|
117
|
+
- Swapped a model -> `threedog assets check new.glb --against old.glb`.
|
|
118
|
+
- Commands slow -> plain node, or `threedog session`.
|
|
127
119
|
|
|
128
|
-
## Conventions (
|
|
120
|
+
## Conventions (detailed in `CONVENTIONS.md`)
|
|
129
121
|
- **A position is one argument** (Vector3, Object3D, `[x, y, z]` or `{ x, z }`); sizes and counts go in the options object after it.
|
|
130
|
-
- **Registrations return a handle**; `h.remove()` undoes it.
|
|
131
|
-
- **
|
|
132
|
-
- **
|
|
133
|
-
- **
|
|
134
|
-
- **Input**: gameplay keys in the fixed step, UI keys in the frame hook; never `addEventListener('keydown')` for gameplay.
|
|
135
|
-
- **Gameplay state** (world, containers, vars, quests) changes only in fixed steps or ops.
|
|
136
|
-
- **The engine owns** sky lights, fog and the camera every frame; adjust with `engine.sky.modify` / `engine.cameraOverride`.
|
|
137
|
-
- **Two doors, one scene**: plain three.js (`engine.add(mesh, { id })`) and templates (`engine.spawn`, content props) land in the same
|
|
138
|
-
scene (`recipes/40-scene.md`). Put what must be saved and edited without code in content (stable ids: `npx threedog content ids --write`,
|
|
139
|
-
`content/renames.js`); <!-- r18-ignore-line --> the check (R33) flags only startup calls that would repeat after a load. <!-- r18-ignore-line -->
|
|
140
|
-
- **Look parameters** belong in the style pack or content, never in logic; materials via `makeMaterial`.
|
|
141
|
-
- **Units** are meters, Y up, north -Z; characters face +Z.
|
|
142
|
-
- **Errors say how to fix it**: an old form throws with the fix.
|
|
122
|
+
- **Registrations return a handle**; `h.remove()` undoes it. **Ready is the boolean `ready`**. **Event names are `noun:action`**.
|
|
123
|
+
- **Fixed step vs frame**: `onFixed` runs game time (damage, AI, timers); `onFrame` is presentation (animation, camera feel, HUD).
|
|
124
|
+
- **The engine owns** sky lights, fog and the camera every frame (CONVENTIONS "Adjusting sky brightness").
|
|
125
|
+
- **Units** are meters, Y up, north -Z; characters face +Z. **Errors say how to fix it**: an old form throws with the fix.
|
|
143
126
|
|
|
144
127
|
## Stability
|
|
145
|
-
|
|
146
|
-
`grids()` · `engine.terrain.edit` · `world.simulate(kind, { worker: true })` · `engine.post.add` · `engine.stream.source` · `hlod()` · `engine.ops.guard / allow`.
|
|
147
|
-
|
|
148
|
-
## Hard rule for game content
|
|
149
|
-
Game content (dialogues, quests, items, map layout) lives in the game's own `content/` folder, never inside the engine.
|
|
128
|
+
May change before 1.0: `net()` · `engine.threads` · `grids()` · `terrain.edit` · `world.simulate({ worker })` · `look.post.add` · `stream.source` · `hlod()` · `ops.guard / allow`.
|