threedog 1.4.0 → 2.1.0
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/CHANGELOG.md +48 -0
- package/README.md +13 -7
- package/bin/threedog.mjs +42 -0
- package/core/assets/assetEntry.js +1 -1
- package/core/assets/assetPart.js +1 -1
- package/core/base/Events.js +7 -1
- package/core/base/errorCodes.js +1 -1
- package/core/base/events.generated.js +2 -2
- package/core/engine/Engine.js +11 -7
- package/core/engine/copies.js +1 -1
- package/core/engine/moduleTypes.js +1 -1
- package/core/engine/modules.js +23 -6
- package/core/engine/page.js +1 -0
- package/core/engine/services.js +5 -3
- package/core/engine/startup.js +4 -1
- package/core/inspect/DebugOverrides.js +2 -2
- package/core/inspect/InspectPerf.js +1 -1
- package/core/inspect/describeRender.js +0 -7
- package/core/inspect/metadata.generated.js +139 -50
- package/core/inspect/pictureChecks.js +2 -27
- package/core/ops/control.js +3 -3
- package/core/ops/holds.js +8 -3
- package/core/ops/sharedPoint.js +11 -2
- package/core/saves/saveApply.js +3 -3
- package/core/saves/session.js +20 -4
- package/core/scene/adaptive.js +5 -2
- package/core/scene/pixelRatio.js +39 -17
- package/core/scene/sceneMethods.js +1 -1
- package/core/scene/things.js +3 -2
- package/core/scene/tier.js +2 -16
- package/core/scene/view.js +14 -0
- package/core/time/skip.js +1 -1
- package/docs/AI.md +2 -2
- package/docs/CODEMAP.md +8 -8
- package/docs/COMMANDS.md +2 -2
- package/docs/CONVENTIONS.md +1 -0
- package/docs/THREE.md +1 -1
- package/docs/api/ambience.md +2 -2
- package/docs/api/cameraRig.md +7 -0
- package/docs/api/engine.md +6 -3
- package/docs/api/events.md +3 -3
- package/docs/api/particles.md +1 -1
- package/docs/api/photo.md +5 -0
- package/docs/api/pickups.md +1 -1
- package/docs/api/post.md +1 -1
- package/docs/api/rigid.md +1 -1
- package/docs/api/sky.md +11 -1
- package/docs/api/terrain.md +19 -0
- package/docs/api/tools.md +1 -1
- package/docs/recipes/01-new-game.md +1 -1
- package/docs/recipes/03-items-pickups.md +1 -1
- package/docs/recipes/05-props-bake.md +1 -1
- package/docs/recipes/06-clock-events.md +3 -10
- package/docs/recipes/07-flow-scenes-pause.md +3 -4
- package/docs/recipes/09-materials-lights-models.md +1 -1
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/{11-vehicles.md → 11-physics.md} +13 -5
- package/docs/recipes/12-navmesh.md +3 -3
- package/docs/recipes/14-custom-module.md +6 -5
- package/docs/recipes/15-perf.md +1 -1
- package/docs/recipes/16-dev-bridge.md +1 -1
- package/docs/recipes/18-world.md +1 -1
- package/docs/recipes/20-content-actions-save.md +0 -1
- package/docs/recipes/21-camera.md +11 -1
- package/docs/recipes/26-ui-parts.md +2 -2
- package/docs/recipes/27-net.md +1 -1
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/34-environment-lighting.md +5 -3
- package/docs/recipes/40-scene.md +1 -1
- package/docs/recipes/44-water-weather-hooks.md +1 -1
- package/docs/recipes/45-cascaded-shadows.md +6 -3
- package/docs/recipes/51-capability-catalog.md +1 -1
- package/docs/recipes/52-around-the-picture.md +8 -8
- package/docs/recipes/53-ground-up-close.md +2 -2
- package/docs/recipes/55-mods-time-wrap.md +6 -8
- package/docs/recipes/57-control.md +1 -1
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +7 -7
- package/docs/recipes/62-picture-code.md +13 -17
- package/examples/action/GAMEMAP.md +4 -2
- package/examples/action/picture/lights.js +3 -2
- package/examples/perf-island/GAMEMAP.md +2 -1
- package/examples/perf-island/picture/lights.js +3 -2
- package/examples/styletest/GAMEMAP.md +2 -2
- package/examples/styletest/picture/env.js +1 -2
- package/examples/techniques/contact-shadows/README.md +1 -1
- package/examples/techniques/day-night-grade/picture/lights.js +3 -1
- package/examples/techniques/interior-light/README.md +1 -1
- package/examples/techniques/interior-light/picture/lights.js +4 -2
- package/examples/techniques/modular-building/picture/lights.js +3 -2
- package/examples/techniques/night-lights/README.md +1 -1
- package/examples/techniques/night-lights/picture/lights.js +3 -1
- package/examples/techniques/night-lights/picture/post.js +2 -2
- package/examples/techniques/outlines-and-rim/README.md +1 -1
- package/examples/techniques/outlines-and-rim/picture/lights.js +3 -2
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/techniques/procedural-animation/picture/lights.js +3 -1
- package/examples/techniques/procedural-surface/README.md +1 -1
- package/examples/techniques/procedural-surface/picture/lights.js +3 -1
- package/examples/techniques/stylized-shading/picture/lights.js +3 -1
- package/examples/techniques/wet-road/README.md +1 -1
- package/examples/techniques/wet-road/picture/lights.js +3 -1
- package/examples/webgpu-tsl/GAMEMAP.md +4 -2
- package/examples/webgpu-tsl/picture/lights.js +3 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/lights.js +3 -1
- package/examples/world/picture/post.js +2 -2
- package/llms.txt +33 -7
- package/modules/camera/common.js +22 -20
- package/modules/camera/contract.js +1 -1
- package/modules/characters/Character.js +2 -2
- package/modules/characters/NPC.js +7 -8
- package/modules/characters/index.js +8 -8
- package/modules/characters/mover.contract.js +1 -1
- package/modules/characters/movers/rapier.js +7 -9
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/player.js +11 -15
- package/modules/characters/playerStrings.js +1 -2
- package/modules/characters/seat.js +1 -1
- package/modules/collision/Collision.js +1 -1
- package/modules/collision/grid.js +1 -1
- package/modules/content/index.js +4 -3
- package/modules/content/models.js +1 -1
- package/modules/content/templates.js +3 -2
- package/modules/flow/index.js +8 -8
- package/modules/gameplay/Dialogue.js +1 -1
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/Quests.js +1 -0
- package/modules/gameplay/inventory.contract.js +1 -1
- package/modules/gameplay/pickups.js +1 -1
- package/modules/gameplay/questLog.js +0 -1
- package/modules/grid/index.js +1 -1
- package/modules/grid/tiles.js +6 -3
- package/modules/hud/index.js +2 -2
- package/modules/level/contract.js +2 -2
- package/modules/level/index.js +1 -1
- package/modules/music/Music.js +1 -1
- package/modules/nav/index.js +1 -1
- package/modules/net/sync.js +1 -1
- package/modules/particles/Particles.js +12 -5
- package/modules/particles/effect.js +17 -3
- package/modules/photo/pathTrace.js +1 -1
- package/modules/rigid/RigidBodies.js +23 -9
- package/modules/rigid/ragdoll.js +1 -1
- package/modules/rigid/sync.js +14 -0
- package/modules/settings/Settings.js +3 -2
- package/modules/settings/apply.js +4 -3
- package/modules/settings/sections.js +1 -1
- package/modules/sky/Sky.js +9 -4
- package/modules/sky/environment.js +5 -3
- package/modules/terrain/index.js +1 -2
- package/modules/timeline/Timeline.js +9 -6
- package/modules/vegetation/Vegetation.js +1 -1
- package/modules/vegetation/index.js +1 -1
- package/modules/weather/weatherDraw.js +1 -2
- package/modules/world/World.js +1 -0
- package/modules/world/index.js +1 -0
- package/modules/world/persist.js +1 -1
- package/package.json +6 -2
- package/render/PostFX.js +17 -12
- package/render/fx/postWebGPU.tsl.js +2 -1
- package/render/lightmap.js +1 -1
- package/render/lights.js +1 -2
- package/render/neutral.js +1 -1
- package/render/patches.js +3 -3
- package/render/probes.js +27 -2
- package/render/shaderErrors.js +1 -1
- package/render/shadows.js +1 -3
- package/types/core.d.ts +16 -9
- package/types/gameplay.d.ts +8 -3
- package/types/generated/modules/sky/Sky.d.ts +4 -4
- package/types/generated/render/PostFX.d.ts +2 -2
- package/types/generated/ui/UI.d.ts +2 -1
- package/types/physics.d.ts +1 -1
- package/types/world.d.ts +4 -2
- package/ui/UI.js +18 -14
- package/ui/cursor.js +2 -2
- package/examples/action/.threedog/content-index.json +0 -1
- package/examples/perf-island/.threedog/content-index.json +0 -1
- package/examples/plain-picture/.threedog/content-index.json +0 -1
- package/examples/rc2d/.threedog/content-index.json +0 -1
- package/examples/styletest/.threedog/content-index.json +0 -1
- package/examples/webgpu-tsl/.threedog/content-index.json +0 -1
- package/examples/world/.threedog/content-index.json +0 -1
package/modules/camera/common.js
CHANGED
|
@@ -25,7 +25,9 @@ import { warnOnce } from '../../core/base/validate.js';
|
|
|
25
25
|
|
|
26
26
|
// the takeover calls the owned-camera warning quotes (core/ops/owned.js): takeCamera is the one explicit entry (its remove() gives the camera back);
|
|
27
27
|
// back is the hand-back for a camera the engine yielded to a direct write (that takeover has no handle)
|
|
28
|
-
|
|
28
|
+
// set: the one additive path (screen shake, recoil, a bob): offset the drawn frame only, so the rig keeps driving and the owned check sees its own value
|
|
29
|
+
const LEVELS = { manual: "const cam = engine.takeCamera('me') (cam.remove() gives it back)", back: "engine.autoView.manual('camera', false)",
|
|
30
|
+
set: "for a shake or offset, add it inside engine.onRender and put the saved pose back in engine.onRender(fn, { when: 'after' }) (recipe 21 \"Screen shake\")" };
|
|
29
31
|
|
|
30
32
|
/** True during a cutscene takeover, and updates engine.focus from the focus the owner supplied */
|
|
31
33
|
function applyOverride(e) {
|
|
@@ -267,25 +269,6 @@ export function rigModule(kind, opts) {
|
|
|
267
269
|
if (r.pitch !== undefined && r.kind === d.kind && Number.isFinite(d.pitch)) r.pitch = d.pitch;
|
|
268
270
|
},
|
|
269
271
|
});
|
|
270
|
-
// a new playthrough (newGame / load) starts with the camera as installed (kind, distance, every option), placed at the player instead of flying across the map.
|
|
271
|
-
// The same object, so a rig the game kept at boot stays the camera; its view is what the load just left on it (the part above, or a game part's load() writing the rig)
|
|
272
|
-
ctx.track(e.events.on('session:start', () => {
|
|
273
|
-
// a hold made by writing the camera has no handle and no one who will end it: it belonged to the playthrough that is over. A manual() hold is on purpose and stays
|
|
274
|
-
if (owned.mode === 'yielded') owned.manual(false);
|
|
275
|
-
// the view the load left is on the rig of the saved kind, and that may be a rig switched to at runtime (the cameraRig part above)
|
|
276
|
-
const old = c, { yaw, pitch } = c.kind === kind ? c : home;
|
|
277
|
-
old.onExit?.(); cache.clear();
|
|
278
|
-
setProjection(e);
|
|
279
|
-
setFov(e, fov0());
|
|
280
|
-
const built = make(kind, opts);
|
|
281
|
-
for (const k of Object.keys(home)) delete home[k];
|
|
282
|
-
c = e.cameraRig = Object.assign(home, built, yaw !== undefined && { yaw, pitch });
|
|
283
|
-
cache.set(kind, home);
|
|
284
|
-
// follows the player only if the game asked (addPlayer({ cameraFollow })), through the seat the load put it in: the rig was rebuilt after that seat was taken
|
|
285
|
-
const P = e.player, car = P?.cameraFollow ? P.vehicle : null;
|
|
286
|
-
c.onEnter?.(false); c.follow(car ? car.object : P?.cameraFollow ? P.root : null, car?.camera); fresh = true;
|
|
287
|
-
e.events.emit('camera:change', { kind, previous: old.kind }); // settings re-apply the player's sensitivity / fov to the rebuilt rig
|
|
288
|
-
}));
|
|
289
272
|
// a scenario put the player somewhere else (?at, ?pos): a rig that eases would open on a glide across the map; follow() puts it there at once
|
|
290
273
|
ctx.track(e.events.on('state:placed', () => { if (c.target) { c.follow(c.target); fresh = true; } }));
|
|
291
274
|
// The camera module places position / orientation every frame: a game that moves the camera directly takes it (the rig stops), warned once
|
|
@@ -302,6 +285,25 @@ export function rigModule(kind, opts) {
|
|
|
302
285
|
RIG_OWNED.set(e, owned);
|
|
303
286
|
return c;
|
|
304
287
|
},
|
|
288
|
+
// a new playthrough (newGame / load) starts with the camera as installed (kind, distance, every option), placed at the player instead of flying across the map.
|
|
289
|
+
// The same object, so a rig the game kept at boot stays the camera; its view is what the load just left on it (the part above, or a game part's load() writing the rig)
|
|
290
|
+
sessionStart(e) {
|
|
291
|
+
// a hold made by writing the camera has no handle and no one who will end it: it belonged to the playthrough that is over. A manual() hold is on purpose and stays
|
|
292
|
+
if (owned.mode === 'yielded') owned.manual(false);
|
|
293
|
+
// the view the load left is on the rig of the saved kind, and that may be a rig switched to at runtime (the cameraRig part above)
|
|
294
|
+
const old = c, { yaw, pitch } = c.kind === kind ? c : home;
|
|
295
|
+
old.onExit?.(); cache.clear();
|
|
296
|
+
setProjection(e);
|
|
297
|
+
setFov(e, fov0());
|
|
298
|
+
const built = make(kind, opts);
|
|
299
|
+
for (const k of Object.keys(home)) delete home[k];
|
|
300
|
+
c = e.cameraRig = Object.assign(home, built, yaw !== undefined && { yaw, pitch });
|
|
301
|
+
cache.set(kind, home);
|
|
302
|
+
// follows the player only if the game asked (addPlayer({ cameraFollow })), through the seat the load put it in: the rig was rebuilt after that seat was taken
|
|
303
|
+
const P = e.player, car = P?.cameraFollow ? P.vehicle : null;
|
|
304
|
+
c.onEnter?.(false); c.follow(car ? car.object : P?.cameraFollow ? P.root : null, car?.camera); fresh = true;
|
|
305
|
+
e.events.emit('camera:change', { kind, previous: old.kind }); // settings re-apply the player's sensitivity / fov to the rebuilt rig
|
|
306
|
+
},
|
|
305
307
|
frame(dt, e) {
|
|
306
308
|
const over = !!e.cameraOverride;
|
|
307
309
|
if (over !== was) { was = over; c.onOverride?.(over); }
|
|
@@ -9,7 +9,7 @@ export default {
|
|
|
9
9
|
fields: ['target'], // what follow() follows: a ragdoll checks it before borrowing the camera, and leaves a camera the game moved elsewhere
|
|
10
10
|
ops: [],
|
|
11
11
|
events: [],
|
|
12
|
-
saves: {},
|
|
12
|
+
saves: { cameraRig: 1 },
|
|
13
13
|
describe: true,
|
|
14
14
|
options: {},
|
|
15
15
|
probe: { setup: [], emits: [], state: null },
|
|
@@ -220,7 +220,7 @@ export class Character {
|
|
|
220
220
|
placeAt(position) {
|
|
221
221
|
this.engine.control?.endTasks(this, 'placed');
|
|
222
222
|
if (this.vehicle) this.exit({ force: true });
|
|
223
|
-
else if (this.recordId && this.engine.world
|
|
223
|
+
else if (this.recordId && this.engine.world.get(this.recordId)?.vehicle != null) this._writeSeat(null, null); // its record waited for a vehicle not built yet: the game put it elsewhere
|
|
224
224
|
return this._place(position);
|
|
225
225
|
}
|
|
226
226
|
/** @internal Put it there with no ending of its own: a link crossing, a step out of a vehicle */
|
|
@@ -374,7 +374,7 @@ export class Character {
|
|
|
374
374
|
}
|
|
375
375
|
/** Dispose this character completely: exit the vehicle first, release animation and mover, remove from the scene and dispose geometries and materials */
|
|
376
376
|
dispose() {
|
|
377
|
-
// a player made by addPlayer: its registry entry (st.players, keys, touch button,
|
|
377
|
+
// a player made by addPlayer: its registry entry (st.players, keys, touch button, worldLoad entry) goes first, and calls this again with _release cleared
|
|
378
378
|
if (this._release) { const r = this._release; this._release = null; r(); return; }
|
|
379
379
|
this.disposed = true; // a model still loading by asset name is dropped on arrival
|
|
380
380
|
this.engine.control?.endTasks(this, 'gone');
|
|
@@ -51,8 +51,6 @@ import { passesOf } from '../collision/grid.js';
|
|
|
51
51
|
const STRINGS = {
|
|
52
52
|
noInteract: 'NPC "{name}" has interact set, but the interactions() module is not installed: nothing can use it',
|
|
53
53
|
badInteract: 'npcs.add(): interact is { op: \'npc.talk\' } or { label, op, args, radius } (op: the op name the interact key runs); got {got}',
|
|
54
|
-
noWorld: 'NPCs need the world() module (facts live in engine.world): engine.use(world(), …, characters()); openWorld() already installs it. '
|
|
55
|
-
+ 'If you do not want NPCs, use characters({ npcs: false })',
|
|
56
54
|
notNpc: 'npcs.add(): id "{id}" is already used by a "{kind}" in world; give this NPC a different id',
|
|
57
55
|
sameName: 'npcs.add(): an NPC named "{name}" already exists (without id the name is the id, so the two would merge). '
|
|
58
56
|
+ 'Give each different NPC its own id, e.g. npcs.add({ id: "{name}_2", name: "{name}", … }); to update an existing NPC, add again with the same id',
|
|
@@ -145,10 +143,11 @@ export class NPCManager {
|
|
|
145
143
|
/** @internal */ this._byName = new Set(); // NPCs added this run without id, using the name as id (two with one name would be one record)
|
|
146
144
|
// on the event, not in remove(): world.remove(id) and thing.remove take NPCs too, and a later add of that id must not inherit the old model or trip the same-name check
|
|
147
145
|
track(engine.events.on('world:remove', ({ id }) => { this._runtime.delete(id); this._handles.delete(id); this._byName.delete(id); }));
|
|
148
|
-
// a load or new game is a new run, and it fires no world:remove: setup code adding the same names again is not a clash
|
|
149
|
-
track(engine.events.on('world:load', () => this._byName.clear()));
|
|
150
146
|
}
|
|
151
|
-
|
|
147
|
+
/** @internal the characters module's worldLoad step: a load or new game is a new run, and it fires no world:remove, so setup code adding the
|
|
148
|
+
* same names again is not a clash; the avoidance index is stale too */
|
|
149
|
+
_worldLoad() { this._byName.clear(); this.avoid._worldLoad(); }
|
|
150
|
+
get world() { return this.engine.world; }
|
|
152
151
|
|
|
153
152
|
/** Register the NPC model and simulation with world (called in characters init; add calls it first if npcs.add comes earlier)@internal */
|
|
154
153
|
setup() {
|
|
@@ -326,7 +325,7 @@ export class NPCManager {
|
|
|
326
325
|
}
|
|
327
326
|
/** Find by id or name (id first) */
|
|
328
327
|
get(idOrName) {
|
|
329
|
-
const W = this.engine.world;
|
|
328
|
+
const W = this.engine.world;
|
|
330
329
|
if (W.get(idOrName)?.kind === KIND) return this._handle(idOrName);
|
|
331
330
|
for (const r of W.records.values()) if (r.kind === KIND && r.name === idOrName) return this._handle(r.id);
|
|
332
331
|
return undefined;
|
|
@@ -334,11 +333,11 @@ export class NPCManager {
|
|
|
334
333
|
/** All NPCs (kind 'npc' records in world, including far ones and those in other levels) */
|
|
335
334
|
list() {
|
|
336
335
|
const W = this.engine.world, out = [];
|
|
337
|
-
|
|
336
|
+
for (const r of W.records.values()) if (r.kind === KIND) out.push(this._handle(r.id));
|
|
338
337
|
return out;
|
|
339
338
|
}
|
|
340
339
|
/** Current character model (Character) of an NPC; null if none */
|
|
341
|
-
character(id) { const o = this.engine.world
|
|
340
|
+
character(id) { const o = this.engine.world.view(id); return (o && this._views.get(o)?.ch) || null; }
|
|
342
341
|
|
|
343
342
|
/** @internal */
|
|
344
343
|
_handle(id) { let h = this._handles.get(id); if (!h) this._handles.set(id, h = new NPC(this, id)); return h; }
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// Characters module: player (keyboard/stick control, camera follow, footsteps, enter/exit vehicles) and NPCs (schedule, pathfinding, dialogue).
|
|
2
2
|
// The pathfinding entry for game code is engine.characters.findPath: uses the navmesh if nav is installed and ready, else A* (astar.js is an internal fallback, not
|
|
3
3
|
// exported).
|
|
4
|
-
// NPC facts live in engine.world (kind 'npc'), the model is just a presentation when near (see the top of NPC.js)
|
|
5
|
-
// already does).
|
|
4
|
+
// NPC facts live in engine.world (kind 'npc'), the model is just a presentation when near (see the top of NPC.js).
|
|
6
5
|
// The player is also a world record (id / kind both 'player'): position, facing, motion state and current vehicle live in the record and are saved with world;
|
|
7
6
|
// world splits near / far by it by default.
|
|
8
7
|
// Only the mover changes the player's position (Character.move / placeAt / enter / exit), then writes back to the record; loading places the player back by the
|
|
9
|
-
// record.
|
|
8
|
+
// record. Both are world records, so the module requires world(): use() says so at install, not addPlayer at runtime (openWorld() installs both).
|
|
10
9
|
// Vehicles are used through an interface (the { object, speed, drive(), seatPosition(), exitPosition() } returned by rigid.addWheeled); rigid is not imported
|
|
11
10
|
// here.
|
|
12
11
|
import { Character } from './Character.js';
|
|
@@ -248,7 +247,7 @@ const NPC_CONTENT = {
|
|
|
248
247
|
function describeCharacters(e, ctx, mgr) {
|
|
249
248
|
// with a model report by the model (merged with interaction points and world's own report for the same object into one), without a model report by data
|
|
250
249
|
// position
|
|
251
|
-
for (const r of mgr
|
|
250
|
+
for (const r of mgr ? e.world.query({ kind: 'npc', near: ctx.center, radius: ctx.radius, where: r => e.world.inZone(r) }) : []) {
|
|
252
251
|
ctx.near(e.world.view(r.id) ?? r.position, { id: r.id, name: r.name, kind: 'npc', state: r.state });
|
|
253
252
|
}
|
|
254
253
|
if (ctx.out.player) Object.assign(ctx.out.player, { swimming: e.player.swimming, grounded: e.player.grounded, facing: Math.round(e.player.facing * 100) / 100,
|
|
@@ -265,7 +264,7 @@ export function characters(opts = {}) {
|
|
|
265
264
|
return {
|
|
266
265
|
// before rigid: the player's move this step is in the physics step that follows (as when control was an onFixed)
|
|
267
266
|
content: { npcs: NPC_CONTENT },
|
|
268
|
-
name: 'characters', skipKind: 'none', type: 'actor', provides: ['characters'], params: CHARACTERS_PARAMS, options: opts, label: 'Characters', before: ['rigid'], noSkip: 'fixed steps paths, control holders and riders, none of which a time jump moves; schedules read the calendar clock', optional: ['cameraRig', 'calendar', 'interactions', 'dialogue', 'nav', 'collision', 'rigid'
|
|
267
|
+
name: 'characters', skipKind: 'none', type: 'actor', provides: ['characters'], params: CHARACTERS_PARAMS, options: opts, label: 'Characters', before: ['rigid'], noSkip: 'fixed steps paths, control holders and riders, none of which a time jump moves; schedules read the calendar clock', requires: ['world'], optional: ['cameraRig', 'calendar', 'interactions', 'dialogue', 'nav', 'collision', 'rigid'],
|
|
269
268
|
install(e, ctx) {
|
|
270
269
|
e.i18n.add(STRINGS); e.i18n.add({ 'zh-CN': { 'module.characters': '角色' }, en: { 'module.characters': 'characters' } });
|
|
271
270
|
// move.* are defined at module install: doc examples call engine.mod('move.speed', …) in setup before creating a character, and relying on the first Character's definition would give unknown-name
|
|
@@ -282,15 +281,16 @@ export function characters(opts = {}) {
|
|
|
282
281
|
listen(e, ctx, st);
|
|
283
282
|
return charactersApi(e, st, animation);
|
|
284
283
|
},
|
|
285
|
-
// NPC simulation and animation are driven by world (simulate / present update); here we only register with world at start
|
|
286
|
-
|
|
287
|
-
init(e) { if (st.mgr && e.world) st.mgr.setup(); },
|
|
284
|
+
// NPC simulation and animation are driven by world (simulate / present update); here we only register with world at start
|
|
285
|
+
init() { st.mgr?.setup(); },
|
|
288
286
|
// player control runs here (stage late: after every early onFixed and the gameplay stages); then carry riders by what moved since their own step
|
|
289
287
|
// (support.js): every platform mover of this step has run by now
|
|
290
288
|
// control holders' steps (the player's input, game steps) run here too, in that order: one move per held character per step (core/ops/control.js)
|
|
291
289
|
fixed(_dt, e) { st.paths.flush(); e.control.stepAll(); stepSeats(e); carryRiders(e, false); },
|
|
292
290
|
// a timeline or frame code moved a platform: carry now, so the picture never shows a rider sinking into or floating above it
|
|
293
291
|
frame(dt, e) { for (const p of st.players.values()) p.character.animate(dt); carryRiders(e, true); },
|
|
292
|
+
// world replaced wholesale (a load): NPC indexes first, then each player goes back to its record, in the order they were added
|
|
293
|
+
worldLoad() { st.mgr?._worldLoad(); for (const p of st.players.values()) p.worldLoad(); },
|
|
294
294
|
describe(e, ctx) { describeCharacters(e, ctx, st.mgr); },
|
|
295
295
|
// a player, a queued path and the control lookup all outlive install unless they are ended here; the player's record stays in world, as NPC records do
|
|
296
296
|
dispose(e) {
|
|
@@ -10,5 +10,5 @@ export default {
|
|
|
10
10
|
api: ['move'],
|
|
11
11
|
fields: ['name'],
|
|
12
12
|
position: { authority: 'solver', writers: { mover: 'move() writes character.root.position while the holder of the control slot drives it; it writes no record' } },
|
|
13
|
-
optional: { dispose: v => typeof v === 'function', leave: v => typeof v === 'function' },
|
|
13
|
+
optional: { dispose: v => typeof v === 'function', leave: v => typeof v === 'function', collider: v => typeof v === 'object', world: v => typeof v === 'object' },
|
|
14
14
|
};
|
|
@@ -6,6 +6,7 @@ import { steer, water, float, tryJump, tickJump, leaveGround, land, finish, stat
|
|
|
6
6
|
import { beginMove, endMove } from './support.js';
|
|
7
7
|
import { passesThrough } from '../../collision/grid.js';
|
|
8
8
|
import { warnOnce, DEV } from '../../../core/base/validate.js';
|
|
9
|
+
import { coded } from '../../../core/base/errorHints.js';
|
|
9
10
|
|
|
10
11
|
/** Create the 'rapier' mover (c is the character, fallback is the simple mover used when not ready) */
|
|
11
12
|
export function rapierMover(c, fallback) {
|
|
@@ -13,6 +14,7 @@ export function rapierMover(c, fallback) {
|
|
|
13
14
|
name: 'rapier', controller: null, body: null, collider: null,
|
|
14
15
|
move(dirX, dirZ, run, dt) {
|
|
15
16
|
const e = c.engine, r = e.rigid, p = c.root.position;
|
|
17
|
+
if (!r && e.ready && DEV) warnOnce(coded('module-requires', "character mover 'rapier' needs the rigid module: without it this character walks with the simple mover. Fix: engine.use(collision(), rigid())"));
|
|
16
18
|
if (!r?.ready || !r.readyAt(p)) return fallback.move(dirX, dirZ, run, dt);
|
|
17
19
|
const fresh = !m.controller || m.world !== r.world; // another world (newGame / load rebuilt it, a replaced rigid brought its own): the old controller went with the old one
|
|
18
20
|
if (fresh) setup(e, r);
|
|
@@ -34,8 +36,8 @@ export function rapierMover(c, fallback) {
|
|
|
34
36
|
else { c.vy += stat(c, 'gravity') * dt; dy = c.vy * dt; }
|
|
35
37
|
}
|
|
36
38
|
const wasGrounded = c.grounded;
|
|
37
|
-
// a collision-module collider with a layer this body passes is skipped (the same passesThrough the simple mover and paths use); no layers anywhere: no predicate
|
|
38
|
-
const through = c.passes && r.
|
|
39
|
+
// a collision-module collider with a layer this body passes is skipped (the same passesThrough the simple mover and paths use); no layers anywhere: no predicate
|
|
40
|
+
const through = c.passes && r.layered ? m.through : undefined;
|
|
39
41
|
m.controller.computeColliderMovement(col, { x: (c.velocity.x + (inh?.x ?? 0)) * dt, y: dy, z: (c.velocity.y + (inh?.y ?? 0)) * dt }, r.rapier.QueryFilterFlags.EXCLUDE_DYNAMIC | r.rapier.QueryFilterFlags.EXCLUDE_SENSORS, undefined, through);
|
|
40
42
|
const mv = m.controller.computedMovement();
|
|
41
43
|
p.x += mv.x; p.y += mv.y; p.z += mv.z;
|
|
@@ -75,16 +77,12 @@ export function rapierMover(c, fallback) {
|
|
|
75
77
|
const R = r.rapier, w = r.world, p = c.root.position;
|
|
76
78
|
m.world = w; // what the handles below belong to: the world object itself, since a count would match across two rigid modules
|
|
77
79
|
// built with the controller: a replaced rigid keeps its layered colliders in its own map, and a test kept from the first one would read every collider as "no layer"
|
|
78
|
-
m.through = hit => { const o = r.
|
|
80
|
+
m.through = hit => { const o = r.layerOf(hit); return !(o && passesThrough(o, c.passes)); };
|
|
79
81
|
if (c === e.player) {
|
|
80
82
|
m.body = r.playerBody; m.collider = r.playerCollider;
|
|
81
83
|
// the capsule is the character's radius (as for every other character, and for simple movers and paths), unless the game set rigid({ playerCapsule: { radius } }): that wins.
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
else if (c.radius !== r.playerCapsule.radius) {
|
|
85
|
-
r.playerCapsule = { ...r.playerCapsule, radius: c.radius };
|
|
86
|
-
m.collider.setRadius(c.radius); m.collider.setTranslationWrtParent({ x: 0, y: r.playerCapsule.halfHeight + c.radius, z: 0 });
|
|
87
|
-
}
|
|
84
|
+
const used = r.fitPlayerCapsule(c.radius);
|
|
85
|
+
if (DEV && used !== c.radius) warnOnce(`rigid({ playerCapsule: { radius: ${used} } }) differs from the player's radius ${c.radius}: the rapier collider uses ${used}, paths and the simple mover ${c.radius}. Set one of them, or make them equal`);
|
|
88
86
|
}
|
|
89
87
|
else {
|
|
90
88
|
const hh = r.playerCapsule.halfHeight;
|
|
@@ -53,9 +53,9 @@ export class NpcAvoid {
|
|
|
53
53
|
shove(this._acc, own.x - o.position.x, own.z - o.position.z, Math.sqrt(d2), this._min, rec.id < o.id ? 1 : -1);
|
|
54
54
|
};
|
|
55
55
|
track(engine.events.on('world:remove', ({ id }) => { const s = this._start.get(id); if (s) { this._grid?.delete(s); this._filed.delete(s); this._start.delete(id); } }));
|
|
56
|
-
// after load the simulation step count returns to the saved value, so the old index is stale
|
|
57
|
-
track(engine.events.on('world:load', () => { this._start.clear(); this._filed.clear(); this._grid?.clear(); this._gridN = -1; }));
|
|
58
56
|
}
|
|
57
|
+
/** @internal after a load the simulation step count returns to the saved value, so the old index is stale (NPCManager._worldLoad) */
|
|
58
|
+
_worldLoad() { this._start.clear(); this._filed.clear(); this._grid?.clear(); this._gridN = -1; }
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* Change settings: set(false) off, set(true) on, set({ radius, strength }) tune (pass only what changes; passing it means on). Read current values from on /
|
|
@@ -8,7 +8,7 @@ import { DEV_STRINGS, validControl } from './playerStrings.js';
|
|
|
8
8
|
import { vehicleById, seatFromRecord } from './seat.js';
|
|
9
9
|
|
|
10
10
|
/** The player's world record: its id and its kind */
|
|
11
|
-
|
|
11
|
+
const PLAYER = 'player';
|
|
12
12
|
|
|
13
13
|
/** Everything addPlayer refuses, before it touches the old player */
|
|
14
14
|
function checkOptions(e, st, opts) {
|
|
@@ -16,7 +16,6 @@ function checkOptions(e, st, opts) {
|
|
|
16
16
|
const control = opts.control;
|
|
17
17
|
if (control === undefined) throw codedError('player-control', DEV_STRINGS.noControl);
|
|
18
18
|
if (!validControl(control)) throw codedError('player-control', fmt(DEV_STRINGS.badControl, { got: JSON.stringify(control) ?? String(control) }));
|
|
19
|
-
if (!e.world) throw codedError('module-needs', DEV_STRINGS.noWorld);
|
|
20
19
|
if (opts.input !== undefined && !e.input.seats.includes(opts.input)) throw codedError('input-seat', 'characters.addPlayer(): input is a seat from engine.input.seat({ pad, keys })');
|
|
21
20
|
const id = opts.id ?? PLAYER;
|
|
22
21
|
if (opts.input) for (const [other, q] of st.players) if (other !== id && q.input === opts.input) throw codedError('input-seat', `characters.addPlayer(): this seat already drives player '${other}'`);
|
|
@@ -63,18 +62,15 @@ function inputStep(e, api, p, control, input) {
|
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
/**
|
|
65
|
+
/** What keeps the record and the player together when world is replaced wholesale: the characters module's worldLoad step calls it (index.js) */
|
|
67
66
|
function watchRecord(e, W, p, id) {
|
|
68
67
|
const begin = p.position.clone(), rest = p.saveMotion(); // a player made after start() is in no new-game state: this is how a new playthrough has it
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
else { if (e.session.replacing) { if (p.vehicle) p.exit({ force: true }); p.root.position.copy(begin); p.loadMotion(rest); } W.add({ id, kind: PLAYER, position: p.position, vehicle: null }); p._store(); }
|
|
76
|
-
}),
|
|
77
|
-
];
|
|
68
|
+
// place the player back by the record; if the save has no player record (saved before the player was created), add one from the current state
|
|
69
|
+
return () => {
|
|
70
|
+
const rec = W.get(id);
|
|
71
|
+
if (rec) placeByRecord(e, p, rec, id);
|
|
72
|
+
else { if (e.session.replacing) { if (p.vehicle) p.exit({ force: true }); p.root.position.copy(begin); p.loadMotion(rest); } W.add({ id, kind: PLAYER, position: p.position, vehicle: null }); p._store(); }
|
|
73
|
+
};
|
|
78
74
|
}
|
|
79
75
|
|
|
80
76
|
/**
|
|
@@ -102,17 +98,17 @@ export function addPlayer(e, api, st, opts) {
|
|
|
102
98
|
if (first) e.player = p;
|
|
103
99
|
if (p.cameraFollow && !p.vehicle) e.cameraRig?.follow(p.root);
|
|
104
100
|
// in the map before control.take: the control lookup finds a held character by id through it
|
|
105
|
-
const entry = { character: p, input, dispose: null };
|
|
101
|
+
const entry = { character: p, input, dispose: null, worldLoad: null };
|
|
106
102
|
st.players.set(id, entry);
|
|
107
103
|
p._release = () => entry.dispose(); // player.dispose() from the game is the same teardown as removePlayer
|
|
108
104
|
if (input !== e.input) input.actor = id;
|
|
109
105
|
const held = e.control.take(p, { owner: 'player-input', layer: 'base', step: inputStep(e, api, p, opts.control, input) });
|
|
110
106
|
// what the keys ask of the pedal, while the keys are in charge: the seat reads it each step, so a holder above lets go of it (seat.js)
|
|
111
107
|
p._pedal = () => { if (!held.active) return null; const a = input.autopilot || input.axis; return [a.y, a.x, input.down('brake') ? 1 : 0]; };
|
|
112
|
-
|
|
108
|
+
entry.worldLoad = watchRecord(e, W, p, id);
|
|
113
109
|
// keepRecord: the module is going, not the player; its place stays in world for the next addPlayer
|
|
114
110
|
entry.dispose = (keepRecord = false) => {
|
|
115
|
-
st.players.delete(id); held.remove(); jump?.remove();
|
|
111
|
+
st.players.delete(id); held.remove(); jump?.remove();
|
|
116
112
|
if (input.actor === id) input.actor = null;
|
|
117
113
|
p.recordId = null; p._release = null; p.dispose(); if (!keepRecord) W.remove(id);
|
|
118
114
|
if (e.player === p) e.player = st.players.values().next().value?.character ?? null; // the next player is the first now
|
|
@@ -6,8 +6,7 @@ const CONTROL_FIX = "pick how the player moves: addPlayer({ ...presets.player.th
|
|
|
6
6
|
export const DEV_STRINGS = { noControl: 'characters.addPlayer(): no control given; ' + CONTROL_FIX,
|
|
7
7
|
badControl: "characters.addPlayer(): control {got} is not a control; " + CONTROL_FIX + ". (A function returning null stands still; a game-driven move takes control, see recipe 57)",
|
|
8
8
|
noFollow: "characters.addPlayer(): a camera module is installed but cameraFollow was not given, so the camera does not follow the player. " +
|
|
9
|
-
'Pass cameraFollow: true (presets.player.* do), or cameraFollow: false if the game aims the camera itself'
|
|
10
|
-
noWorld: 'characters.addPlayer() needs world() installed first: the player is a record in world (position is saved, world splits near/far by it). Use engine.use(world(), …); openWorld() already installs it' };
|
|
9
|
+
'Pass cameraFollow: true (presets.player.* do), or cameraFollow: false if the game aims the camera itself' };
|
|
11
10
|
export const STRINGS = { 'zh-CN': { 'npc.talk': '和{name}说话', 'input.brake': '刹车' }, en: { 'npc.talk': 'Talk to {name}', 'input.brake': 'Brake' } };
|
|
12
11
|
|
|
13
12
|
export const validControl = c => c === 'camera' || typeof c === 'function';
|
|
@@ -28,7 +28,7 @@ export function seatFromRecord(c, v, seat) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/** The records that name this vehicle. A far NPC has no model, so only its record knows */
|
|
31
|
-
const ridersOf = (e, v) => (v.id == null ? [] : e.world
|
|
31
|
+
const ridersOf = (e, v) => (v.id == null ? [] : e.world.query({}).filter(r => r.vehicle === v.id));
|
|
32
32
|
|
|
33
33
|
/** characters.addVehicle: join the registry, and seat the riders whose record is waiting for this id. A far NPC is seated by its next build (npcView.js). A vehicle gone for good answers those records too: nothing will come for them */
|
|
34
34
|
export function addVehicle(e, v) {
|
|
@@ -22,7 +22,7 @@ function slab(S, o, d, h) {
|
|
|
22
22
|
|
|
23
23
|
const BOX_KEYS = ['halfWidth', 'halfDepth', 'rotation', 'height', 'y', 'occluder', 'layer'], CIRCLE_KEYS = ['radius', 'height', 'occluder', 'layer'], SEG_KEYS = ['thickness', 'height', 'y', 'occluder', 'layer'], BLOCK_KEYS = ['bounds'];
|
|
24
24
|
|
|
25
|
-
/** A collider's layer option: one name, or undefined for "stops every mover"
|
|
25
|
+
/** A collider's layer option: one name, or undefined for "stops every mover" */
|
|
26
26
|
function layerOf(where, v) {
|
|
27
27
|
if (v === undefined || (typeof v === 'string' && v)) return v;
|
|
28
28
|
throw codedError('collision-misuse', `${where}: layer is one name, e.g. { layer: 'gate' } (movers with passes: ['gate'] go through it, every other mover is stopped); got ${JSON.stringify(v)}`, TypeError);
|
|
@@ -8,7 +8,7 @@ const CELL = 8, MAX_CELLS = 64, KEY = 1048576; // colliders too large (coverin
|
|
|
8
8
|
export const bodyHits = (it, y, body) => !(y >= it.y + it.h || y + body <= it.y);
|
|
9
9
|
/**
|
|
10
10
|
* A mover's passes option (character option; findPath, findPathAsync and walkable option): the collider layers it goes through. Read here for every entry,
|
|
11
|
-
* sorted and without repeats so one set is one navmesh, never two. Left out or empty: undefined, which every reader takes as "stopped by everything"
|
|
11
|
+
* sorted and without repeats so one set is one navmesh, never two. Left out or empty: undefined, which every reader takes as "stopped by everything"
|
|
12
12
|
*/
|
|
13
13
|
export function passesOf(where, v) {
|
|
14
14
|
if (v === undefined || v === null) return undefined;
|
package/modules/content/index.js
CHANGED
|
@@ -25,7 +25,7 @@ import { missingText, warnOnce } from '../../core/base/validate.js';
|
|
|
25
25
|
import { loadContent, checkRefs, BUILTIN_TESTS, BUILTIN_RUNS } from './loader.js';
|
|
26
26
|
import { sectionsOf } from '../../core/base/sections.js';
|
|
27
27
|
import { addProps, needWorld } from './props.js';
|
|
28
|
-
import { templateOf, spawnTemplate, placeTemplate, defineTemplates } from './templates.js';
|
|
28
|
+
import { templateOf, spawnTemplate, placeTemplate, defineTemplates, templatesWorldLoad } from './templates.js';
|
|
29
29
|
import { refit } from './models.js';
|
|
30
30
|
import { holdProtos } from '../../core/assets/namedModel.js';
|
|
31
31
|
import { packsOf } from './packs.js';
|
|
@@ -100,7 +100,7 @@ function contentApi(st) {
|
|
|
100
100
|
return done;
|
|
101
101
|
},
|
|
102
102
|
/**
|
|
103
|
-
* @internal modules a replaces installed fresh, or a failed one put back ('module:
|
|
103
|
+
* @internal modules a replaces installed fresh, or a failed one put back ('module:fresh'): their sections get every pack again, one load each as they came. A fresh install has
|
|
104
104
|
* none of it. A section's format is its holder's, so a newcomer may refuse what was written for the old one: no line of the game asked for this load, so it is told, not thrown
|
|
105
105
|
*/
|
|
106
106
|
_replay(mods) {
|
|
@@ -227,11 +227,12 @@ export function content() {
|
|
|
227
227
|
ctx.saves.define('content', { ...marksPart(api, st), atomic: true });
|
|
228
228
|
for (const holder of ['collision', 'collider3d']) ctx.feeds(holder, () => refit(e));
|
|
229
229
|
ctx.track(e.events.on('engine:ready', () => { checkOps(e, st); checkRefs(st); }));
|
|
230
|
-
ctx.track(e.events.on('module:
|
|
230
|
+
ctx.track(e.events.on('module:fresh', ({ modules }) => api._replay(modules)));
|
|
231
231
|
ctx.track({ remove: () => { for (const m of api.markers.values()) m.remove(); api.markers.clear(); } }); // the marks stay in st.marks and the save part; only what is on screen goes
|
|
232
232
|
st.checkOps = () => { if (e.ready) checkOps(e, st); };
|
|
233
233
|
return api;
|
|
234
234
|
},
|
|
235
|
+
worldLoad(e) { templatesWorldLoad(e, st); },
|
|
235
236
|
isReady() { return api.ready; },
|
|
236
237
|
// ?at=<place> / applyState({ at }): this module owns the names, core does the placing with what it gets back. An unknown name stops here: a picture of the
|
|
237
238
|
// spawn point taken for "the pier" would look fine and be wrong
|
|
@@ -36,7 +36,7 @@ function partsOf(root, frame) {
|
|
|
36
36
|
* Cached per prototype by the parts themselves (geometry and matrix): copies whose setup only swapped materials share the prototype's base, while a setup that
|
|
37
37
|
* thickened the trunk under the same crown gets its own. Overall bounds would not tell those two apart. @internal
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
function baseOf(m) {
|
|
40
40
|
if (m.base) return m.base;
|
|
41
41
|
if (!m.parts) { m.obj.updateMatrix(); m.parts = partsOf(m.obj, m.obj.matrix.clone()); } // a prototype: never placed, its root matrix is its frame
|
|
42
42
|
const cache = ((m.owner ?? m).bases ??= new Map());
|
|
@@ -99,10 +99,11 @@ export function defineTemplates(e, api, st, defs) {
|
|
|
99
99
|
if (d.stages || d.update) simulate(e, st, name);
|
|
100
100
|
limitContainers(e, st, name);
|
|
101
101
|
}
|
|
102
|
-
// a save brings back runtime instances and their goods, but container limits are definition data: put them back from the template
|
|
103
|
-
st.templateLoad ??= st.track(e.events.on('world:load', () => { for (const name of st.templates.keys()) limitContainers(e, st, name); }));
|
|
104
102
|
}
|
|
105
103
|
|
|
104
|
+
/** The content module's worldLoad step: a save brings back runtime instances and their goods, but container limits are definition data: put them back from the template. @internal */
|
|
105
|
+
export function templatesWorldLoad(e, st) { for (const name of st.templates.keys()) limitContainers(e, st, name); }
|
|
106
|
+
|
|
106
107
|
/** The definition of a template, or a dev error listing the known ones. @internal */
|
|
107
108
|
export function templateOf(st, name) {
|
|
108
109
|
const d = st.templates.get(name);
|
package/modules/flow/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const FLOW_PARAMS = keysSchema(['start']);
|
|
|
27
27
|
*/
|
|
28
28
|
export function flow(opts = {}) {
|
|
29
29
|
readParams('flow', FLOW_PARAMS, opts);
|
|
30
|
-
let e = null, sig = null, chain = Promise.resolve(), held = null, frozen = null, leaving = false, queued = null;
|
|
30
|
+
let e = null, sig = null, chain = Promise.resolve(), held = null, frozen = null, leaving = false, queued = null, before = null; // before: the state a playthrough ended in, for a failed replacement to go back to
|
|
31
31
|
const states = new Map([['playing', {}], ['paused', { freeze: true, lockInput: true }]]);
|
|
32
32
|
// turn freeze / input lock on or off for one state
|
|
33
33
|
const hold = (def, on) => {
|
|
@@ -74,7 +74,7 @@ export function flow(opts = {}) {
|
|
|
74
74
|
const lock = lockInput ? e.input.push('transition') : null;
|
|
75
75
|
let shown = false, turn = null;
|
|
76
76
|
try {
|
|
77
|
-
await fadeScreen(e, 1, { seconds: fade });
|
|
77
|
+
await fadeScreen(e, 1, { seconds: fade, owner: 'flow' });
|
|
78
78
|
if (sig?.aborted || await gone()) return; // unloaded, or the state replaced, during the fade: no scene swap for what is gone (the finally gives the screen and input back)
|
|
79
79
|
const m = music === 'fade' ? e.music : null, prev = m?.current;
|
|
80
80
|
m?.stop({ fade });
|
|
@@ -84,10 +84,10 @@ export function flow(opts = {}) {
|
|
|
84
84
|
await whenSettled(e, undefined, true);
|
|
85
85
|
if (sig?.aborted) return;
|
|
86
86
|
if (m && prev && !m.current && !m.ruled && !replaced()) m.play(prev); // no track rule: resume the previous track after the switch. A new game or load has its own music, however fn started it; a level load nobody awaited is still this playthrough
|
|
87
|
-
await fadeScreen(e, 0, { seconds: fade });
|
|
87
|
+
await fadeScreen(e, 0, { seconds: fade, owner: 'flow' });
|
|
88
88
|
shown = true;
|
|
89
89
|
} finally {
|
|
90
|
-
if (!shown) fadeScreen(e, 0, { seconds: 0 }); // fn threw: don't leave the screen black, fade back in at once (the error still propagates to the caller)
|
|
90
|
+
if (!shown) fadeScreen(e, 0, { seconds: 0, owner: 'flow' }); // fn threw: don't leave the screen black, fade back in at once (the error still propagates to the caller)
|
|
91
91
|
turn?.remove();
|
|
92
92
|
lock?.remove();
|
|
93
93
|
api.transitioning = false;
|
|
@@ -105,13 +105,13 @@ export function flow(opts = {}) {
|
|
|
105
105
|
if (opts.start && opts.start !== 'playing') ctx.track(e.events.once('engine:ready', () => api.go(opts.start)));
|
|
106
106
|
// a playthrough ends (engine.session): back to the start state, so its enter() runs again; a new one starts in 'playing'
|
|
107
107
|
// a failed replacement keeps the old playthrough: back to the state it was in
|
|
108
|
-
|
|
109
|
-
// the state goes after every session:end listener: the start state may start things (a title track) that another listener of the same event ends (music stops there), and install order must not decide which won
|
|
110
|
-
ctx.track(e.events.on('session:end', () => { before = api.state; queueMicrotask(() => { if (!sig.aborted) api.go(opts.start ?? 'playing'); }); }));
|
|
111
|
-
ctx.track(e.events.on('session:start', () => api.go('playing')));
|
|
108
|
+
before = null;
|
|
112
109
|
ctx.track(e.events.on('session:failed', ({ kind }) => { if (before && kind !== 'quick') api.go(before); })); // a quick load ended nothing here
|
|
113
110
|
return api;
|
|
114
111
|
},
|
|
112
|
+
// the state goes after the whole end step and its event: the start state may start things (a title track) that another module's sessionEnd or a game listener ends (music stops there)
|
|
113
|
+
sessionEnd() { before = api.state; queueMicrotask(() => { if (!sig.aborted) api.go(opts.start ?? 'playing'); }); },
|
|
114
|
+
sessionStart() { api.go('playing'); },
|
|
115
115
|
// unloaded (unuse, replaces) in a state that stops the game: nothing else would ever end its freeze or input lock
|
|
116
116
|
dispose() { frozen?.remove(); held?.remove(); frozen = held = null; },
|
|
117
117
|
// ?play / applyState({ play }): leave the start state (a title) the way its Start button does; session:start then goes to 'playing'
|
|
@@ -312,7 +312,6 @@ export function dialogue(opts = {}) {
|
|
|
312
312
|
// choice1..9 pick a choice by number: declared, never bound here (presets.bindings.dialogNumbers binds 1-9). Optional: the choice cursor
|
|
313
313
|
// (basic menu keys + confirm) and clicks pick choices without them. Context 'dialog', so 1-9 stay free for hotbars outside a conversation
|
|
314
314
|
for (let i = 1; i <= 9; i++) ctx.input.define('choice' + i, { context: 'dialog', label: 'dialogue.choice', optional: true });
|
|
315
|
-
ctx.track(e.events.on('session:end', () => d._cancel())); // an open dialogue belongs to the playthrough that opened it
|
|
316
315
|
ctx.ui.define('dialogue', dialogueBox);
|
|
317
316
|
ctx.ui.define('dialogue.bubble', bubblePart, { multi: true });
|
|
318
317
|
ctx.ops.define('dialogue.advance', {
|
|
@@ -332,6 +331,7 @@ export function dialogue(opts = {}) {
|
|
|
332
331
|
return d;
|
|
333
332
|
},
|
|
334
333
|
frame(dt) { d.frame(dt); },
|
|
334
|
+
sessionEnd() { d._cancel(); }, // an open dialogue belongs to the playthrough that opened it
|
|
335
335
|
// unloaded mid-conversation: the input context and focus entry are the conversation's, not tracked, and a say() Promise gets its end. Not on engine.dispose: waits stay pending there
|
|
336
336
|
dispose(e) { if (!e.disposed) { d._bubbles.clear(); d._asks.clear(); d.end(); } },
|
|
337
337
|
afterLoad() { if (!d.active?.duringLoad) d._cancel(); }, // a line open at a load belongs to the state thrown away; one a load opened stays
|
|
@@ -44,9 +44,6 @@ export class Inventory {
|
|
|
44
44
|
if (engine.input.keysOf(action).length) track(engine.input.touchButton(action, 'inventory.action'));
|
|
45
45
|
ctx.ui.define('inventory', inventoryWindow, { modal: { cancel: e => e.ui.close('inventory'), freeze: () => this.pauseGame, data: () => windowData(this) } });
|
|
46
46
|
for (const ev of ['i18n:change', 'input:rebind']) track(engine.events.on(ev, () => this._refresh()));
|
|
47
|
-
// a pack loaded after start() stays for the next playthrough with its props and definitions, and its start items with them
|
|
48
|
-
track(engine.events.on('session:start', ({ kind }) => { if (kind === 'new') for (const d of this._lateStart) this.giveStart(d); }));
|
|
49
|
-
track(engine.events.on('session:end', () => engine.ui.close('inventory'))); // it shows the playthrough that ended, and its freeze must not reach the next one
|
|
50
47
|
// version 1 is the current shape; raise it with a migrate step when it changes. seq: the numbering of entry keys (sword#3); a save without it continues
|
|
51
48
|
// after the highest key it holds
|
|
52
49
|
ctx.saves.define('inventory', { atomic: true, version: 1, save: () => ({ seq: this._seq, items: this.home._save() }), load: d => {
|
|
@@ -247,6 +244,9 @@ export function inventory(opts = {}) {
|
|
|
247
244
|
defineInventoryOps(e, ctx, inv);
|
|
248
245
|
return inv;
|
|
249
246
|
},
|
|
247
|
+
sessionEnd(e) { e.ui.close('inventory'); }, // it shows the playthrough that ended, and its freeze must not reach the next one
|
|
248
|
+
// a pack loaded after start() stays for the next playthrough with its props and definitions, and its start items with them
|
|
249
|
+
sessionStart(e, { kind }) { if (kind === 'new') for (const d of inv._lateStart) inv.giveStart(d); },
|
|
250
250
|
frame(dt, e) { // the inventory key toggles the part; while open the part holds the input lock, so the close press is read raw
|
|
251
251
|
const open = e.ui.isOpen('inventory');
|
|
252
252
|
if (open ? e.input.pressedRaw(inv.action) : e.input.pressed(inv.action)) { if (open) e.ui.close('inventory'); else e.ui.open('inventory'); }
|
|
@@ -326,6 +326,7 @@ export function quests(opts = {}) {
|
|
|
326
326
|
name: 'quests', skipKind: 'approx', type: 'rules', provides: ['quests'], label: 'Quests', params: QUEST_PARAMS, options: o,
|
|
327
327
|
// o: the schema defaults are filled in, the class repeats none
|
|
328
328
|
install(e, ctx) { q = new Quests(e, o, ctx); return q; },
|
|
329
|
+
sessionEnd() { q.win.toggle(false); }, // the log shows the playthrough that ended
|
|
329
330
|
// Check quests in the fixed step (game time; not while frozen or flow is paused, so no rewards are granted while paused)
|
|
330
331
|
fixed() { if (--q._t <= 0) { q._t = q._period; q.check(); } },
|
|
331
332
|
// engine.skip: the countdown lands where stepping would have left it; conditions are checked once, on the last segment, if a check fell inside
|
|
@@ -11,7 +11,7 @@ export default {
|
|
|
11
11
|
'contents', 'setContents', 'renameIds'], // contents / setContents: net syncs containers through these; renameIds: content renames move goods
|
|
12
12
|
ops: ['inventory.transfer', 'inventory.trade', 'inventory.use', 'inventory.drop'],
|
|
13
13
|
events: ['item:add', 'item:remove', 'item:use'], // item:add / item:remove carry { container, actor } for every container
|
|
14
|
-
saves: { inventory: 1 },
|
|
14
|
+
saves: { inventory: 1, containers: 2 },
|
|
15
15
|
describe: true,
|
|
16
16
|
options: {},
|
|
17
17
|
probe: {
|
|
@@ -62,7 +62,6 @@ export class Pickups {
|
|
|
62
62
|
engine.i18n.add(STRINGS);
|
|
63
63
|
// a record gone (taken without respawn, removed, not in a loaded save): its live parts are no longer needed for a rebuild
|
|
64
64
|
track(engine.events.on('world:remove', ({ id, kind }) => { this._live.delete(id); dirty({ kind }); }));
|
|
65
|
-
track(engine.events.on('world:load', () => { this._autoDirty = true; for (const id of this._live.keys()) if (!engine.world.get(id)) this._live.delete(id); }));
|
|
66
65
|
present(this, track);
|
|
67
66
|
}
|
|
68
67
|
|
|
@@ -364,6 +363,7 @@ export function pickups(opts = {}) {
|
|
|
364
363
|
return pk;
|
|
365
364
|
},
|
|
366
365
|
fixed() { pk._auto(); },
|
|
366
|
+
worldLoad(e) { pk._autoDirty = true; for (const id of pk._live.keys()) if (!e.world.get(id)) pk._live.delete(id); }, // records not in the loaded world need no live parts
|
|
367
367
|
describe(e, ctx) { // use the model if present (same object the interactions module reports, merged into one entry); far away only data
|
|
368
368
|
const w = e.world;
|
|
369
369
|
for (const r of w.query({ kind: 'pickup', near: ctx.center, radius: ctx.radius, where: r => r.until == null })) ctx.near(w.view(r.id) ?? r.position, { name: pk._name(r), kind: 'pickup', id: r.item ?? r.id });
|
|
@@ -44,7 +44,6 @@ export function questLogWindow(e, q, ctx) {
|
|
|
44
44
|
/** @returns {QuestLogView} */
|
|
45
45
|
const view = () => ({ title: e.t('quests.title'), key: e.input.label(q.action), quests: q.list(), close: () => e.ui.close(NAME) });
|
|
46
46
|
ctx.ui.define(NAME, questLogPart, { modal: { cancel: eng => eng.ui.close(NAME), data: view } });
|
|
47
|
-
track(e.events.on('session:end', () => e.ui.close(NAME))); // it shows the playthrough that ended
|
|
48
47
|
const win = {
|
|
49
48
|
get open() { return e.ui.isOpen(NAME); },
|
|
50
49
|
toggle(on = !win.open) { if (on) e.ui.open(NAME); else e.ui.close(NAME); },
|
package/modules/grid/index.js
CHANGED
|
@@ -278,9 +278,9 @@ export function grids(opts = {}) {
|
|
|
278
278
|
ctx.track(e.events.on('world:add', ({ id }) => G._reindex(id)));
|
|
279
279
|
ctx.track(e.events.on('world:remove', ({ id }) => G._unindex(id)));
|
|
280
280
|
ctx.track(e.events.on('world:change', ({ id, keys }) => { if (keys.includes('grid')) G._reindex(id); }));
|
|
281
|
-
ctx.track(e.events.on('world:load', () => G._rebuild()));
|
|
282
281
|
return G;
|
|
283
282
|
},
|
|
283
|
+
worldLoad() { G._rebuild(); }, // the records were replaced wholesale (a load): index them again
|
|
284
284
|
frame() { for (const t of G._tiles.values()) t.frame(); for (const p of G._previews) p.frame(); },
|
|
285
285
|
explain: { grid: (e, q) => G._explain(q) },
|
|
286
286
|
describe() { return G._describe(); },
|