@moku-labs/game 0.15.56 → 0.15.57

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.
@@ -7187,7 +7187,7 @@ function refreshGuide(ctx, payload) {
7187
7187
  * @param ctx - Kernel context of the flow plugin.
7188
7188
  * @returns The two hooks of the plugin.
7189
7189
  */
7190
- function createHandlers$7(ctx) {
7190
+ function createHandlers$8(ctx) {
7191
7191
  return {
7192
7192
  /**
7193
7193
  * Reacts to a change of the pause stack.
@@ -7417,7 +7417,7 @@ const flowPlugin = /*#__PURE__*/ createPlugin$1("flow", {
7417
7417
  }),
7418
7418
  createState: createFlowState,
7419
7419
  api: createFlowApi,
7420
- hooks: createHandlers$7,
7420
+ hooks: createHandlers$8,
7421
7421
  onInit: connectFlow,
7422
7422
  onStop: ({ config, state }) => stopRunner({
7423
7423
  config,
@@ -8885,7 +8885,7 @@ var QueryWalk = class {
8885
8885
  if (entity === void 0 || value === void 0) continue;
8886
8886
  if (!carriesAll(state.stores, names, entity)) continue;
8887
8887
  markWritten(state, written, entity);
8888
- this.value = rowOf$1(state.stores, names, entity, value);
8888
+ this.value = rowOf$2(state.stores, names, entity, value);
8889
8889
  return this;
8890
8890
  }
8891
8891
  return this.end();
@@ -9012,7 +9012,7 @@ function carriesAll(stores, names, entity) {
9012
9012
  * @param value - Its stored value of the first term.
9013
9013
  * @returns The row: the entity, then one stored value per name.
9014
9014
  */
9015
- function rowOf$1(stores, names, entity, value) {
9015
+ function rowOf$2(stores, names, entity, value) {
9016
9016
  switch (names.length) {
9017
9017
  case 1: return [entity, value];
9018
9018
  case 2: return [
@@ -9603,7 +9603,7 @@ function startTiming(state, clock) {
9603
9603
  * @param name - The system's name.
9604
9604
  * @returns Its row; 0 for a name the table never saw, which cannot happen for a registered system.
9605
9605
  */
9606
- function rowOf(state, name) {
9606
+ function rowOf$1(state, name) {
9607
9607
  return state.timingSlots.get(name) ?? 0;
9608
9608
  }
9609
9609
  /**
@@ -9816,7 +9816,7 @@ function runTimed(ctx, timing, entries, context, phase, time) {
9816
9816
  const entry = entries[index];
9817
9817
  if (entry === void 0 || entry.frame >= time.frame) continue;
9818
9818
  if (!wakes(state, entry, context)) continue;
9819
- const row = rowOf(state, entry.definition.name);
9819
+ const row = rowOf$1(state, entry.definition.name);
9820
9820
  const started = timing.clock();
9821
9821
  guardedRun(ctx, entry, context, phase);
9822
9822
  timing.ms[row] = (timing.ms[row] ?? 0) + timing.clock() - started;
@@ -10151,7 +10151,8 @@ function connectWorld(ctx) {
10151
10151
  /**
10152
10152
  * Empties the world in `onStop`: the frame callbacks and the hint listener are removed, then
10153
10153
  * every track, view, queued view, entity and resource is dropped, a running scene build and the
10154
- * `onBuild` checks with them, every warm record, and the scenes and the frame history are reset.
10154
+ * `onBuild` checks with them, every warm record, every held name and owed `show`, every value fed, and the scenes
10155
+ * and the frame history are reset.
10155
10156
  * No `onRemoved` fires, because `renderer` stopped earlier and destroyed its own objects.
10156
10157
  *
10157
10158
  * @param state - The plugin state, the only thing a teardown context carries.
@@ -10184,6 +10185,10 @@ function clearWorld(state) {
10184
10185
  state.projection.warmHeld.clear();
10185
10186
  delete state.projection.warmActive;
10186
10187
  state.projection.warmStale = false;
10188
+ state.projection.held.clear();
10189
+ state.projection.showing.length = 0;
10190
+ state.projection.fed.clear();
10191
+ state.projection.heldFed.clear();
10187
10192
  state.ecs.generations.length = 0;
10188
10193
  state.ecs.free.length = 0;
10189
10194
  state.ecs.owners.clear();
@@ -11762,14 +11767,16 @@ function isSeen(seen, snapshot) {
11762
11767
  return seen !== void 0 && seen.player === snapshot.player && seen.session === snapshot.session;
11763
11768
  }
11764
11769
  /**
11765
- * Gives a mounted projection that declares `warm` its record, cold, at the end of the warm list. A projection that
11766
- * has one keeps it: a projection a scene before mounted and the coming one keeps (F23) keeps its held view.
11770
+ * Gives a mounted projection that declares `warm`, or is held, its record, cold, at the end of the warm list. A
11771
+ * projection that has one keeps it: a projection a scene before mounted and the coming one keeps (F23) keeps its held
11772
+ * view.
11767
11773
  *
11768
11774
  * @param state - The projection branch of the plugin state.
11769
11775
  * @param spec - The projection spec.
11770
11776
  */
11771
11777
  function ensureWarm(state, spec) {
11772
- if (spec.warm === void 0 || state.warm.has(spec.name)) return;
11778
+ if (state.warm.has(spec.name)) return;
11779
+ if (spec.warm === void 0 && !state.held.has(spec.name)) return;
11773
11780
  const record = {
11774
11781
  name: spec.name,
11775
11782
  entities: /* @__PURE__ */ new Set(),
@@ -11881,7 +11888,8 @@ function forgetWarm(pctx, name) {
11881
11888
  state.warmList.splice(state.warmList.indexOf(record), 1);
11882
11889
  }
11883
11890
  /**
11884
- * Drops every held view and forgets every record: the clear of the projections.
11891
+ * Drops every held view and forgets every record, every held name, every owed `show` and every value fed: the clear of
11892
+ * the projections.
11885
11893
  *
11886
11894
  * @param pctx - Domain context of the projection module.
11887
11895
  */
@@ -11891,6 +11899,10 @@ function clearWarm(pctx) {
11891
11899
  state.warm.clear();
11892
11900
  state.warmList.length = 0;
11893
11901
  state.warmHeld.clear();
11902
+ state.held.clear();
11903
+ state.showing.length = 0;
11904
+ state.fed.clear();
11905
+ state.heldFed.clear();
11894
11906
  delete state.warmActive;
11895
11907
  state.warmStale = false;
11896
11908
  }
@@ -11977,7 +11989,7 @@ function frameBudget(state) {
11977
11989
  * @param record - The record that holds the view.
11978
11990
  * @param cause - `"mount"` for a direct reconcile, `"change"` for a live one.
11979
11991
  */
11980
- function showHeld(pctx, mounted, record, cause) {
11992
+ function showHeld$1(pctx, mounted, record, cause) {
11981
11993
  const state = pctx.ctx.state.projection;
11982
11994
  const view = record.view;
11983
11995
  for (const entity of record.entities) state.warmHeld.delete(entity);
@@ -12063,17 +12075,31 @@ function pollActive(state, active) {
12063
12075
  delete state.warmActive;
12064
12076
  }
12065
12077
  /**
12066
- * Reads the warm item of a projection and its key. A `warm` or a `key` that throws is logged as a projection that
12067
- * failed, and nothing is warm.
12078
+ * The first item `from` gives: the first of a list, or the one object of a screen.
12079
+ *
12080
+ * @param spec - The projection spec.
12081
+ * @param snapshot - The state now.
12082
+ * @param sw - The switch `from` reads.
12083
+ * @returns The item, or `undefined` for an empty list.
12084
+ */
12085
+ function firstItem(spec, snapshot, sw) {
12086
+ const source = spec.from(snapshot.player, snapshot.session, sw);
12087
+ return Array.isArray(source) ? source[0] : source;
12088
+ }
12089
+ /**
12090
+ * Reads the item a record holds and its key: `from`'s first item while the projection is held, read with the value the
12091
+ * first feed after `hold` stored (else the one fed before), so a later feed never makes it differ; else the item
12092
+ * `warm` gives. A `warm`, a `from` or a `key` that throws is logged as a projection that failed, and nothing is held.
12068
12093
  *
12069
12094
  * @param pctx - Domain context of the projection module.
12070
- * @param spec - The projection spec, which declares `warm`.
12095
+ * @param spec - The projection spec, which declares `warm` or is held.
12071
12096
  * @param snapshot - The state now.
12072
12097
  * @returns The item and its key, or `undefined` for no item and for a throw.
12073
12098
  */
12074
12099
  function readWarm(pctx, spec, snapshot) {
12100
+ const state = pctx.ctx.state.projection;
12075
12101
  try {
12076
- const item = spec.warm?.(snapshot.player, snapshot.session);
12102
+ const item = state.held.has(spec.name) ? firstItem(spec, snapshot, state.heldFed.get(spec.name) ?? state.fed.get(spec.name)) : spec.warm?.(snapshot.player, snapshot.session);
12077
12103
  if (item === void 0 || item === null) return void 0;
12078
12104
  return {
12079
12105
  item,
@@ -12175,8 +12201,8 @@ function refreshWarm(pctx, spec, record, warm) {
12175
12201
  }
12176
12202
  /**
12177
12203
  * One record's turn in the warm step: a record shown, in work, or read against this state is passed over. Otherwise
12178
- * `warm` is read: with no item, or with a key `from` shows, what is held is dropped; a cold record spawns its held
12179
- * view, a ready one is brought up to date.
12204
+ * its item is read (`warm`, or `from`'s first while held): with no item, or with a key `from` shows, what is held is
12205
+ * dropped; a cold record spawns its held view, a ready one is brought up to date.
12180
12206
  *
12181
12207
  * @param pctx - Domain context of the projection module.
12182
12208
  * @param record - The record.
@@ -12391,7 +12417,7 @@ function enterEntry(pctx, spec, mounted, entry) {
12391
12417
  function adoptEntry(pctx, spec, mounted, record, entry) {
12392
12418
  const view = record.view;
12393
12419
  const next = sameItem(record.item, entry.item) ? void 0 : collectView(pctx, spec, entry.item);
12394
- showHeld(pctx, mounted, record, entry.direct ? "mount" : "change");
12420
+ showHeld$1(pctx, mounted, record, entry.direct ? "mount" : "change");
12395
12421
  if (next === void 0) view.item = entry.item;
12396
12422
  else writeDifference(pctx, view, next, entry.item);
12397
12423
  playEnter$1(pctx, spec, view, entry);
@@ -12609,7 +12635,9 @@ function exitGone(pctx, spec, mounted, next, entry, counts) {
12609
12635
  }
12610
12636
  }
12611
12637
  /**
12612
- * Reads the keyed items of one projection. A throw from `from` or `key` is reported and the
12638
+ * Reads the keyed items of one projection, `from` reading the value last fed to it (`undefined`
12639
+ * for one never fed). A held projection (`hold`) shows none: `from` is not read, and the warm step
12640
+ * keeps its first item built and hidden. A throw from `from` or `key` is reported and the
12613
12641
  * projection is skipped for this reconcile.
12614
12642
  *
12615
12643
  * @param pctx - Domain context of the projection module.
@@ -12619,8 +12647,10 @@ function exitGone(pctx, spec, mounted, next, entry, counts) {
12619
12647
  */
12620
12648
  function keyedItems(pctx, spec, snapshot) {
12621
12649
  const next = /* @__PURE__ */ new Map();
12650
+ const state = pctx.ctx.state.projection;
12651
+ if (state.held.has(spec.name)) return next;
12622
12652
  try {
12623
- const source = spec.from(snapshot.player, snapshot.session);
12653
+ const source = spec.from(snapshot.player, snapshot.session, state.fed.get(spec.name));
12624
12654
  if (!Array.isArray(source)) {
12625
12655
  if (source !== void 0 && source !== null) next.set(spec.key?.(source) ?? spec.name, source);
12626
12656
  return next;
@@ -12949,8 +12979,9 @@ function drawsAlike(before, after, spec) {
12949
12979
  }
12950
12980
  /**
12951
12981
  * Unmounts projections: every motion of their views is finished, and the live views and the
12952
- * despawn queue are despawned in the same call, and so is the view a warm window holds hidden.
12953
- * An unknown or unmounted name is skipped.
12982
+ * despawn queue are despawned in the same call, and so is the view a warm window or a hold keeps
12983
+ * hidden. A held name is held no more. The value fed to a name stays: a `hold` or a `mount` that places it again
12984
+ * reads it, and the public `unmount` forgets it. An unknown or unmounted name is skipped.
12954
12985
  *
12955
12986
  * @param pctx - Domain context of the projection module.
12956
12987
  * @param names - Names of the projections to unmount.
@@ -12962,6 +12993,8 @@ function unmountNames(pctx, names) {
12962
12993
  if (mounted === void 0) continue;
12963
12994
  clearMounted(pctx, mounted);
12964
12995
  forgetWarm(pctx, name);
12996
+ state.held.delete(name);
12997
+ state.heldFed.delete(name);
12965
12998
  state.mounted.delete(name);
12966
12999
  }
12967
13000
  }
@@ -13020,7 +13053,8 @@ function mountNames(pctx, names, owner) {
13020
13053
  * Gives every projection of a list its place under the current layer list: a missing one gets an
13021
13054
  * empty record at the `Order` of its place, a kept one mounted under another list takes its new
13022
13055
  * place (`placeMounted`), its held warm view too. A screen root draws at its place in the list
13023
- * (spec 16 U1.6). A projection that declares `warm` gets its warm record, cold, unless it has one.
13056
+ * (spec 16 U1.6). A projection that declares `warm` or is held gets its warm record, cold, unless
13057
+ * it has one.
13024
13058
  *
13025
13059
  * @param pctx - Domain context of the projection module.
13026
13060
  * @param names - The projection list of the scene.
@@ -13195,6 +13229,106 @@ function discardBuild(pctx) {
13195
13229
  handBack(pctx, building);
13196
13230
  }
13197
13231
  //#endregion
13232
+ //#region src/plugins/world/projection/hold.ts
13233
+ /**
13234
+ * Mounts projections held: the checks of a mount first, so a throw holds nothing; then every name joins the held set
13235
+ * before its record is made and before the reconcile, which shows none of its items. A record a projection had
13236
+ * already (its `warm`) reads its item again, from `from` now, with the value the first `feed` after this hold stores,
13237
+ * else the one fed before. Every name of the list is reconciled at once, direct: a kept one that showed views drops
13238
+ * them.
13239
+ *
13240
+ * @param pctx - Domain context of the projection module.
13241
+ * @param names - Names of the projections to hold.
13242
+ * @param owner - Who owns the entities of the new ones.
13243
+ * @throws {Error} For an unknown name, or a `layer` or `lift` the scene does not declare.
13244
+ */
13245
+ function holdNames(pctx, names, owner) {
13246
+ const state = pctx.ctx.state.projection;
13247
+ const { again } = sortMount(pctx, names, state.layers);
13248
+ unmountNames(pctx, again);
13249
+ for (const name of names) {
13250
+ state.held.add(name);
13251
+ state.heldFed.delete(name);
13252
+ delete state.warm.get(name)?.seen;
13253
+ }
13254
+ state.warmStale = true;
13255
+ placeNames(pctx, names, owner);
13256
+ reconcileFresh(pctx, names);
13257
+ }
13258
+ /**
13259
+ * Releases a held projection: it is held no more, its `from` and its record are read again, the next reconcile
13260
+ * reconciles it by name, and its `from` reads the latest value fed. A name that is not held changes nothing.
13261
+ *
13262
+ * @param pctx - Domain context of the projection module.
13263
+ * @param name - The projection.
13264
+ */
13265
+ function showName(pctx, name) {
13266
+ const state = pctx.ctx.state.projection;
13267
+ if (!state.held.delete(name)) return;
13268
+ state.heldFed.delete(name);
13269
+ delete state.mounted.get(name)?.seen;
13270
+ delete state.warm.get(name)?.seen;
13271
+ state.warmStale = true;
13272
+ state.showing.push(name);
13273
+ }
13274
+ /**
13275
+ * Tells whether two switches are equal field by field. Pure.
13276
+ *
13277
+ * @param before - The switch stored.
13278
+ * @param after - The switch fed.
13279
+ * @returns True when `from`, `to` and `progress` are the same.
13280
+ * @example
13281
+ * ```ts
13282
+ * sameSwitch({ from: "ward", to: "board", progress: 0.5 }, { from: "ward", to: "board", progress: 0.5 }); // true
13283
+ * ```
13284
+ */
13285
+ function sameSwitch(before, after) {
13286
+ return before.from === after.from && before.to === after.to && before.progress === after.progress;
13287
+ }
13288
+ /**
13289
+ * Hands a projection the switch its `from` reads. An equal value changes nothing and allocates nothing. Another one is
13290
+ * stored; then a held name keeps the value its warm step reads (the first feed after `hold` sets it, so a later commit
13291
+ * re-reads the held item with it and a feed never rebuilds the held view), a mounted shown name is read again by name
13292
+ * in the next reconcile (its `seen` dropped, its name on `showing` once), and a name not mounted is only stored.
13293
+ *
13294
+ * @param pctx - Domain context of the projection module.
13295
+ * @param name - The projection.
13296
+ * @param sw - The switch.
13297
+ */
13298
+ function feedName(pctx, name, sw) {
13299
+ const state = pctx.ctx.state.projection;
13300
+ const stored = state.fed.get(name);
13301
+ const held = state.held.has(name);
13302
+ if (held && !state.heldFed.has(name)) state.heldFed.set(name, sw);
13303
+ if (stored !== void 0 && sameSwitch(stored, sw)) return;
13304
+ state.fed.set(name, sw);
13305
+ if (held) return;
13306
+ const mounted = state.mounted.get(name);
13307
+ if (mounted === void 0) return;
13308
+ delete mounted.seen;
13309
+ if (!state.showing.includes(name)) state.showing.push(name);
13310
+ }
13311
+ /**
13312
+ * Reconciles the projections `show` released and the shown ones `feed` changed since the last reconcile, by name: a
13313
+ * running scene build would pass over a mounted projection its list does not name. A live world plays the enter of the
13314
+ * view it shows; a world that is not live shows it direct. Nothing runs while none was released.
13315
+ *
13316
+ * @param pctx - Domain context of the projection module.
13317
+ */
13318
+ function reconcileShown(pctx) {
13319
+ const state = pctx.ctx.state.projection;
13320
+ const names = state.showing;
13321
+ if (names.length === 0) return;
13322
+ state.showing = [];
13323
+ reconcile(pctx, {
13324
+ names,
13325
+ direct: pctx.deps.ecs.mode() !== "live",
13326
+ force: false,
13327
+ converge: false,
13328
+ settle: false
13329
+ });
13330
+ }
13331
+ //#endregion
13198
13332
  //#region src/plugins/world/projection/api.ts
13199
13333
  /**
13200
13334
  * Tells whether a cause sets the picture instead of playing it.
@@ -13300,6 +13434,7 @@ function createProjectionApi(ctx, deps) {
13300
13434
  * and whether an unchanged view that stands off its rest pose is settled (a rollback does).
13301
13435
  * A restore, a load and a forced rerun drop the views warm windows hold hidden first: they
13302
13436
  * replace the state or run `view` anew. After a reconcile the warm step looks at its records.
13437
+ * Then the projections `show` released are reconciled by name.
13303
13438
  */
13304
13439
  const reconcileIfDirty = () => {
13305
13440
  const dirty = state.dirty;
@@ -13317,6 +13452,7 @@ function createProjectionApi(ctx, deps) {
13317
13452
  });
13318
13453
  if (state.warmList.length > 0) state.warmStale = true;
13319
13454
  }
13455
+ reconcileShown(pctx);
13320
13456
  state.hints.length = 0;
13321
13457
  };
13322
13458
  /**
@@ -13348,7 +13484,7 @@ function createProjectionApi(ctx, deps) {
13348
13484
  state.specs.set(spec.name, spec);
13349
13485
  reseedViews(state, spec.name, from, seed);
13350
13486
  if (!mounted) return;
13351
- if (spec.warm === void 0) forgetWarm(pctx, spec.name);
13487
+ if (spec.warm === void 0 && !state.held.has(spec.name)) forgetWarm(pctx, spec.name);
13352
13488
  else ensureWarm(state, spec);
13353
13489
  forceRerun();
13354
13490
  },
@@ -13361,6 +13497,16 @@ function createProjectionApi(ctx, deps) {
13361
13497
  },
13362
13498
  unmount: (names) => {
13363
13499
  unmountNames(pctx, names);
13500
+ for (const name of names) state.fed.delete(name);
13501
+ },
13502
+ hold: (names, owner) => {
13503
+ holdNames(pctx, names, owner);
13504
+ },
13505
+ show: (name) => {
13506
+ showName(pctx, name);
13507
+ },
13508
+ feed: (name, sw) => {
13509
+ feedName(pctx, name, sw);
13364
13510
  },
13365
13511
  restOf: (entity, component) => {
13366
13512
  const stored = (state.byEntity.get(entity)?.rest ?? state.rests.get(entity))?.get(component.componentName);
@@ -13659,6 +13805,9 @@ function exposeProjection(projection) {
13659
13805
  layers: projection.layers,
13660
13806
  mount: projection.mount,
13661
13807
  unmount: projection.unmount,
13808
+ hold: projection.hold,
13809
+ show: projection.show,
13810
+ feed: projection.feed,
13662
13811
  settle: projection.settle,
13663
13812
  mute: projection.mute,
13664
13813
  lift: projection.lift,
@@ -13720,7 +13869,7 @@ function createWorldApi(ctx) {
13720
13869
  * @param ctx - Kernel context of the world plugin.
13721
13870
  * @returns The one hook of the plugin.
13722
13871
  */
13723
- function createHandlers$6(ctx) {
13872
+ function createHandlers$7(ctx) {
13724
13873
  let modules;
13725
13874
  return {
13726
13875
  /**
@@ -13836,7 +13985,8 @@ function emptySet$8() {
13836
13985
  * Creates the initial projection state: nothing registered, nothing mounted, no layer list, no
13837
13986
  * running track and no driver, so every motion is instant until `anim` installs one. No build
13838
13987
  * runs: `building` is absent. No warm window is held, and none is being built: `warmActive` is
13839
- * absent. The warm budget starts at two thirds of a 60 Hz frame until a step reads the rate.
13988
+ * absent. The warm budget starts at two thirds of a 60 Hz frame until a step reads the rate. No
13989
+ * projection is held, no `show` is owed, and nothing was fed.
13840
13990
  *
13841
13991
  * @returns The projection branch of the plugin state.
13842
13992
  */
@@ -13870,7 +14020,11 @@ function createProjectionState() {
13870
14020
  warmList: [],
13871
14021
  warmHeld: emptySet$8(),
13872
14022
  warmStale: false,
13873
- warmBudgetMs: FALLBACK_WARM_MS
14023
+ warmBudgetMs: FALLBACK_WARM_MS,
14024
+ held: emptySet$8(),
14025
+ showing: [],
14026
+ fed: emptyMap$9(),
14027
+ heldFed: emptyMap$9()
13874
14028
  };
13875
14029
  }
13876
14030
  //#endregion
@@ -13919,7 +14073,7 @@ const worldPlugin = /*#__PURE__*/ createPlugin$1("world", {
13919
14073
  events: (register) => register.map({ "world:reconciled": "A reconcile finished (dev only)" }),
13920
14074
  createState: createWorldState,
13921
14075
  api: createWorldApi,
13922
- hooks: createHandlers$6,
14076
+ hooks: createHandlers$7,
13923
14077
  onStart: connectWorld,
13924
14078
  onStop: ({ state }) => clearWorld(state)
13925
14079
  });
@@ -27310,7 +27464,8 @@ function syncLayers(sctx) {
27310
27464
  /**
27311
27465
  * Detaches the containers of the layers that are no longer declared and names the views that stay in them. The views
27312
27466
  * that went with the scene are gone already (the pass drops the removed ones first), and a view that plays its exit
27313
- * (`Exiting`, a root that leaves with a motion) goes with it: neither is named.
27467
+ * (`Exiting`, a root that leaves with a motion) goes with it: neither is named. A layer the loader of a scene being
27468
+ * left holds above the veil stays there: it fades out with the veil after the swap, and its views go with the loader.
27314
27469
  *
27315
27470
  * @param sctx - Domain context of the sync module.
27316
27471
  * @param next - The new table of layers.
@@ -27318,9 +27473,11 @@ function syncLayers(sctx) {
27318
27473
  function dropLeftLayers(sctx, next) {
27319
27474
  const state = sctx.ctx.state.sync;
27320
27475
  const ecs = sctx.ctx.deps.world.ecs;
27476
+ const held = state.leave.objects?.held;
27321
27477
  const stranded = [];
27322
27478
  for (const [name, entry] of state.layers) {
27323
27479
  if (next.has(name)) continue;
27480
+ if (held !== void 0 && entry.container?.parent === held) continue;
27324
27481
  if (entry.container !== void 0) detach$1(entry.container);
27325
27482
  for (const [entity, view] of state.views) if (view.layer === name && !isLeaving(ecs, entity)) stranded.push(entity);
27326
27483
  }
@@ -28070,27 +28227,95 @@ function loaderOf$1(sctx, look) {
28070
28227
  return { loader: "ring" };
28071
28228
  }
28072
28229
  /**
28073
- * Puts a layer the look drew above the veil back under the root, at the place of its layer: the layer list of the
28074
- * scene orders the root's children. A layer the list of a swap took back already, or let go, is left alone.
28230
+ * Puts a layer the look drew above the veil back under the root at alpha 1, at the place of its layer in the layer
28231
+ * list as it stands now: the list orders the root's children. A layer that list does not declare is let go. One that
28232
+ * no longer hangs above the veil (a layer list took it back, its application was lost) is left where it is.
28075
28233
  *
28076
28234
  * @param sctx - Domain context of the sync module.
28077
- * @param run - The look whose layer goes back.
28235
+ * @param container - The layer's container.
28236
+ * @param name - The layer.
28078
28237
  */
28079
- function unlift(sctx, run) {
28080
- const lifted = run.lifted;
28081
- if (lifted === void 0) return;
28082
- delete run.lifted;
28238
+ function putBack(sctx, container, name) {
28083
28239
  const state = sctx.ctx.state.sync;
28084
- if (lifted.parent !== state.leave.objects?.held) return;
28085
- const name = run.layer;
28240
+ container.alpha = 1;
28241
+ if (container.parent !== state.leave.objects?.held) return;
28086
28242
  const at = state.layerList?.findIndex((spec) => spec.name === name) ?? -1;
28087
28243
  const root = state.root;
28088
28244
  state.passesVersion += 1;
28089
28245
  if (root === void 0 || at === -1) {
28090
- detach$1(lifted);
28246
+ detach$1(container);
28091
28247
  return;
28092
28248
  }
28093
- root.addChildAt(lifted, Math.min(at, root.children.length));
28249
+ root.addChildAt(container, Math.min(at, root.children.length));
28250
+ }
28251
+ /**
28252
+ * The frames a loader layer waits at most after the veil's fade-out of `outMs`: `scenes` unmounts the loader once the
28253
+ * frame deltas it counts reach `outMs`, and `time` caps a delta at its `maxDeltaMs` (50 by default), so after a run of
28254
+ * long frames it counts at least 50 ms a frame; two frames more cover the frame it starts counting in and its last.
28255
+ *
28256
+ * @param outMs - The veil's fade-out.
28257
+ * @returns The frames.
28258
+ * @example
28259
+ * ```ts
28260
+ * parkFrames(300); // 8
28261
+ * ```
28262
+ */
28263
+ function parkFrames(outMs) {
28264
+ return Math.ceil(outMs / 50) + 2;
28265
+ }
28266
+ /**
28267
+ * Leaves a loader layer waiting where it hangs, at alpha 0, until the loader's views left it, or for `framesLeft`
28268
+ * frames at most: one layer at a time, so an older one goes back now.
28269
+ *
28270
+ * @param sctx - Domain context of the sync module.
28271
+ * @param container - The layer's container.
28272
+ * @param name - The layer.
28273
+ * @param framesLeft - The frames it waits at most.
28274
+ */
28275
+ function park(sctx, container, name, framesLeft) {
28276
+ const state = sctx.ctx.state.sync;
28277
+ const before = state.leave.parked;
28278
+ if (before !== void 0 && before.container !== container) putBack(sctx, before.container, before.layer);
28279
+ container.alpha = 0;
28280
+ state.leave.parked = {
28281
+ container,
28282
+ layer: name,
28283
+ framesLeft
28284
+ };
28285
+ state.passesVersion += 1;
28286
+ }
28287
+ /**
28288
+ * Lets the layer a look drew above the veil go. Before the swap, and once no view hangs in it, it goes back under the
28289
+ * root (`putBack`). After the swap, while the loader's views still hang in it, it waits above the veil at alpha 0:
28290
+ * `scenes` unmounts the loader projection in the first frame `outMs` has passed in, which can come a frame after the
28291
+ * veil is gone, and under the root the layer would draw the loader whole in that frame. The step puts it back once
28292
+ * its views left, or after a bounded wait (`stepParked`).
28293
+ *
28294
+ * @param sctx - Domain context of the sync module.
28295
+ * @param run - The look whose layer goes.
28296
+ */
28297
+ function unlift(sctx, run) {
28298
+ const lifted = run.lifted;
28299
+ if (lifted === void 0) return;
28300
+ delete run.lifted;
28301
+ if (run.landed && lifted.children.length > 0) park(sctx, lifted, run.layer, parkFrames(run.look.cover?.outMs ?? 0));
28302
+ else putBack(sctx, lifted, run.layer);
28303
+ }
28304
+ /**
28305
+ * Puts a layer that waits for the loader's views back once they left it, or once it waited its frames: views another
28306
+ * owner draws there stay, and are drawn whole again. A frame is asked for while it waits, so the wait ends.
28307
+ *
28308
+ * @param sctx - Domain context of the sync module.
28309
+ * @param parked - The waiting layer.
28310
+ */
28311
+ function stepParked(sctx, parked) {
28312
+ if (parked.container.children.length > 0 && parked.framesLeft > 0) {
28313
+ parked.framesLeft -= 1;
28314
+ sctx.deps.demand.request();
28315
+ return;
28316
+ }
28317
+ delete sctx.ctx.state.sync.leave.parked;
28318
+ putBack(sctx, parked.container, parked.layer);
28094
28319
  }
28095
28320
  /**
28096
28321
  * Takes the look down at once: its layer goes back, its objects leave the stage and are kept for the next look, and the
@@ -28179,8 +28404,10 @@ function paintVeil(objects, run) {
28179
28404
  objects.veil.alpha = cover.alpha * run.level;
28180
28405
  }
28181
28406
  /**
28182
- * Keeps the layer of a shown `"layer"` loader in the holder above the veil until the swap. A layer the scene does not
28183
- * declare draws nothing.
28407
+ * Keeps the layer of a shown `"layer"` loader in the holder above the veil, until the end of the fade-out after the
28408
+ * swap: the container lifted stays the look's, also when the next scene's layer list takes it back under the root or
28409
+ * does not declare it. After the swap its alpha is the veil's level. A layer the last loader left waiting is this
28410
+ * look's again, drawn whole. A layer the scene does not declare draws nothing.
28184
28411
  *
28185
28412
  * @param sctx - Domain context of the sync module.
28186
28413
  * @param objects - The engine's objects.
@@ -28188,11 +28415,19 @@ function paintVeil(objects, run) {
28188
28415
  */
28189
28416
  function lift(sctx, objects, run) {
28190
28417
  const state = sctx.ctx.state.sync;
28191
- const container = run.layer === void 0 ? void 0 : layerContainer(state, run.layer);
28192
- if (container === void 0 || container.parent === objects.held) return;
28193
- objects.held.addChild(container);
28418
+ const container = run.lifted ?? (run.layer === void 0 ? void 0 : layerContainer(state, run.layer));
28419
+ if (container === void 0) return;
28194
28420
  run.lifted = container;
28195
- state.passesVersion += 1;
28421
+ if (state.leave.parked?.container === container) {
28422
+ delete state.leave.parked;
28423
+ container.alpha = 1;
28424
+ state.passesVersion += 1;
28425
+ }
28426
+ if (container.parent !== objects.held) {
28427
+ objects.held.addChild(container);
28428
+ state.passesVersion += 1;
28429
+ }
28430
+ if (run.landed) container.alpha = run.landedLevel > 0 ? run.level / run.landedLevel : 0;
28196
28431
  }
28197
28432
  /**
28198
28433
  * Turns the ring or the spinner at the centre of the frame: one turn a second from the switch start.
@@ -28210,9 +28445,23 @@ function turn(objects, run, now, size) {
28210
28445
  turned.rotation = angle;
28211
28446
  }
28212
28447
  /**
28448
+ * Whether the loader of a running look shows in this frame: from `afterMs` after the switch start until the swap. After
28449
+ * the swap a layer loader that showed shows on, fading out with the veil; a ring, a texture, or a loader not due yet,
28450
+ * shows no more.
28451
+ *
28452
+ * @param run - The running look.
28453
+ * @param now - The clock now, ms.
28454
+ * @returns True while it shows.
28455
+ */
28456
+ function loaderShown(run, now) {
28457
+ if (run.landed) return run.shown && run.loader === "layer";
28458
+ return run.loader !== "none" && now - run.startedAt >= (run.look.loader?.afterMs ?? 0);
28459
+ }
28460
+ /**
28213
28461
  * Shows the loader once the switch took `afterMs`, until the swap: a layer loader asks its `due` then and lifts the
28214
- * layer it answers above the veil; a ring or a texture turns. A loader that comes or goes moves the walks of `shown`,
28215
- * so the loops of a lifted layer's views run while it shows.
28462
+ * layer it answers above the veil, where it stays and fades out with the veil after the swap; a ring or a texture
28463
+ * turns until the swap. A loader that comes or goes moves the walks of `shown`, so the loops of a lifted layer's views
28464
+ * run while it shows.
28216
28465
  *
28217
28466
  * @param sctx - Domain context of the sync module.
28218
28467
  * @param objects - The engine's objects.
@@ -28221,8 +28470,7 @@ function turn(objects, run, now, size) {
28221
28470
  * @returns True when the loader came, went or turns in this frame: the frame is drawn.
28222
28471
  */
28223
28472
  function paintLoader(sctx, objects, run, now) {
28224
- const afterMs = run.look.loader?.afterMs ?? 0;
28225
- const shown = !run.landed && run.loader !== "none" && now - run.startedAt >= afterMs;
28473
+ const shown = loaderShown(run, now);
28226
28474
  const due = shown && run.loader === "layer";
28227
28475
  if (due && !run.asked) ask(sctx, run);
28228
28476
  if (due) lift(sctx, objects, run);
@@ -28241,7 +28489,8 @@ function paintLoader(sctx, objects, run, now) {
28241
28489
  }
28242
28490
  /**
28243
28491
  * Shows a look from now, in place of one that runs: the veil fades in from where it stands (0, or the level of a veil
28244
- * still fading out after the last swap), the loader waits for its `afterMs`. Inert, nothing is kept.
28492
+ * still fading out after the last swap), the loader waits for its `afterMs`. A layer the last loader faded out with
28493
+ * waits unseen for its views to leave. Inert, nothing is kept.
28245
28494
  *
28246
28495
  * @param sctx - Domain context of the sync module.
28247
28496
  * @param look - The veil and the loader, resolved.
@@ -28260,6 +28509,7 @@ function showLeave(sctx, look) {
28260
28509
  steppedAt: now,
28261
28510
  level,
28262
28511
  landed: false,
28512
+ landedLevel: 1,
28263
28513
  asked: false,
28264
28514
  shown: false,
28265
28515
  ...loader
@@ -28267,26 +28517,29 @@ function showLeave(sctx, look) {
28267
28517
  sctx.deps.demand.request();
28268
28518
  }
28269
28519
  /**
28270
- * The swap came: the loader goes at once and the veil fades out over its `outMs` from where it stands; a look without
28271
- * a veil, or with `outMs: 0`, is taken down at once. Nothing runs, or the swap was told already: nothing happens.
28520
+ * The swap came: the veil fades out over its `outMs` from where it stands, and a layer loader that shows stays above
28521
+ * it and fades with it, its layer waiting unseen at the end until the loader's views left it; a ring or a texture goes
28522
+ * at once. A look without a veil, or with `outMs: 0`, is taken down at once, a layer loader's layer waiting the same.
28523
+ * Nothing runs, or the swap was told already: nothing happens.
28272
28524
  *
28273
28525
  * @param sctx - Domain context of the sync module.
28274
28526
  */
28275
28527
  function landLeave(sctx) {
28276
28528
  const run = sctx.ctx.state.sync.leave.run;
28277
28529
  if (run === void 0 || run.landed) return;
28530
+ run.landed = true;
28531
+ run.landedLevel = run.level;
28278
28532
  const cover = run.look.cover;
28279
28533
  if (cover === void 0 || cover.outMs <= 0) {
28280
28534
  takeDown(sctx);
28281
28535
  return;
28282
28536
  }
28283
- unlift(sctx, run);
28284
- run.landed = true;
28285
28537
  run.steppedAt = sctx.ctx.deps.clock.now();
28286
28538
  sctx.deps.demand.request();
28287
28539
  }
28288
28540
  /**
28289
- * The switch ended without a swap: the veil and the loader go at once. Nothing runs: nothing happens.
28541
+ * The switch ended without a swap: the veil and the loader go at once, a lifted layer back under the root. Nothing
28542
+ * runs: nothing happens.
28290
28543
  *
28291
28544
  * @param sctx - Domain context of the sync module.
28292
28545
  */
@@ -28297,13 +28550,16 @@ function dropLeave(sctx) {
28297
28550
  /**
28298
28551
  * The look of this frame, before the decision: the veil's level from the clock, the loader once due, both placed over
28299
28552
  * the canvas as it stands, and a frame asked for while either moves. A look whose veil faded out after the swap is
28300
- * taken down. One field read and no allocation while no look runs; a lost device leaves the look waiting for the
28301
- * restore, which makes its objects again.
28553
+ * taken down, a layer loader fading with it left waiting; a waiting layer whose views left goes back. Two field reads
28554
+ * and no allocation while no look runs, none during a fade or a wait either; a lost device leaves the look waiting for
28555
+ * the restore, which makes its objects again.
28302
28556
  *
28303
28557
  * @param sctx - Domain context of the sync module.
28304
28558
  */
28305
28559
  function stepLeave(sctx) {
28306
- const run = sctx.ctx.state.sync.leave.run;
28560
+ const leave = sctx.ctx.state.sync.leave;
28561
+ const run = leave.run;
28562
+ if (leave.parked !== void 0) stepParked(sctx, leave.parked);
28307
28563
  if (run === void 0) return;
28308
28564
  const objects = objectsOf(sctx);
28309
28565
  const stage = sctx.deps.host.stage();
@@ -28321,18 +28577,19 @@ function stepLeave(sctx) {
28321
28577
  if (moved || loading) sctx.deps.demand.request();
28322
28578
  }
28323
28579
  /**
28324
- * Forgets the objects of a lost application: they go with its stage, and so does a layer lifted above the veil. The
28325
- * running look stays: the step makes its objects again on the restored device.
28580
+ * Forgets the objects of a lost application: they go with its stage, and so does a layer lifted above the veil or
28581
+ * waiting there. The running look stays: the step makes its objects again on the restored device.
28326
28582
  *
28327
28583
  * @param state - The sync branch of the plugin state.
28328
28584
  */
28329
28585
  function forgetLeave$1(state) {
28330
28586
  delete state.leave.objects;
28587
+ delete state.leave.parked;
28331
28588
  if (state.leave.run !== void 0) delete state.leave.run.lifted;
28332
28589
  }
28333
28590
  /**
28334
- * Drops the look and frees the engine's objects when the plugin stops. A lifted layer is the layer table's and the
28335
- * spinner's texture is the game's: neither is freed with them.
28591
+ * Drops the look and frees the engine's objects when the plugin stops. A lifted or waiting layer is the layer table's
28592
+ * and the spinner's texture is the game's: neither is freed with them.
28336
28593
  *
28337
28594
  * @param state - The sync branch of the plugin state.
28338
28595
  */
@@ -28340,6 +28597,7 @@ function stopLeave(state) {
28340
28597
  const objects = state.leave.objects;
28341
28598
  delete state.leave.run;
28342
28599
  delete state.leave.objects;
28600
+ delete state.leave.parked;
28343
28601
  if (objects === void 0) return;
28344
28602
  objects.held.removeChildren();
28345
28603
  objects.top.destroy({ children: true });
@@ -32749,7 +33007,7 @@ function checkTree(sctx, entities) {
32749
33007
  /** Label of the container the viewport transform is written on. */
32750
33008
  const ROOT_LABEL = "renderer.root";
32751
33009
  /** The change steps of a pass that write an entity's view: what `runStep` does for each changed component. */
32752
- const STEP = {
33010
+ const STEP$1 = {
32753
33011
  transform: 0,
32754
33012
  sprite: 1,
32755
33013
  nineSlice: 2,
@@ -32942,27 +33200,27 @@ function createSyncApi(ctx, deps) {
32942
33200
  */
32943
33201
  const runStep = (step, entity, view) => {
32944
33202
  switch (step) {
32945
- case STEP.transform:
33203
+ case STEP$1.transform:
32946
33204
  applyTransform(sctx, entity, view);
32947
33205
  resort(sctx, entity, view);
32948
33206
  break;
32949
- case STEP.sprite:
33207
+ case STEP$1.sprite:
32950
33208
  if (applySprite(sctx, entity, view)) applyTransform(sctx, entity, view);
32951
33209
  break;
32952
- case STEP.nineSlice:
33210
+ case STEP$1.nineSlice:
32953
33211
  applyNineSlice(sctx, entity, view);
32954
33212
  break;
32955
- case STEP.shape:
33213
+ case STEP$1.shape:
32956
33214
  applyShape(sctx, entity, view);
32957
33215
  break;
32958
- case STEP.order:
33216
+ case STEP$1.order:
32959
33217
  resort(sctx, entity, view);
32960
33218
  break;
32961
- case STEP.layer:
33219
+ case STEP$1.layer:
32962
33220
  attach$1(sctx, entity, view);
32963
33221
  resort(sctx, entity, view);
32964
33222
  break;
32965
- case STEP.parent:
33223
+ case STEP$1.parent:
32966
33224
  rehang(entity, view);
32967
33225
  break;
32968
33226
  default: if (view.display === adapterEntry) updateAdapterView(sctx, entity, view);
@@ -32994,14 +33252,14 @@ function createSyncApi(ctx, deps) {
32994
33252
  const view = state.views.get(entity);
32995
33253
  if (view !== void 0) guardedStep(step, entity, view);
32996
33254
  };
32997
- const onTransform = (entity) => stepOn(STEP.transform, entity);
32998
- const onSprite = (entity) => stepOn(STEP.sprite, entity);
32999
- const onNineSlice = (entity) => stepOn(STEP.nineSlice, entity);
33000
- const onShape = (entity) => stepOn(STEP.shape, entity);
33001
- const onOrder = (entity) => stepOn(STEP.order, entity);
33002
- const onLayer = (entity) => stepOn(STEP.layer, entity);
33003
- const onParent = (entity) => stepOn(STEP.parent, entity);
33004
- const onAdapter = (entity) => stepOn(STEP.adapter, entity);
33255
+ const onTransform = (entity) => stepOn(STEP$1.transform, entity);
33256
+ const onSprite = (entity) => stepOn(STEP$1.sprite, entity);
33257
+ const onNineSlice = (entity) => stepOn(STEP$1.nineSlice, entity);
33258
+ const onShape = (entity) => stepOn(STEP$1.shape, entity);
33259
+ const onOrder = (entity) => stepOn(STEP$1.order, entity);
33260
+ const onLayer = (entity) => stepOn(STEP$1.layer, entity);
33261
+ const onParent = (entity) => stepOn(STEP$1.parent, entity);
33262
+ const onAdapter = (entity) => stepOn(STEP$1.adapter, entity);
33005
33263
  /**
33006
33264
  * A new `Display` object of the game replaces the old view outright, unless this pass built it, or it waits aside
33007
33265
  * for its view (spec 31): the chunk that makes it reads the new object.
@@ -34012,7 +34270,7 @@ function createRendererApi(ctx) {
34012
34270
  * @param ctx - Kernel context of the renderer plugin.
34013
34271
  * @returns The hooks of the plugin.
34014
34272
  */
34015
- function createHandlers$5(ctx) {
34273
+ function createHandlers$6(ctx) {
34016
34274
  let monitor;
34017
34275
  /**
34018
34276
  * The monitor module, built once.
@@ -34473,7 +34731,7 @@ const rendererPlugin = /*#__PURE__*/ createPlugin$1("renderer", {
34473
34731
  events: (register) => register.map({ "renderer:device-lost": "The GPU device or context was lost; the game is paused" }),
34474
34732
  createState: createRendererState,
34475
34733
  api: createRendererApi,
34476
- hooks: createHandlers$5,
34734
+ hooks: createHandlers$6,
34477
34735
  onStart: startRenderer,
34478
34736
  onStop: ({ config, state }) => stopRenderer({
34479
34737
  config,
@@ -34590,7 +34848,7 @@ function countPlaying(ecs, entity, delta) {
34590
34848
  * frameMsOf(10); // 100
34591
34849
  * ```
34592
34850
  */
34593
- function frameMsOf(fps) {
34851
+ function frameMsOf$1(fps) {
34594
34852
  return fps > 0 ? 1e3 / fps : 0;
34595
34853
  }
34596
34854
  /**
@@ -34605,7 +34863,7 @@ function frameMsOf(fps) {
34605
34863
  * ```
34606
34864
  */
34607
34865
  function framesDurationMs(keys, fps) {
34608
- return keys.length * frameMsOf(fps);
34866
+ return keys.length * frameMsOf$1(fps);
34609
34867
  }
34610
34868
  /**
34611
34869
  * Which key of the list belongs to a point of the step. A looping list wraps; a list that plays
@@ -34623,7 +34881,7 @@ function framesDurationMs(keys, fps) {
34623
34881
  * ```
34624
34882
  */
34625
34883
  function frameIndexAt(keys, fps, loop, elapsed) {
34626
- const frameMs = frameMsOf(fps);
34884
+ const frameMs = frameMsOf$1(fps);
34627
34885
  const raw = frameMs > 0 ? Math.floor(elapsed / frameMs) : keys.length - 1;
34628
34886
  if (loop) return (raw % keys.length + keys.length) % keys.length;
34629
34887
  return Math.min(Math.max(raw, 0), keys.length - 1);
@@ -40405,7 +40663,7 @@ function createSwap$1(ctx, reload = reloadPage$1) {
40405
40663
  * means the page reload; a test passes a spy.
40406
40664
  * @returns The two hooks of the plugin.
40407
40665
  */
40408
- function createHandlers$4(ctx, reload) {
40666
+ function createHandlers$5(ctx, reload) {
40409
40667
  let assets;
40410
40668
  let swap;
40411
40669
  return {
@@ -40537,7 +40795,7 @@ const assetsPlugin = /*#__PURE__*/ createPlugin$1("assets", {
40537
40795
  }),
40538
40796
  createState: createAssetsState,
40539
40797
  api: createAssetsApi,
40540
- hooks: createHandlers$4,
40798
+ hooks: createHandlers$5,
40541
40799
  onInit: connectAssets,
40542
40800
  onStart: startAssets,
40543
40801
  onStop: ({ state }) => releaseAll(state)
@@ -40560,6 +40818,236 @@ function createScenesApi(ctx) {
40560
40818
  };
40561
40819
  }
40562
40820
  //#endregion
40821
+ //#region src/plugins/scenes/progress.ts
40822
+ /**
40823
+ * @file scenes plugin — the switch a leave loader projection reads (F107 part 1). `world.projection.feed` hands its
40824
+ * `from` a `SceneSwitch`, `{ from, to, progress }`, as a third argument: while a scene stands, its held loader reads
40825
+ * `{ from: current, to: current, progress: 0 }`; a switch feeds it the scene left, the scene entered and the share of
40826
+ * the switch's bundles loaded, in steps of 0.01 up to 1: a bundle loaded at the start counts whole, one being loaded
40827
+ * counts its files from `assets:bundle-progress`, and every bundle the scene stage finds loaded counts whole (a bundle
40828
+ * with no file sends no progress). Only a loader scenes holds, or one with no view yet (A2, mounted at its due), is
40829
+ * fed: a projection another owner shows never is. The progress is counted in integer thousandths, so the last value
40830
+ * fed is exactly 1.
40831
+ */
40832
+ /** A bundle loaded, and a switch whose bundles are all in, in thousandths. */
40833
+ const WHOLE = 1e3;
40834
+ /** The growth of the progress, in thousandths, a switch waits for before it feeds the loader again: 0.01. */
40835
+ const STEP = 10;
40836
+ /**
40837
+ * Reads the committed state a scene's `bundles` gets: the frozen trees of the store, in a frozen
40838
+ * wrapper. During the scene stage no node writes, so it is the state the node is entered with.
40839
+ *
40840
+ * @param ctx - Domain context of the plugin.
40841
+ * @returns The committed `player` and `session`.
40842
+ */
40843
+ function committedState(ctx) {
40844
+ const { player, session } = ctx.deps.model.store.snapshot();
40845
+ return Object.freeze({
40846
+ player,
40847
+ session
40848
+ });
40849
+ }
40850
+ /**
40851
+ * The share of a bundle one progress event tells, in thousandths, floored: the whole once every file settled.
40852
+ *
40853
+ * @param loaded - The settled files.
40854
+ * @param total - The files of the bundle.
40855
+ * @returns 0 to 1000.
40856
+ * @example
40857
+ * ```ts
40858
+ * shareOf(1, 3); // 333
40859
+ * ```
40860
+ */
40861
+ function shareOf(loaded, total) {
40862
+ return loaded >= total ? WHOLE : Math.floor(WHOLE * loaded / total);
40863
+ }
40864
+ /**
40865
+ * The progress of a switch, in thousandths: the mean of its bundles' shares, floored; the whole with no bundle.
40866
+ *
40867
+ * @param bundles - The table of the switch.
40868
+ * @returns 0 to 1000.
40869
+ * @example
40870
+ * ```ts
40871
+ * meanOf([{ bundle: "board", share: 250 }, { bundle: "ep01", share: 0 }]); // 125
40872
+ * ```
40873
+ */
40874
+ function meanOf(bundles) {
40875
+ if (bundles.length === 0) return WHOLE;
40876
+ let sum = 0;
40877
+ for (const row of bundles) sum += row.share;
40878
+ return Math.floor(sum / bundles.length);
40879
+ }
40880
+ /**
40881
+ * Tells whether the progress moved far enough to feed the loader again: by 0.01 since the last feed, or onto the whole
40882
+ * for the first time.
40883
+ *
40884
+ * @param fed - The progress last fed, in thousandths.
40885
+ * @param now - The progress now, in thousandths.
40886
+ * @returns True when the loader is fed.
40887
+ * @example
40888
+ * ```ts
40889
+ * isStep(995, 1000); // true: the switch is done
40890
+ * ```
40891
+ */
40892
+ function isStep(fed, now) {
40893
+ return now - fed >= STEP || now === WHOLE && fed < WHOLE;
40894
+ }
40895
+ /**
40896
+ * The row of a bundle in the table of a switch.
40897
+ *
40898
+ * @param bundles - The table.
40899
+ * @param bundle - The bundle.
40900
+ * @returns Its row, or `undefined` for a bundle the switch does not name.
40901
+ * @example
40902
+ * ```ts
40903
+ * rowOf([{ bundle: "board", share: 0 }], "ep01"); // undefined
40904
+ * ```
40905
+ */
40906
+ function rowOf(bundles, bundle) {
40907
+ for (const row of bundles) if (row.bundle === bundle) return row;
40908
+ }
40909
+ /**
40910
+ * The table of a switch: one row per bundle the scene being switched to names for the committed state, a bundle
40911
+ * loaded already counted whole. A `bundles` that throws gives an empty table, a switch done: the `scene` stage throws
40912
+ * it again, as it does without a loader.
40913
+ *
40914
+ * @param ctx - Domain context of the plugin.
40915
+ * @param scene - The scene being switched to.
40916
+ * @returns The rows, in the order the scene names its bundles.
40917
+ */
40918
+ function sharesOf(ctx, scene) {
40919
+ let named;
40920
+ try {
40921
+ named = namedBundles(scene, committedState(ctx));
40922
+ } catch {
40923
+ return [];
40924
+ }
40925
+ const assets = ctx.deps.assets;
40926
+ return named.map((bundle) => ({
40927
+ bundle,
40928
+ share: assets.isLoaded(bundle) ? WHOLE : 0
40929
+ }));
40930
+ }
40931
+ /**
40932
+ * Starts feeding the loader projection of a switch, before it is due: the table of its bundles, one `feed` bound to
40933
+ * the name, and the first value, `{ from, to, progress }`. A held loader only stores it, and the show writes it into
40934
+ * the view built ahead once; a loader with no view (A2) reads it when it is mounted at its due. A projection another
40935
+ * owner shows is not fed: a held one answers no entity either, so a view means someone else's.
40936
+ *
40937
+ * @param ctx - Domain context of the plugin.
40938
+ * @param leaving - The look of the switch: it keeps what it feeds.
40939
+ * @param name - The loader projection.
40940
+ * @param between - The scene being left and the scene being switched to.
40941
+ * @param between.from - The scene being left.
40942
+ * @param between.to - The scene being switched to.
40943
+ */
40944
+ function startFeeding(ctx, leaving, name, between) {
40945
+ const projection = ctx.deps.world.projection;
40946
+ if (projection.entitiesOf(name).length > 0) return;
40947
+ const bundles = sharesOf(ctx, between.to);
40948
+ const feeding = {
40949
+ name,
40950
+ from: between.from.id,
40951
+ to: between.to.id,
40952
+ bundles,
40953
+ fed: meanOf(bundles),
40954
+ feed: (sw) => projection.feed(name, sw)
40955
+ };
40956
+ leaving.feeding = feeding;
40957
+ feeding.feed({
40958
+ from: feeding.from,
40959
+ to: feeding.to,
40960
+ progress: feeding.fed / WHOLE
40961
+ });
40962
+ }
40963
+ /**
40964
+ * Feeds the loader a new switch when the progress moved by a step since the last feed; below the step it only reads
40965
+ * numbers.
40966
+ *
40967
+ * @param feeding - What the switch feeds.
40968
+ */
40969
+ function feedStep(feeding) {
40970
+ const now = meanOf(feeding.bundles);
40971
+ if (!isStep(feeding.fed, now)) return;
40972
+ feeding.fed = now;
40973
+ feeding.feed({
40974
+ from: feeding.from,
40975
+ to: feeding.to,
40976
+ progress: now / WHOLE
40977
+ });
40978
+ }
40979
+ /**
40980
+ * Counts one settled file of a bundle of the running switch, from the `assets:bundle-progress` hook: the bundle's share
40981
+ * is set, and the loader is fed when the progress moved by a step. With no switch (none runs, or it swapped or
40982
+ * dropped: `endLeave` takes it out of the state), no loader fed, or a bundle the switch does not name, nothing happens.
40983
+ * Below the step it reads and writes numbers only: no allocation.
40984
+ *
40985
+ * @param state - The plugin state.
40986
+ * @param bundle - The bundle the event names.
40987
+ * @param loaded - Its settled files.
40988
+ * @param total - Its files.
40989
+ */
40990
+ function countProgress(state, bundle, loaded, total) {
40991
+ const feeding = state.leaving?.feeding;
40992
+ if (feeding === void 0) return;
40993
+ const row = rowOf(feeding.bundles, bundle);
40994
+ if (row === void 0) return;
40995
+ row.share = shareOf(loaded, total);
40996
+ feedStep(feeding);
40997
+ }
40998
+ /**
40999
+ * Counts every bundle of the running switch whole once the scene stage has its loads in: a bundle with no file, which
41000
+ * sends no progress, counts then, and the loader reads 1 before the warm and the build. With no loader fed, nothing
41001
+ * happens.
41002
+ *
41003
+ * @param state - The plugin state.
41004
+ */
41005
+ function countLoaded(state) {
41006
+ const feeding = state.leaving?.feeding;
41007
+ if (feeding === void 0) return;
41008
+ for (const row of feeding.bundles) row.share = WHOLE;
41009
+ feedStep(feeding);
41010
+ }
41011
+ /**
41012
+ * Feeds a loader scenes holds the switch of the scene that stands, right after the hold: `world` keeps the first
41013
+ * value fed after a hold for the view it builds ahead, so the loader is built for `{ from: current, to: current,
41014
+ * progress: 0 }` and not for the last switch.
41015
+ *
41016
+ * @param ctx - Domain context of the plugin.
41017
+ * @param name - The loader held.
41018
+ */
41019
+ function feedStanding(ctx, name) {
41020
+ const scene = ctx.state.current;
41021
+ if (scene === void 0) return;
41022
+ ctx.deps.world.projection.feed(name, {
41023
+ from: scene,
41024
+ to: scene,
41025
+ progress: 0
41026
+ });
41027
+ }
41028
+ //#endregion
41029
+ //#region src/plugins/scenes/handlers.ts
41030
+ /**
41031
+ * @file scenes plugin — the hook of `assets` (F107 part 1): every settled file of a bundle of the running switch moves
41032
+ * the progress its leave loader projection reads (`progress.ts`). It reads the plugin state only, so it allocates
41033
+ * nothing for an event that does not move the progress by a step. A bundle that is loaded is counted by the switch
41034
+ * itself, at its start and once the scene stage has its loads, not on `assets:bundle-loaded`: the kernel awaits each
41035
+ * handler of an event in plugin order, so a scenes handler there would move the font install of `text`, a later
41036
+ * plugin, one microtask later.
41037
+ */
41038
+ /**
41039
+ * Creates the hook handler. It reads the state only, which exists when the kernel registers hooks: the `feed` of a
41040
+ * switch is bound to `world` when the switch starts.
41041
+ *
41042
+ * @param ctx - Kernel context of the scenes plugin.
41043
+ * @returns The one hook of the plugin.
41044
+ */
41045
+ function createHandlers$4(ctx) {
41046
+ return { "assets:bundle-progress": ({ bundle, loaded, total }) => {
41047
+ countProgress(ctx.state, bundle, loaded, total);
41048
+ } };
41049
+ }
41050
+ //#endregion
40563
41051
  //#region src/plugins/scenes/swap.ts
40564
41052
  /**
40565
41053
  * The projections of the scene that leaves which the scene that comes does not list. A projection
@@ -40649,8 +41137,8 @@ function swapIn(ctx, scene, named, build) {
40649
41137
  const SECOND_MS$1 = 1e3;
40650
41138
  /** The share of a frame interval `"auto"` gives the building work: two thirds. */
40651
41139
  const BUILD_SHARE = 2 / 3;
40652
- /** The budget of a frame when `time` answers no usable frame rate: two thirds of a 60 Hz frame, ≈ 11.1 ms. */
40653
- const FALLBACK_BUDGET_MS = SECOND_MS$1 / 60 * BUILD_SHARE;
41140
+ /** The frame interval when `time` answers no usable frame rate: a 60 Hz frame, ≈ 16.7 ms. */
41141
+ const FALLBACK_FRAME_MS = SECOND_MS$1 / 60;
40654
41142
  /**
40655
41143
  * Tells whether a value is a number a frame can count with: finite and above 0. Pure.
40656
41144
  *
@@ -40679,6 +41167,17 @@ function agentNow(ctx) {
40679
41167
  return clock === void 0 ? 0 : clock();
40680
41168
  }
40681
41169
  /**
41170
+ * The frame interval the loop runs at now, `1000 / time.rate().fps`. A rate that is not a finite number above 0 gives
41171
+ * a 60 Hz frame.
41172
+ *
41173
+ * @param ctx - Domain context of the plugin.
41174
+ * @returns Milliseconds of one frame.
41175
+ */
41176
+ function frameMsOf(ctx) {
41177
+ const { fps } = ctx.deps.time.rate();
41178
+ return isPositiveFinite(fps) ? SECOND_MS$1 / fps : FALLBACK_FRAME_MS;
41179
+ }
41180
+ /**
40682
41181
  * The building budget of a frame for a build that starts now: the number a game configured, or
40683
41182
  * for `"auto"` two thirds of the frame interval the loop runs at, `(1000 / time.rate().fps) * 2 / 3`,
40684
41183
  * read once here. A rate that is not a finite number above 0 gives two thirds of a 60 Hz frame.
@@ -40689,8 +41188,7 @@ function agentNow(ctx) {
40689
41188
  function budgetOf(ctx) {
40690
41189
  const { buildMs } = ctx.config;
40691
41190
  if (buildMs !== "auto") return buildMs;
40692
- const { fps } = ctx.deps.time.rate();
40693
- return isPositiveFinite(fps) ? SECOND_MS$1 / fps * BUILD_SHARE : FALLBACK_BUDGET_MS;
41191
+ return frameMsOf(ctx) * BUILD_SHARE;
40694
41192
  }
40695
41193
  /**
40696
41194
  * Ends the build with the swap: its listeners go and the record is dropped, then the swap of a
@@ -40852,109 +41350,38 @@ function dropBuild(build) {
40852
41350
  build.resolve();
40853
41351
  }
40854
41352
  //#endregion
40855
- //#region src/plugins/scenes/leave.ts
41353
+ //#region src/plugins/scenes/loader.ts
40856
41354
  /**
40857
- * What a game gets when it writes nothing: black at 45 %, 50 ms in and 150 ms out, the engine's ring once the switch took
40858
- * 400 ms. The level under `config.leave`, and where a part written over `false` starts. `index.ts` writes the same
40859
- * value inline as the plugin's default config; a test pins the two equal.
41355
+ * Does nothing: the remover of a fade before its frame callback is registered.
40860
41356
  */
40861
- const FALLBACK_LEAVE = Object.freeze({
40862
- cover: Object.freeze({
40863
- color: 0,
40864
- alpha: .45,
40865
- inMs: 50,
40866
- outMs: 150
40867
- }),
40868
- loader: Object.freeze({ afterMs: 400 })
40869
- });
41357
+ function noFrame() {}
40870
41358
  /**
40871
- * Merges one level's veil over the one below, field by field. `false` turns it off; a veil written over `false`
40872
- * starts from the engine's.
41359
+ * Tells whether an entry of a feature's `projections` list names its layer. The key carries whatever the game put
41360
+ * there, so an entry that does not is skipped.
40873
41361
  *
40874
- * @param below - The veil of the levels below, or `false`.
40875
- * @param over - What this level writes: nothing, `false` or fields.
40876
- * @returns The veil, or `false`.
40877
- * @example
40878
- * ```ts
40879
- * coverOver(false, { alpha: 0.6 }); // { color: 0, alpha: 0.6, inMs: 50, outMs: 150 }
40880
- * ```
40881
- */
40882
- function coverOver(below, over) {
40883
- if (over === void 0) return below;
40884
- if (over === false) return false;
40885
- const base = below === false ? FALLBACK_LEAVE.cover : below;
40886
- return {
40887
- color: over.color ?? base.color,
40888
- alpha: over.alpha ?? base.alpha,
40889
- inMs: over.inMs ?? base.inMs,
40890
- outMs: over.outMs ?? base.outMs
40891
- };
40892
- }
40893
- /**
40894
- * The look of a loader: its projection, else its texture, else nothing (the engine's ring).
40895
- *
40896
- * @param loader - A level that names a look, or the level below.
40897
- * @returns At most one of the two fields.
40898
- * @example
40899
- * ```ts
40900
- * lookOf({ texture: "ui.loader.ring", projection: "loading" }); // { projection: "loading" }
40901
- * ```
40902
- */
40903
- function lookOf(loader) {
40904
- if (loader.projection !== void 0) return { projection: loader.projection };
40905
- if (loader.texture !== void 0) return { texture: loader.texture };
40906
- return {};
40907
- }
40908
- /**
40909
- * Merges one level's loader over the one below. `afterMs` is a field of its own; `texture` and `projection` are one
40910
- * choice: a level that names either replaces both of the level below. `false` turns it off; a loader written over
40911
- * `false` starts from the engine's.
40912
- *
40913
- * @param below - The loader of the levels below, or `false`.
40914
- * @param over - What this level writes: nothing, `false` or fields.
40915
- * @returns The loader, or `false`.
41362
+ * @param entry - One entry of the list.
41363
+ * @returns True for an object with a string `name` and a string `layer`.
40916
41364
  * @example
40917
41365
  * ```ts
40918
- * loaderOver({ afterMs: 400, projection: "loading" }, { texture: "ui.loader.ring" }); // { afterMs: 400, texture: "ui.loader.ring" }
41366
+ * isLayered({ name: "loading", layer: "loading", view: () => [] }); // true
40919
41367
  * ```
40920
41368
  */
40921
- function loaderOver(below, over) {
40922
- if (over === void 0) return below;
40923
- if (over === false) return false;
40924
- const base = below === false ? FALLBACK_LEAVE.loader : below;
40925
- const named = over.texture !== void 0 || over.projection !== void 0;
40926
- return {
40927
- afterMs: over.afterMs ?? base.afterMs,
40928
- ...lookOf(named ? over : base)
40929
- };
41369
+ function isLayered(entry) {
41370
+ return typeof entry === "object" && entry !== null && "name" in entry && typeof entry.name === "string" && "layer" in entry && typeof entry.layer === "string";
40930
41371
  }
40931
41372
  /**
40932
- * Resolves what a switch shows over the scene being left: the scene's `leave` over the config's over the engine's,
40933
- * field by field. `false` at a level turns both parts off there.
41373
+ * The layer a projection's spec names, read from the `projections` of the features, the list `world` registers.
40934
41374
  *
40935
- * @param config - `config.leave`.
40936
- * @param scene - The `leave` of the scene being left.
40937
- * @returns Both parts, each resolved or `false`; `undefined` when both are off.
40938
- * @example
40939
- * ```ts
40940
- * leaveOf({ loader: false }, { cover: { alpha: 0.6 } }); // { cover: { color: 0, alpha: 0.6, inMs: 50, outMs: 150 }, loader: false }
40941
- * ```
41375
+ * @param ctx - Domain context of the plugin.
41376
+ * @param name - The projection.
41377
+ * @returns Its `layer`, or `undefined` when no feature brings it.
40942
41378
  */
40943
- function leaveOf(config, scene) {
40944
- let cover = FALLBACK_LEAVE.cover;
40945
- let loader = FALLBACK_LEAVE.loader;
40946
- for (const level of [config, scene]) if (level === false) {
40947
- cover = false;
40948
- loader = false;
40949
- } else if (level !== void 0) {
40950
- cover = coverOver(cover, level.cover);
40951
- loader = loaderOver(loader, level.loader);
41379
+ function specLayerOf(ctx, name) {
41380
+ for (const feature of ctx.deps.flow.features.all()) {
41381
+ const list = feature.description.projections;
41382
+ if (!Array.isArray(list)) continue;
41383
+ for (const entry of list) if (isLayered(entry) && entry.name === name) return entry.layer;
40952
41384
  }
40953
- if (cover === false && loader === false) return void 0;
40954
- return {
40955
- cover,
40956
- loader
40957
- };
40958
41385
  }
40959
41386
  /**
40960
41387
  * The layer a mounted projection's views draw in, read from its first view.
@@ -40969,12 +41396,31 @@ function layerOf(ctx, name) {
40969
41396
  return entity === void 0 ? void 0 : ecs.get(entity, Layer)?.name;
40970
41397
  }
40971
41398
  /**
40972
- * Unmounts the loader projection a switch mounted, once: one it did not mount is left alone.
41399
+ * Refuses a loader whose layer a projection of the scene being left draws in too: lifted above the veil, that layer
41400
+ * would take the scene's own views with it. Warned; the renderer draws the ring.
41401
+ *
41402
+ * @param ctx - Domain context of the plugin.
41403
+ * @param name - The loader projection.
41404
+ * @param layer - The layer of the loader.
41405
+ * @param from - The scene being left.
41406
+ * @returns True when one of the scene's projections has a view in that layer.
41407
+ */
41408
+ function refusesShared(ctx, name, layer, from) {
41409
+ if (!from.projections.some((other) => layerOf(ctx, other) === layer)) return false;
41410
+ ctx.log.warn("scenes:loader-layer-shared", {
41411
+ projection: name,
41412
+ layer,
41413
+ scene: from.id
41414
+ });
41415
+ return true;
41416
+ }
41417
+ /**
41418
+ * Unmounts the loader projection a switch mounted or showed, at once: one it did not is left alone.
40973
41419
  *
40974
41420
  * @param ctx - Domain context of the plugin.
40975
41421
  * @param leaving - The look of the switch.
40976
41422
  */
40977
- function unmountLoader(ctx, leaving) {
41423
+ function dropLoader(ctx, leaving) {
40978
41424
  const name = leaving.projection;
40979
41425
  if (name === void 0) return;
40980
41426
  delete leaving.projection;
@@ -41008,44 +41454,364 @@ function mountOnce(ctx, name, from, leaving) {
41008
41454
  return true;
41009
41455
  }
41010
41456
  /**
41011
- * Tells whether a projection of the scene being left draws in a layer: lifted above the veil, that layer would take
41012
- * the scene's own views with it.
41457
+ * Mounts a loader projection the scene being left does not hold, in the frame it is due (A2), and answers the layer its
41458
+ * views draw in. A mount that throws, a layer a projection of the scene draws in too and a projection with no view give
41459
+ * the engine's ring.
41013
41460
  *
41014
41461
  * @param ctx - Domain context of the plugin.
41462
+ * @param name - The loader projection.
41015
41463
  * @param from - The scene being left.
41016
- * @param layer - The layer of the loader.
41017
- * @returns True when one of its projections has a view in that layer.
41464
+ * @param leaving - The look of the switch: it keeps the name to unmount at the end.
41465
+ * @returns The layer, or `undefined` for the ring.
41018
41466
  */
41019
- function sharesLayer(ctx, from, layer) {
41020
- return from.projections.some((other) => layerOf(ctx, other) === layer);
41467
+ function mountLoader(ctx, name, from, leaving) {
41468
+ if (!mountOnce(ctx, name, from, leaving)) return void 0;
41469
+ const layer = layerOf(ctx, name);
41470
+ if (layer === void 0 || !refusesShared(ctx, name, layer, from)) return layer;
41471
+ dropLoader(ctx, leaving);
41021
41472
  }
41022
41473
  /**
41023
- * Mounts a loader projection once its loader is due, called by the renderer in that frame, and answers the layer its
41024
- * views draw in, which the renderer draws above the veil. A mount that throws, a layer a projection of the scene being
41025
- * left draws in too, and a projection with no view give the engine's ring. A switch that ended meanwhile mounts
41026
- * nothing.
41474
+ * Shows the loader the scene being left holds: built already, it is on the screen in the next frame, the same views,
41475
+ * no spawn. Its layer is its spec's: the view `show` brings is reconciled in the next frame, so it has no `Layer` yet.
41476
+ * One whose layer a projection of the scene draws in too is unmounted instead, and the renderer draws the ring.
41477
+ *
41478
+ * @param ctx - Domain context of the plugin.
41479
+ * @param held - The loader the scene holds.
41480
+ * @param from - The scene being left.
41481
+ * @param leaving - The look of the switch: it keeps the name to unmount or fade out at the end.
41482
+ * @returns The layer, or `undefined` for the ring.
41483
+ */
41484
+ function showHeld(ctx, held, from, leaving) {
41485
+ const projection = ctx.deps.world.projection;
41486
+ delete ctx.state.held;
41487
+ if (refusesShared(ctx, held.name, held.layer, from)) {
41488
+ projection.unmount([held.name]);
41489
+ return;
41490
+ }
41491
+ projection.show(held.name);
41492
+ leaving.projection = held.name;
41493
+ return held.layer;
41494
+ }
41495
+ /**
41496
+ * The `due` of a loader projection, called by the renderer in the first frame the loader is due: a loader the scene
41497
+ * being left holds is shown, any other is mounted then (A2). It answers the layer the renderer draws above the veil.
41498
+ * A switch that ended meanwhile shows nothing.
41027
41499
  *
41028
41500
  * @param ctx - Domain context of the plugin.
41029
41501
  * @param name - The loader projection.
41030
41502
  * @param from - The scene being left.
41031
- * @param leaving - The look of the switch: it keeps the name to unmount at the end.
41503
+ * @param leaving - The look of the switch.
41032
41504
  * @returns The layer, or `undefined` for the ring.
41033
41505
  */
41034
- function mountLoader(ctx, name, from, leaving) {
41035
- if (leaving.done || !mountOnce(ctx, name, from, leaving)) return void 0;
41036
- const layer = layerOf(ctx, name);
41037
- if (layer === void 0 || !sharesLayer(ctx, from, layer)) return layer;
41038
- ctx.log.warn("scenes:loader-layer-shared", {
41039
- projection: name,
41040
- layer,
41041
- scene: from.id
41042
- });
41043
- unmountLoader(ctx, leaving);
41506
+ function dueLoader(ctx, name, from, leaving) {
41507
+ if (leaving.done) return void 0;
41508
+ const held = ctx.state.held;
41509
+ if (held !== void 0 && held.name === name) return showHeld(ctx, held, from, leaving);
41510
+ return mountLoader(ctx, name, from, leaving);
41511
+ }
41512
+ /**
41513
+ * Holds a loader for the next switch and feeds it the switch of the scene that stands right after, in the same call:
41514
+ * the first value fed after a hold is the one `world` builds the held view for. A hold `world` refuses (a `lift` the
41515
+ * scene does not declare) is warned and holds nothing: the loader is then mounted when it is due, and that mount is
41516
+ * refused the same way.
41517
+ *
41518
+ * @param ctx - Domain context of the plugin.
41519
+ * @param loader - The loader to hold.
41520
+ */
41521
+ function holdNow(ctx, loader) {
41522
+ try {
41523
+ ctx.deps.world.projection.hold([loader.name], ctx.state.owner);
41524
+ } catch (error) {
41525
+ ctx.log.warn("scenes:loader-unmounted", {
41526
+ projection: loader.name,
41527
+ scene: ctx.state.current,
41528
+ error
41529
+ });
41530
+ return;
41531
+ }
41532
+ feedStanding(ctx, loader.name);
41533
+ ctx.state.held = loader;
41534
+ }
41535
+ /**
41536
+ * The loader a scene that stands may hold, by the rules of A2: a projection the scene does not list, whose spec's
41537
+ * layer the scene declares.
41538
+ *
41539
+ * @param ctx - Domain context of the plugin.
41540
+ * @param scene - The scene that stands.
41541
+ * @param name - The projection its leave loader names.
41542
+ * @returns The loader, or `undefined` when the scene cannot hold it.
41543
+ */
41544
+ function loaderToHold(ctx, scene, name) {
41545
+ if (scene.projections.includes(name)) return void 0;
41546
+ const layer = specLayerOf(ctx, name);
41547
+ if (layer === void 0 || !scene.layers.some((spec) => spec.name === layer)) return void 0;
41548
+ return {
41549
+ name,
41550
+ layer
41551
+ };
41552
+ }
41553
+ /**
41554
+ * Holds the leave loader of a scene that stands for its next switch: `world` builds the view of its `from`'s first
41555
+ * item in idle frames and keeps it hidden, so the frame the loader is due only shows it. A loader the scene before held
41556
+ * and this one does not hold is unmounted: the next switch does not use it. The one this switch showed, still fading
41557
+ * out with the veil, is held again once the fade is over. A projection another owner shows is never held.
41558
+ *
41559
+ * @param ctx - Domain context of the plugin.
41560
+ * @param scene - The scene that stands.
41561
+ * @param name - The projection its leave loader names; `undefined` when it holds none (no projection loader, a fast
41562
+ * walk, a world that does not run live, a headless app).
41563
+ */
41564
+ function holdLoader(ctx, scene, name) {
41565
+ const state = ctx.state;
41566
+ const want = name === void 0 ? void 0 : loaderToHold(ctx, scene, name);
41567
+ const held = state.held;
41568
+ if (held !== void 0 && held.name !== want?.name) {
41569
+ delete state.held;
41570
+ ctx.deps.world.projection.unmount([held.name]);
41571
+ }
41572
+ if (want === void 0) return;
41573
+ const fading = state.fading;
41574
+ if (fading !== void 0 && fading.name === want.name) {
41575
+ fading.rehold = want;
41576
+ return;
41577
+ }
41578
+ if (ctx.deps.world.projection.entitiesOf(want.name).length > 0) return;
41579
+ holdNow(ctx, want);
41580
+ }
41581
+ /**
41582
+ * Unmounts the loader held for the running switch when the scene it switches to lists it, before that scene is built
41583
+ * or mounted: the scene mounts it as its own, and a projection still held would show nothing there.
41584
+ *
41585
+ * @param ctx - Domain context of the plugin.
41586
+ * @param scene - The scene being switched to.
41587
+ */
41588
+ function releaseListed(ctx, scene) {
41589
+ const held = ctx.state.held;
41590
+ if (held === void 0 || !scene.projections.includes(held.name)) return;
41591
+ delete ctx.state.held;
41592
+ ctx.deps.world.projection.unmount([held.name]);
41593
+ }
41594
+ /**
41595
+ * Ends a fade: the frame callback goes, and the loader is unmounted, or held again for the scene that stands.
41596
+ *
41597
+ * @param ctx - Domain context of the plugin.
41598
+ * @param fading - The fade.
41599
+ */
41600
+ function endFade(ctx, fading) {
41601
+ fading.off();
41602
+ delete ctx.state.fading;
41603
+ if (fading.rehold === void 0) ctx.deps.world.projection.unmount([fading.name]);
41604
+ else holdNow(ctx, fading.rehold);
41605
+ }
41606
+ /**
41607
+ * The `signals` callback of a fade: counts the frame's milliseconds before the time scale (a game time frozen at
41608
+ * scale 0 counts one frame of the loop's rate) and ends the fade in the frame the veil's `outMs` ran out, before that
41609
+ * frame is drawn: about the frame the renderer takes the veil down, which keeps the layer unseen until then. A fade a
41610
+ * new switch ended earlier in the frame does nothing: `time` runs the callbacks it took at the frame start. Per frame
41611
+ * while a loader fades: a subtraction, no allocation.
41612
+ *
41613
+ * @param ctx - Domain context of the plugin.
41614
+ * @param fading - The fade.
41615
+ * @param time - The frame's `Time`.
41616
+ */
41617
+ function stepFade(ctx, fading, time) {
41618
+ if (ctx.state.fading !== fading) return;
41619
+ fading.leftMs -= time.scale > 0 ? time.delta / time.scale : frameMsOf(ctx);
41620
+ if (fading.leftMs > 0) return;
41621
+ endFade(ctx, fading);
41622
+ }
41623
+ /**
41624
+ * The swap came (F107 part 3): the loader the switch mounted or showed fades out with the veil above the scene that
41625
+ * stands, and is unmounted in the frame the veil's `outMs` ran out, or held again when the scene that stands leaves with
41626
+ * it too (`holdLoader`). A look without a veil, or with `outMs: 0`, leaves the screen at once, and so does its loader.
41627
+ *
41628
+ * @param ctx - Domain context of the plugin.
41629
+ * @param leaving - The look of the switch.
41630
+ */
41631
+ function landLoader(ctx, leaving) {
41632
+ const name = leaving.projection;
41633
+ if (name === void 0) return;
41634
+ delete leaving.projection;
41635
+ if (leaving.outMs <= 0) {
41636
+ ctx.deps.world.projection.unmount([name]);
41637
+ return;
41638
+ }
41639
+ const fading = {
41640
+ name,
41641
+ leftMs: leaving.outMs,
41642
+ off: noFrame
41643
+ };
41644
+ fading.off = ctx.deps.time.onFrame("signals", (time) => stepFade(ctx, fading, time));
41645
+ ctx.state.fading = fading;
41646
+ }
41647
+ /**
41648
+ * Ends a loader still fading out when the next switch starts: it is unmounted, or held again, before that switch shows
41649
+ * its look or touches the world.
41650
+ *
41651
+ * @param ctx - Domain context of the plugin.
41652
+ */
41653
+ function settleFade(ctx) {
41654
+ const fading = ctx.state.fading;
41655
+ if (fading !== void 0) endFade(ctx, fading);
41656
+ }
41657
+ /**
41658
+ * Forgets the held loader and a fade when the plugin stops: the frame callback of the fade goes. Nothing is unmounted:
41659
+ * a teardown context may not call another plugin, and `world.onStop` clears the projections.
41660
+ *
41661
+ * @param state - The plugin state.
41662
+ */
41663
+ function forgetLoader(state) {
41664
+ state.fading?.off();
41665
+ delete state.fading;
41666
+ delete state.held;
41667
+ }
41668
+ //#endregion
41669
+ //#region src/plugins/scenes/leave.ts
41670
+ /**
41671
+ * What a game gets when it writes nothing: black at 45 %, 50 ms in and 150 ms out, the engine's ring once the switch took
41672
+ * 400 ms. The level under `config.leave`, and where a part written over `false` starts. `index.ts` writes the same
41673
+ * value inline as the plugin's default config; a test pins the two equal.
41674
+ */
41675
+ const FALLBACK_LEAVE = Object.freeze({
41676
+ cover: Object.freeze({
41677
+ color: 0,
41678
+ alpha: .45,
41679
+ inMs: 50,
41680
+ outMs: 150
41681
+ }),
41682
+ loader: Object.freeze({ afterMs: 400 })
41683
+ });
41684
+ /**
41685
+ * Merges one level's veil over the one below, field by field. `false` turns it off; a veil written over `false`
41686
+ * starts from the engine's.
41687
+ *
41688
+ * @param below - The veil of the levels below, or `false`.
41689
+ * @param over - What this level writes: nothing, `false` or fields.
41690
+ * @returns The veil, or `false`.
41691
+ * @example
41692
+ * ```ts
41693
+ * coverOver(false, { alpha: 0.6 }); // { color: 0, alpha: 0.6, inMs: 50, outMs: 150 }
41694
+ * ```
41695
+ */
41696
+ function coverOver(below, over) {
41697
+ if (over === void 0) return below;
41698
+ if (over === false) return false;
41699
+ const base = below === false ? FALLBACK_LEAVE.cover : below;
41700
+ return {
41701
+ color: over.color ?? base.color,
41702
+ alpha: over.alpha ?? base.alpha,
41703
+ inMs: over.inMs ?? base.inMs,
41704
+ outMs: over.outMs ?? base.outMs
41705
+ };
41706
+ }
41707
+ /**
41708
+ * The veil of a switch: the one the scene being left resolved, with the `color` and `alpha` of the scene being entered
41709
+ * over it, field by field, in a new object (the resolved veil may be the engine's frozen one). A veil turned off stays
41710
+ * off: the scene being entered never turns one on, and the times stay the left scene's.
41711
+ *
41712
+ * @param cover - The veil the scene being left resolved, or `false`.
41713
+ * @param enter - The `enter.cover` of the scene being entered.
41714
+ * @returns The veil, or `false`.
41715
+ * @example
41716
+ * ```ts
41717
+ * enteredCover(FALLBACK_LEAVE.cover, { color: 0x0b1020 }); // { color: 0x0b1020, alpha: 0.45, inMs: 50, outMs: 150 }
41718
+ * ```
41719
+ */
41720
+ function enteredCover(cover, enter) {
41721
+ if (cover === false || enter === void 0) return cover;
41722
+ return {
41723
+ color: enter.color ?? cover.color,
41724
+ alpha: enter.alpha ?? cover.alpha,
41725
+ inMs: cover.inMs,
41726
+ outMs: cover.outMs
41727
+ };
41728
+ }
41729
+ /**
41730
+ * The look of a loader: its projection, else its texture, else nothing (the engine's ring).
41731
+ *
41732
+ * @param loader - A level that names a look, or the level below.
41733
+ * @returns At most one of the two fields.
41734
+ * @example
41735
+ * ```ts
41736
+ * lookOf({ texture: "ui.loader.ring", projection: "loading" }); // { projection: "loading" }
41737
+ * ```
41738
+ */
41739
+ function lookOf(loader) {
41740
+ if (loader.projection !== void 0) return { projection: loader.projection };
41741
+ if (loader.texture !== void 0) return { texture: loader.texture };
41742
+ return {};
41743
+ }
41744
+ /**
41745
+ * Merges one level's loader over the one below. `afterMs` is a field of its own; `texture` and `projection` are one
41746
+ * choice: a level that names either replaces both of the level below. `false` turns it off; a loader written over
41747
+ * `false` starts from the engine's.
41748
+ *
41749
+ * @param below - The loader of the levels below, or `false`.
41750
+ * @param over - What this level writes: nothing, `false` or fields.
41751
+ * @returns The loader, or `false`.
41752
+ * @example
41753
+ * ```ts
41754
+ * loaderOver({ afterMs: 400, projection: "loading" }, { texture: "ui.loader.ring" }); // { afterMs: 400, texture: "ui.loader.ring" }
41755
+ * ```
41756
+ */
41757
+ function loaderOver(below, over) {
41758
+ if (over === void 0) return below;
41759
+ if (over === false) return false;
41760
+ const base = below === false ? FALLBACK_LEAVE.loader : below;
41761
+ const named = over.texture !== void 0 || over.projection !== void 0;
41762
+ return {
41763
+ afterMs: over.afterMs ?? base.afterMs,
41764
+ ...lookOf(named ? over : base)
41765
+ };
41766
+ }
41767
+ /**
41768
+ * Resolves what a switch shows over the scene being left: the scene's `leave` over the config's over the engine's,
41769
+ * field by field. `false` at a level turns both parts off there.
41770
+ *
41771
+ * @param config - `config.leave`.
41772
+ * @param scene - The `leave` of the scene being left.
41773
+ * @returns Both parts, each resolved or `false`; `undefined` when both are off.
41774
+ * @example
41775
+ * ```ts
41776
+ * leaveOf({ loader: false }, { cover: { alpha: 0.6 } }); // { cover: { color: 0, alpha: 0.6, inMs: 50, outMs: 150 }, loader: false }
41777
+ * ```
41778
+ */
41779
+ function leaveOf(config, scene) {
41780
+ let cover = FALLBACK_LEAVE.cover;
41781
+ let loader = FALLBACK_LEAVE.loader;
41782
+ for (const level of [config, scene]) if (level === false) {
41783
+ cover = false;
41784
+ loader = false;
41785
+ } else if (level !== void 0) {
41786
+ cover = coverOver(cover, level.cover);
41787
+ loader = loaderOver(loader, level.loader);
41788
+ }
41789
+ if (cover === false && loader === false) return void 0;
41790
+ return {
41791
+ cover,
41792
+ loader
41793
+ };
41794
+ }
41795
+ /**
41796
+ * The loader projection a scene leaves with: the one its `leave` over `config.leave` names, when the loader is on.
41797
+ *
41798
+ * @param config - `config.leave`.
41799
+ * @param scene - The `leave` of the scene.
41800
+ * @returns The projection's name, or `undefined` for a ring, a texture, a loader turned off or no look at all.
41801
+ * @example
41802
+ * ```ts
41803
+ * loaderProjectionOf({ loader: { projection: "loading" } }, { cover: false }); // "loading"
41804
+ * ```
41805
+ */
41806
+ function loaderProjectionOf(config, scene) {
41807
+ const leave = leaveOf(config, scene);
41808
+ return leave === void 0 || leave.loader === false ? void 0 : leave.loader.projection;
41044
41809
  }
41045
41810
  /**
41046
41811
  * The renderer's loader of a resolved one: a texture as it is, nothing for the ring, and for a projection the `due`
41047
- * the renderer calls once the loader is due, which mounts it then: a switch done sooner never runs its `from` and
41048
- * `view`. A projection a scene of the switch lists is no loader: warned, the ring.
41812
+ * the renderer calls once the loader is due, which shows it then when the scene being left holds it built (F103), and
41813
+ * mounts it then otherwise: a switch done sooner shows nothing of it. Such a projection is fed the switch from now on
41814
+ * (F107 part 1). A projection a scene of the switch lists is no loader: warned, the ring.
41049
41815
  *
41050
41816
  * @param ctx - Domain context of the plugin.
41051
41817
  * @param loader - The resolved loader.
@@ -41071,9 +41837,10 @@ function loaderLook(ctx, loader, between, leaving) {
41071
41837
  });
41072
41838
  return { afterMs };
41073
41839
  }
41840
+ startFeeding(ctx, leaving, projection, between);
41074
41841
  return {
41075
41842
  afterMs,
41076
- due: () => mountLoader(ctx, projection, from, leaving)
41843
+ due: () => dueLoader(ctx, projection, from, leaving)
41077
41844
  };
41078
41845
  }
41079
41846
  /**
@@ -41093,8 +41860,9 @@ function leftScene(ctx, run) {
41093
41860
  }
41094
41861
  /**
41095
41862
  * Shows the veil and the loader of a switch that starts now, before its bundles are awaited: the scene being left
41096
- * decides. A loader projection is mounted only once its loader is due. An abort of the node drops both at once, from
41097
- * its listener. The look keeps the node's signal, so the `scene` stage of the same node takes it over.
41863
+ * decides, and the scene being entered sets the veil's colour and alpha (`enter.cover`). A loader projection is fed
41864
+ * the switch from now on, and shown or mounted only once its loader is due. An abort of the node drops both at once,
41865
+ * from its listener. The look keeps the node's signal, so the `scene` stage of the same node takes it over.
41098
41866
  *
41099
41867
  * @param ctx - Domain context of the plugin.
41100
41868
  * @param scene - The scene being switched to.
@@ -41106,15 +41874,17 @@ function startLeave(ctx, scene, run) {
41106
41874
  if (from === void 0) return void 0;
41107
41875
  const leave = leaveOf(ctx.config.leave, from.leave);
41108
41876
  if (leave === void 0) return void 0;
41877
+ const cover = enteredCover(leave.cover, scene.enter?.cover);
41109
41878
  const listening = new AbortController();
41110
41879
  const leaving = {
41111
41880
  signal: run.signal,
41112
41881
  to: scene.id,
41113
41882
  done: false,
41883
+ outMs: cover === false ? 0 : cover.outMs,
41114
41884
  off: () => listening.abort()
41115
41885
  };
41116
41886
  const look = {};
41117
- if (leave.cover !== false) look.cover = leave.cover;
41887
+ if (cover !== false) look.cover = cover;
41118
41888
  if (leave.loader !== false) look.loader = loaderLook(ctx, leave.loader, {
41119
41889
  from,
41120
41890
  to: scene
@@ -41166,9 +41936,11 @@ function dropLeftOver(ctx, run) {
41166
41936
  if (leaving !== void 0 && leaving.signal !== run.signal) endLeave(ctx, leaving, "drop");
41167
41937
  }
41168
41938
  /**
41169
- * Ends the look of a switch once: `"land"` at the swap (the loader goes, the veil fades out over the next scene),
41170
- * `"drop"` on an abort or a throw (both go at once). A loader projection mounted for the wait is unmounted. A look
41171
- * ended already, or a switch that showed nothing, is left alone.
41939
+ * Ends the look of a switch once: `"land"` at the swap (the veil fades out over the next scene, and a loader
41940
+ * projection mounted or shown for the wait fades out with it and is unmounted after the veil's `outMs`), `"drop"` on an
41941
+ * abort or a throw (both go at once, the loader projection unmounted). Either ends the feeding of its loader: the look
41942
+ * leaves the state, where the hooks of `assets` find it, and a fading loader keeps the last value fed. A look ended
41943
+ * already, or a switch that showed nothing, is left alone.
41172
41944
  *
41173
41945
  * @param ctx - Domain context of the plugin.
41174
41946
  * @param leaving - The look of the switch.
@@ -41180,9 +41952,13 @@ function endLeave(ctx, leaving, how) {
41180
41952
  leaving.off();
41181
41953
  if (ctx.state.leaving === leaving) delete ctx.state.leaving;
41182
41954
  const leave = ctx.deps.renderer.sync.leave;
41183
- if (how === "land") leave.land();
41184
- else leave.drop();
41185
- unmountLoader(ctx, leaving);
41955
+ if (how === "land") {
41956
+ leave.land();
41957
+ landLoader(ctx, leaving);
41958
+ } else {
41959
+ leave.drop();
41960
+ dropLoader(ctx, leaving);
41961
+ }
41186
41962
  }
41187
41963
  /**
41188
41964
  * Forgets the look of a running switch when the plugin stops: its abort listener goes and a later end does nothing.
@@ -41267,16 +42043,20 @@ function isName(value) {
41267
42043
  function isRecord$2(value) {
41268
42044
  return typeof value === "object" && value !== null && !Array.isArray(value);
41269
42045
  }
42046
+ /** The colour of a veil. */
42047
+ const COLOR_RULE = {
42048
+ ok: isColor$1,
42049
+ hint: "a colour from 0x000000 to 0xffffff"
42050
+ };
42051
+ /** The alpha of a veil. */
42052
+ const ALPHA_RULE = {
42053
+ ok: isAlpha,
42054
+ hint: "the alpha the veil fades in to, a number from 0 to 1"
42055
+ };
41270
42056
  /** The fields of a veil. */
41271
42057
  const COVER_RULES = Object.freeze({
41272
- color: {
41273
- ok: isColor$1,
41274
- hint: "a colour from 0x000000 to 0xffffff"
41275
- },
41276
- alpha: {
41277
- ok: isAlpha,
41278
- hint: "the alpha the veil fades in to, a number from 0 to 1"
41279
- },
42058
+ color: COLOR_RULE,
42059
+ alpha: ALPHA_RULE,
41280
42060
  inMs: {
41281
42061
  ok: isDuration,
41282
42062
  hint: "the milliseconds of the fade-in, 0 or more"
@@ -41286,6 +42066,11 @@ const COVER_RULES = Object.freeze({
41286
42066
  hint: "the milliseconds of the fade-out, 0 or more"
41287
42067
  }
41288
42068
  });
42069
+ /** The fields of the veil a scene being entered sets: its look, never its times. */
42070
+ const ENTER_COVER_RULES = Object.freeze({
42071
+ color: COLOR_RULE,
42072
+ alpha: ALPHA_RULE
42073
+ });
41289
42074
  /** The fields of a loader. */
41290
42075
  const LOADER_RULES = Object.freeze({
41291
42076
  afterMs: {
@@ -41353,6 +42138,24 @@ function checkLeave(where, leave) {
41353
42138
  checkPart(`${where}.cover`, leave.cover, COVER_RULES);
41354
42139
  checkPart(`${where}.loader`, leave.loader, LOADER_RULES);
41355
42140
  }
42141
+ /**
42142
+ * Checks a scene's `enter`: nothing, or an object whose `cover` is nothing or an object of a colour and an alpha from 0
42143
+ * to 1, by the rules of `leave.cover`.
42144
+ *
42145
+ * @param where - Where it was written, for the message: `Scene "night": enter`.
42146
+ * @param enter - What was written.
42147
+ * @throws {Error} For an `enter` that is no object, and for the first field of the wrong shape.
42148
+ * @example
42149
+ * ```ts
42150
+ * checkEnter('Scene "night": enter', { cover: { alpha: 2 } });
42151
+ * // throws '[game] Scene "night": enter.cover.alpha is 2.\n Give the alpha the veil fades in to, a number from 0 to 1.'
42152
+ * ```
42153
+ */
42154
+ function checkEnter(where, enter) {
42155
+ if (enter === void 0) return;
42156
+ if (!isRecord$2(enter)) throw wrong(where, enter, "{ cover }");
42157
+ checkPart(`${where}.cover`, enter.cover, ENTER_COVER_RULES);
42158
+ }
41356
42159
  //#endregion
41357
42160
  //#region src/plugins/scenes/switch.ts
41358
42161
  /**
@@ -41420,20 +42223,6 @@ async function untilAborted(ctx, bundles, signal) {
41420
42223
  if (load.failed && !signal.aborted) throw load.error;
41421
42224
  }
41422
42225
  /**
41423
- * Reads the committed state a scene's `bundles` gets: the frozen trees of the store, in a frozen
41424
- * wrapper. During the scene stage no node writes, so it is the state the node is entered with.
41425
- *
41426
- * @param ctx - Domain context of the plugin.
41427
- * @returns The committed `player` and `session`.
41428
- */
41429
- function committedState(ctx) {
41430
- const { player, session } = ctx.deps.model.store.snapshot();
41431
- return Object.freeze({
41432
- player,
41433
- session
41434
- });
41435
- }
41436
- /**
41437
42226
  * Tells whether two lists name the same bundles in the same order.
41438
42227
  *
41439
42228
  * @param left - One list.
@@ -41526,7 +42315,8 @@ function buildsAside(ctx, run) {
41526
42315
  /**
41527
42316
  * Builds the scene: aside on a live switch with a drawing renderer, resolving at the commit or
41528
42317
  * the abort; in one block otherwise, and when the world refuses to build it aside because a
41529
- * projection both scenes list is declared on other layer rules (named in a dev build).
42318
+ * projection both scenes list is declared on other layer rules (named in a dev build). A loader
42319
+ * held for this switch that the scene lists is unmounted first: the scene mounts it as its own.
41530
42320
  *
41531
42321
  * @param ctx - Domain context of the plugin.
41532
42322
  * @param scene - The scene whose bundles are there.
@@ -41536,6 +42326,7 @@ function buildsAside(ctx, run) {
41536
42326
  * @throws {Error} Whatever the mount or the build threw: a `view` or an unknown projection.
41537
42327
  */
41538
42328
  async function standUp(ctx, scene, named, run) {
42329
+ releaseListed(ctx, scene);
41539
42330
  if (buildsAside(ctx, run)) {
41540
42331
  const building = buildAside(ctx, scene, named, run.signal);
41541
42332
  if (building !== void 0) {
@@ -41553,7 +42344,8 @@ async function standUp(ctx, scene, named, run) {
41553
42344
  /**
41554
42345
  * Awaits every bundle the scene names and only then builds the scene. In live mode it waits between
41555
42346
  * the two for the textures of those bundles to reach the GPU; a fast walk does not, so tests and
41556
- * restores keep their pace. An aborted node, or a plugin stopped during the wait, returns without
42347
+ * restores keep their pace. Once the loads are in, a loader projection fed the switch counts every
42348
+ * loaded bundle whole. An aborted node, or a plugin stopped during the wait, returns without
41557
42349
  * touching anything. A live switch with a drawing renderer resolves at the commit of the scene
41558
42350
  * built aside, frames later.
41559
42351
  *
@@ -41566,18 +42358,46 @@ async function standUp(ctx, scene, named, run) {
41566
42358
  */
41567
42359
  async function loadAndStand(ctx, scene, named, run) {
41568
42360
  await untilAborted(ctx, named, run.signal);
41569
- if (run.mode === "live" && !run.signal.aborted) await untilWarmed(ctx, named, run.signal);
42361
+ const warmsFirst = run.mode === "live" && !run.signal.aborted;
42362
+ if (warmsFirst) countLoaded(ctx.state);
42363
+ if (warmsFirst) await untilWarmed(ctx, named, run.signal);
41570
42364
  const stopped = ctx.state.teardown === void 0;
41571
42365
  if (run.signal.aborted || stopped) return;
41572
42366
  await standUp(ctx, scene, named, run);
41573
42367
  }
41574
42368
  /**
41575
- * Switches to another scene: it takes over the veil and the loader the `begin` stage of the node
41576
- * showed over the scene being left for this scene (a cold first visit reacts in the next frame),
41577
- * or shows them now when that stage did not, or showed them for another scene, after reading what
41578
- * the scene names from the committed state. Then
41579
- * it awaits the bundles and builds the scene (`loadAndStand`). The look lands when the scene
41580
- * stands, and is dropped when the switch ends without it or throws.
42369
+ * Holds the loader of the scene that stands for its next switch (`loader.ts`): the projection its
42370
+ * leave loader names, on a live run while the world runs live and the renderer draws, the switches
42371
+ * that show a look. A fast walk, a world that does not run live and a headless app hold none.
42372
+ *
42373
+ * @param ctx - Domain context of the plugin.
42374
+ * @param scene - The scene that stands.
42375
+ * @param run - The runner's mode and signal.
42376
+ */
42377
+ function standLoader(ctx, scene, run) {
42378
+ holdLoader(ctx, scene, buildsAside(ctx, run) ? loaderProjectionOf(ctx.config.leave, scene.leave) : void 0);
42379
+ }
42380
+ /**
42381
+ * Holds the loader of the scene that still stands after a switch that ended without its swap: the drop unmounted the
42382
+ * loader the switch showed, and its next switch would mount it in the frame it is due. A loader the switch did not show
42383
+ * is held still; no scene stands: nothing.
42384
+ *
42385
+ * @param ctx - Domain context of the plugin.
42386
+ * @param run - The runner's mode and signal.
42387
+ */
42388
+ function standAgain(ctx, run) {
42389
+ if (ctx.state.held !== void 0) return;
42390
+ const current = ctx.state.current === void 0 ? void 0 : ctx.state.scenes.get(ctx.state.current);
42391
+ if (current !== void 0) standLoader(ctx, current, run);
42392
+ }
42393
+ /**
42394
+ * Switches to another scene: a loader still fading out after the last swap goes first. It takes
42395
+ * over the veil and the loader the `begin` stage of the node showed over the scene being left for
42396
+ * this scene (a cold first visit reacts in the next frame), or shows them now when that stage did
42397
+ * not, or showed them for another scene, after reading what the scene names from the committed
42398
+ * state. Then it awaits the bundles and builds the scene (`loadAndStand`). The look lands when the
42399
+ * scene stands, and the scene holds its own loader then; the look is dropped when the switch ends
42400
+ * without it or throws.
41581
42401
  *
41582
42402
  * @param ctx - Domain context of the plugin.
41583
42403
  * @param target - Id of the scene to mount.
@@ -41588,6 +42408,7 @@ async function loadAndStand(ctx, scene, named, run) {
41588
42408
  async function switchTo(ctx, target, run) {
41589
42409
  const scene = ctx.state.scenes.get(target);
41590
42410
  if (scene === void 0) throw new Error(`[game] Scene "${target}" is not registered.\n List it in the scenes of a feature.`);
42411
+ settleFade(ctx);
41591
42412
  let leaving = leaveFor(ctx, run, scene.id);
41592
42413
  try {
41593
42414
  const named = namedBundles(scene, committedState(ctx));
@@ -41595,9 +42416,13 @@ async function switchTo(ctx, target, run) {
41595
42416
  await loadAndStand(ctx, scene, named, run);
41596
42417
  } catch (error) {
41597
42418
  endLeave(ctx, leaving, "drop");
42419
+ standAgain(ctx, run);
41598
42420
  throw error;
41599
42421
  }
41600
- endLeave(ctx, leaving, ctx.state.current === scene.id ? "land" : "drop");
42422
+ const stands = ctx.state.current === scene.id;
42423
+ endLeave(ctx, leaving, stands ? "land" : "drop");
42424
+ if (stands) standLoader(ctx, scene, run);
42425
+ else standAgain(ctx, run);
41601
42426
  }
41602
42427
  /**
41603
42428
  * Reads again what the mounted scene names, at a node that keeps it: a bundle it names now and
@@ -41667,8 +42492,9 @@ function nextScene(ctx, node, run) {
41667
42492
  * downloads the bundles of the coming one, so a cold first visit reacts in the next frame. The
41668
42493
  * `scene` stage of the same node takes the look over, lands it at the swap or drops it. A node
41669
42494
  * that keeps the scene, the first scene of a run, a fast walk and an aborted node start nothing
41670
- * (`startLeave` decides the rest). A stage after `begin` that throws aborts the node, and the abort
41671
- * drops the look; one a node before left running all the same is dropped first.
42495
+ * (`startLeave` decides the rest). A loader still fading out after the last swap goes before the
42496
+ * look shows. A stage after `begin` that throws aborts the node, and the abort drops the look; one a
42497
+ * node before left running all the same is dropped first.
41672
42498
  *
41673
42499
  * @param ctx - Domain context of the plugin.
41674
42500
  * @param node - The node being entered.
@@ -41679,7 +42505,9 @@ function beginScene(ctx, node, run) {
41679
42505
  const target = nextScene(ctx, node, run);
41680
42506
  if (target === void 0 || target === ctx.state.current) return;
41681
42507
  const scene = ctx.state.scenes.get(target);
41682
- if (scene !== void 0) startLeave(ctx, scene, run);
42508
+ if (scene === void 0) return;
42509
+ settleFade(ctx);
42510
+ startLeave(ctx, scene, run);
41683
42511
  }
41684
42512
  //#endregion
41685
42513
  //#region src/plugins/scenes/lifecycle.ts
@@ -41789,9 +42617,10 @@ function startScenes(ctx) {
41789
42617
  /**
41790
42618
  * Removes the two `onEnter` callbacks in `onStop` and forgets every scene and the bundles the mounted
41791
42619
  * one named. A running build loses its frame callback and its switch returns; the look of a running
41792
- * switch loses its abort listener (the renderer drops it at its own stop). Nothing is unmounted
41793
- * or discarded: a teardown context may not call another plugin, and `world.onStop` clears every
41794
- * entity and the build table anyway.
42620
+ * switch loses its abort listener (the renderer drops it at its own stop), a loader fading out its
42621
+ * frame callback, and the held loader is forgotten. Nothing is unmounted or discarded: a teardown
42622
+ * context may not call another plugin, and `world.onStop` clears every entity and the build table
42623
+ * anyway.
41795
42624
  *
41796
42625
  * @param teardown - What the teardown context carries.
41797
42626
  * @param teardown.state - The plugin state.
@@ -41808,6 +42637,7 @@ function stopScenes(teardown) {
41808
42637
  dropBuild(state.build);
41809
42638
  delete state.build;
41810
42639
  forgetLeave(state);
42640
+ forgetLoader(state);
41811
42641
  state.scenes.clear();
41812
42642
  state.current = void 0;
41813
42643
  state.pending = void 0;
@@ -41905,6 +42735,7 @@ const scenesPlugin = /*#__PURE__*/ createPlugin$1("scenes", {
41905
42735
  events: (register) => register.map({ "scenes:changed": "The mounted scene changed" }),
41906
42736
  createState: createScenesState,
41907
42737
  api: createScenesApi,
42738
+ hooks: createHandlers$4,
41908
42739
  onInit: ({ config }) => checkConfig(config),
41909
42740
  onStart: startScenes,
41910
42741
  onStop: ({ state }) => stopScenes({ state })
@@ -68858,14 +69689,15 @@ function namesOf(id, layers, projections) {
68858
69689
  * `lift` is not among them does not compile — and throws here for a caller without types.
68859
69690
  * `bundles` names bundles that depend on the committed state: the scene is mounted once those
68860
69691
  * are in too. `leave` is what a live switch shows over the scene when it is left, merged over the
68861
- * config's: `false` shows nothing.
69692
+ * config's: `false` shows nothing. `enter` sets the colour and the alpha of the veil of every live switch to the scene.
68862
69693
  *
68863
69694
  * @param id - Id of the scene. A node names it with `defineNode({ scene: id })`.
68864
69695
  * @param scene - The bundle, the optional bundles of state, the layers, the projections, the
68865
- * optional music key and the optional `leave`.
69696
+ * optional music key, the optional `leave` and the optional `enter`.
68866
69697
  * @returns The scene as frozen data, ready for the `scenes` key of a feature.
68867
69698
  * @throws {Error} For an integer-like layer name, for a `layer` or `lift` that is not declared, for two HUD layers,
68868
- * an `above` other than `"overlays"`, a `ui` declared after the HUD layer, and a `leave` of the wrong shape.
69699
+ * an `above` other than `"overlays"`, a `ui` declared after the HUD layer, and a `leave` or an `enter` of the wrong
69700
+ * shape.
68869
69701
  * @example
68870
69702
  * ```ts
68871
69703
  * // features/board/view/scene.ts of a game.
@@ -68898,12 +69730,21 @@ function namesOf(id, layers, projections) {
68898
69730
  * projections: [],
68899
69731
  * leave: { cover: { color: 0x0b1020, alpha: 0.6 }, loader: { texture: "ui.loader.ring" } }
68900
69732
  * }).leave; // { cover: { color: 0x0b1020, alpha: 0.6 }, loader: { texture: "ui.loader.ring" } }
69733
+ *
69734
+ * // Every switch to the night dims the scene being left in navy at 70 %, whatever that scene leaves with.
69735
+ * defineScene("night", {
69736
+ * bundle: "night",
69737
+ * layers: { sky: {} },
69738
+ * projections: [],
69739
+ * enter: { cover: { color: 0x0b1020, alpha: 0.7 } }
69740
+ * }).enter; // { cover: { color: 0x0b1020, alpha: 0.7 } }
68901
69741
  * ```
68902
69742
  */
68903
69743
  function defineScene(id, scene) {
68904
69744
  const layers = layersOf(id, scene.layers);
68905
69745
  const projections = scene.projections;
68906
69746
  checkLeave(`Scene "${id}": leave`, scene.leave);
69747
+ checkEnter(`Scene "${id}": enter`, scene.enter);
68907
69748
  return Object.freeze({
68908
69749
  id,
68909
69750
  bundle: scene.bundle,
@@ -68911,7 +69752,8 @@ function defineScene(id, scene) {
68911
69752
  layers: Object.freeze(layers),
68912
69753
  projections: Object.freeze(namesOf(id, layers, projections)),
68913
69754
  ...scene.bundles === void 0 ? {} : { bundles: scene.bundles },
68914
- ...scene.leave === void 0 ? {} : { leave: scene.leave }
69755
+ ...scene.leave === void 0 ? {} : { leave: scene.leave },
69756
+ ...scene.enter === void 0 ? {} : { enter: scene.enter }
68915
69757
  });
68916
69758
  }
68917
69759
  /**