0.2.6-dev: port PR #416 by Cromemadnd — at every round start the own board's pieces replay their Start clip and landing sound one after another in deployment order (the maintainer's confirmation from official play, 2026-10-13), and a purchase or a move onto / across the board plays them too ([ASSUMED], the PR author's account); one sound per landing, idle prep pieces only, the round marked once the view took the sequence, own board only, timers cleared when prep mode ends and on destroy; DESIGN §31.8; golden: unchanged

This commit is contained in:
sganggs committed 2026-10-13 04:36:56 +08:00
1 parent 281cf01ff0
commit 231da0efbc
16 files changed
+791 -22

No files matched your search

+83 -9
View File
@@ -14,7 +14,15 @@
// view.setPrep(privateState, { editable, canPlace }) hand/temp/board pieces; editable enables drag & drop; a
// new board piece flashes (fx.deploy), and so does a card that just arrived in the hand or temp; a merge's elite — on the tile of
// the deployed copy it replaced, or on its bench slot — gets the
// promotion cue instead (render/promote.js, fx.promote)
// promotion cue instead (render/promote.js, fx.promote). Landings (PR #416,
// UnitView.land: the Start clip again + the landing sound, once): an
// operator that just arrived on the bench (a purchase, a reward, a grant)
// and a merge's elite [ASSUMED], a piece this state puts on a board tile it
// was not on — from the bench, from another tile, a swap — [ASSUMED]
// view.replayDeploys(uids) the round start: the own board's pieces `uids` (deployment order) land one
// after another, DEPLOY_REPLAY_MS apart (the maintainer's confirmation from
// official play, 2026-10-13) → how many of them the board holds now (0: not
// built yet); the timers end with prep mode (enterBattle) and destroy
// view.enterBattle(fieldMeta) m.field { fieldId, kind, rect, stageId, units: [UnitInfo] } — each
// unit through renderInfo(UnitInfo) (an enemy's `form`: a view built
// mid-battle starts in the current model form)
@@ -134,14 +142,14 @@ import { pickOnTile, pickBattle, hitTiles } from './pick.js';
import { promotionsOf } from './promote.js';
import { ensurePixi } from './app/pixi.js';
import { pieceDirOf, pickUnitOf } from './app/pick.js';
import { CAMERA_MS, BOARD3D_STABLE_MS, BOARD3D_RETRY_MS, PEN_CAMERA_MS, RANGE_GROUPS, LEADER_HIT_STYLE, DRAG_HOLD_TILES, CHAIN_KINDS, DROP_PENDING_MS } from './app/tune.js';
import { CAMERA_MS, BOARD3D_STABLE_MS, BOARD3D_RETRY_MS, PEN_CAMERA_MS, RANGE_GROUPS, LEADER_HIT_STYLE, DRAG_HOLD_TILES, CHAIN_KINDS, DROP_PENDING_MS, DEPLOY_REPLAY_MS } from './app/tune.js';
import { boardPreference, switchableBox, bandFor, fieldRows, boardArea, viewKind, penShown, leaderShown } from './app/view.js';
import { renderInfo, FORCED_EXIT, showsDeathFx } from './app/info.js';
import { resolveAssets, makeData, withTimeout, QUALITY_RES, BOARD_RES, releaseGl } from './app/host.js';
import { t } from '../../../shared/i18n.js';
export { ensurePixi } from './app/pixi.js';
export { PEN_CAMERA_MS, LEADER_HIT_STYLE, DRAG_HOLD_TILES } from './app/tune.js';
export { PEN_CAMERA_MS, LEADER_HIT_STYLE, DRAG_HOLD_TILES, DEPLOY_REPLAY_MS } from './app/tune.js';
export { viewKind, boardArea, bandFor, fieldRows, penShown, leaderShown, boardPreference, switchableBox } from './app/view.js';
export { FORCED_EXIT, showsDeathFx, renderInfo } from './app/info.js';
export { releaseGl } from './app/host.js';
@@ -270,6 +278,8 @@ export async function createFieldView(host, options = {}) {
// or 机变 grant at ROUND_START, a SETTLE merge) is still recognised by the next setPrep (QA 6b)
let promoBase = [];
const promotions = []; // the last merges cued by setPrep (fx.promote): { uid, id, area, row, col, idx, copies } — dev / tests
const landings = []; // the last prep landings (UnitView.land, PR #416): { uid, why: 'round'|'buy'|'merge'|'board', at } — dev / tests
let replayTimer = 0; // the next turn of the round start's replay (replayDeploys): cleared when prep mode ends and on destroy
let battleMeta = null;
let sceneHold = null; // release function of the Spine cache hold of battle mode (holdScene)
const infos = new Map(); // battle unit id → UnitInfo
@@ -308,6 +318,7 @@ export async function createFieldView(host, options = {}) {
const heightAt = (r, c) => (tiles ? tiles.heightAt(r, c) : 0);
const ctx = {
P, layers, assets, settings, fx: null, shadowTex: shadowTexture(),
audio: opts.audio || null, // the prep landings' sound (UnitView.land → audio.deployCue)
cam: () => cam, heightAt,
animRate: () => (mode === 'battle' ? interp.rate : 1),
timeScale: () => (mode === 'battle' ? interp.rate : 1),
@@ -748,6 +759,9 @@ export async function createFieldView(host, options = {}) {
addList(src.board, 'board');
const seen = new Set();
const prevBoard = new Set(prepPieces.filter((p) => p.area === 'board').map((p) => p.uid));
// where each piece stood in the last state of this prep (nothing after a battle rebuilt the scene): a piece this state
// puts on a board tile it was not on lands (PR #416)
const prevAt = new Map(prepPieces.map((p) => [p.uid, p]));
// merges since the last state (render/promote.js): new elite uid → where its consumed copies stood (their views
// still exist until the sweep below) — the elite gets the promotion cue instead of the deploy flash
const promoFrom = new Map();
@@ -782,13 +796,18 @@ export async function createFieldView(host, options = {}) {
v.setWorld(w.x, w.y, w.z);
views.set(key, v);
if (promoFrom.has(e.uid)) {
// a merge's elite: on the tile of the deployed copy it replaced, or on its bench slot
if (e.area === 'board') v.onDeploy?.();
// a merge's elite: on the tile of the deployed copy it replaced, or on its bench slot — it lands there (PR #416)
landPiece(v, 'merge');
fx.promote(v, promoFrom.get(e.uid).filter((f) => Math.abs(f.x - w.x) + Math.abs(f.y - w.y) > 1e-3));
promotions.push({ uid: e.uid, id: e.piece.id, area: e.area, row: e.row ?? null, col: e.col ?? null, idx: e.idx ?? null, copies: promoFrom.get(e.uid).length });
if (promotions.length > 20) promotions.shift();
} else if (e.area === 'board' && prevBoard.size && !prevBoard.has(e.uid)) { v.onDeploy?.(); fx.deploy(v); }
else if (before.length && (e.area === 'hand' || e.area === 'temp') && !before.some((g) => g.uid === e.uid)) fx.deploy(v);
} else if (e.area === 'board' && prevBoard.size && !prevBoard.has(e.uid)) { landPiece(v, 'board'); fx.deploy(v); }
else if (before.length && (e.area === 'hand' || e.area === 'temp') && !before.some((g) => g.uid === e.uid)) {
// an operator that just arrived on the bench — bought, a reward, a grant — lands there (PR #416); a summon that comes
// with its owner's placement does not, nor does an item
if (e.piece.kind === 'chess') landPiece(v, 'buy');
fx.deploy(v);
}
} else {
const prevHome = v._home;
const moved = !prevHome || prevHome.x !== w.x || prevHome.y !== w.y || prevHome.z !== w.z;
@@ -800,8 +819,13 @@ export async function createFieldView(host, options = {}) {
pending.delete(key);
if (moved || Math.abs(v.x - w.x) + Math.abs(v.y - w.y) > 1e-3) v._tween = { fx: v.x, fy: v.y, fz: v.z, tx: w.x, ty: w.y, tz: w.z, t: 0 };
v.lift = 0;
if (e.area === 'board' && !prevBoard.has(e.uid) && v.onDeploy) { v.onDeploy(); fx.deploy(v); }
if (e.area === 'board' && !prevBoard.has(e.uid) && v.onDeploy) fx.deploy(v);
}
// a piece this state puts on a board tile it was not on — from the bench, from another tile, a swap — lands (PR #416),
// also while its drop is still held on that tile (the direction step pins it there, so `moved` is false); turned in
// place, retreated or moved on the bench it does not
const was = prevAt.get(e.uid);
if (was && e.area === 'board' && (was.area !== 'board' || was.row !== e.row || was.col !== e.col) && !(dragState && dragState.key === key)) landPiece(v, 'board');
}
v._home = w;
v.dimmed = false;
@@ -830,6 +854,52 @@ export async function createFieldView(host, options = {}) {
return true;
}
/** Land a prep piece (UnitView.land, PR #416) and note it (`landings`, dev / tests); false when the view refused. */
function landPiece(v, why) {
if (!v || typeof v.land !== 'function' || !v.land()) return false;
landings.push({ uid: v.uid ?? null, why, at: performance.now() });
if (landings.length > 40) landings.shift();
return true;
}
/**
* The round start's replay (see the header; PR #416): the listed pieces of the own board land one after another in the
* order given (deployment order, ui/gameLogic deployOrder), each turn DEPLOY_REPLAY_MS after the one before (a chain of
* timeouts, so a busy frame never squeezes two together). A piece gone, rebuilt, not idle or already landing when its
* turn comes is passed over (UnitView.land), and none lands while the tab is hidden (no frame shows it; the suspended
* audio would play the sound on return). A new sequence replaces one still running; prep mode ending and destroy()
* cancel it.
* @param {number[]} uids
* @param {number} [gap] ms between two pieces
* @returns {number} how many of `uids` the board holds now — 0 outside prep mode or before setPrep built them
*/
function replayDeploys(uids, gap = DEPLOY_REPLAY_MS) {
if (destroyed || mode !== 'prep' || !Array.isArray(uids)) return 0;
const step = Number.isFinite(gap) && gap >= 0 ? gap : DEPLOY_REPLAY_MS;
const queue = [];
for (const uid of uids) {
const v = Number.isInteger(uid) ? views.get('p:' + uid) : null;
if (v && !v.destroyed && typeof v.land === 'function' && !queue.some((q) => q.v === v)) queue.push({ uid, v });
}
if (!queue.length) return 0;
cancelReplay();
let i = 0;
const turn = () => {
replayTimer = 0;
if (destroyed || mode !== 'prep') return;
const { uid, v } = queue[i++];
if (!globalThis.document?.hidden && views.get('p:' + uid) === v) landPiece(v, 'round');
if (i < queue.length) replayTimer = setTimeout(turn, step);
};
replayTimer = setTimeout(turn, 0);
return queue.length;
}
function cancelReplay() {
if (replayTimer) clearTimeout(replayTimer);
replayTimer = 0;
}
/**
* The reserve medic and a boss pair's partner pieces: read-only 'm:<uid>' views. These are not movable prep pieces;
* only the owner's prepMapChars may be picked for inspection. Rebuild when body, tile or facing changes.
@@ -874,6 +944,7 @@ export async function createFieldView(host, options = {}) {
function enterPrepMode() {
mode = 'prep';
held.clear();
cancelReplay();
clearViews();
infos.clear();
gone.clear();
@@ -1323,6 +1394,7 @@ export async function createFieldView(host, options = {}) {
holdScene(true); // before the prep views go: the cache is never "quiet" across the switch
drag.reset();
endDragVisual(false);
cancelReplay(); // the round start's replay is a prep-board thing: none of it reaches a battle (or a scouted board)
clearViews();
if (prepPieces.length) promoBase = prepPieces;
prepPieces = [];
@@ -1816,6 +1888,7 @@ export async function createFieldView(host, options = {}) {
setStage,
setCamera,
setPrep,
replayDeploys,
/** Enemy preview pen: a list in m.private.nextEnemies shape, or null to empty it (setPrep does this itself). */
setPen(list) { if (destroyed) return false; setPenList(Array.isArray(list) ? list : null); return true; },
enterBattle,
@@ -1936,6 +2009,7 @@ export async function createFieldView(host, options = {}) {
app.ticker.remove(preRender);
app.ticker.remove(postRender);
clearTimeout(recover.timer);
cancelReplay();
drag.reset();
for (const k of [...views.keys()]) dropView(k);
clearPen();
@@ -1964,7 +2038,7 @@ export async function createFieldView(host, options = {}) {
/** Dev hooks (demo / tests). */
debug: {
app, get cam() { return cam; }, get board3d() { return board3d; }, tiles, views, penViews, get leader() { return leader; }, interp, fx, ctx, drag, get camKind() { return viewKind(camKind, camOpts); },
promotions,
promotions, landings, get replaying() { return !!replayTimer; },
// picking (render/pick.js) at canvas px: the prep piece / battle view / pen view there, the ground tile under it
pick: { pieceAt, mapCharAt, battleUnitAt, penUnitAt, groundTile },
},
+7
View File
@@ -32,4 +32,11 @@ const DROP_PENDING_MS = 1300;
*/
export const DRAG_HOLD_TILES = 0.45;
/**
* The round start's replay of the own board (view.replayDeploys, PR #416 by @Cromemadnd): ms between two pieces' Start
* clips, in deployment order. The maintainer saw them come one after another in official play (2026-10-13); [ASSUMED] the
* gap — the PR's 50 ms, no source gives the official one.
*/
export const DEPLOY_REPLAY_MS = 50;
export { CAMERA_MS, BOARD3D_RETRY_MS, BOARD3D_STABLE_MS, RANGE_GROUPS, CHAIN_KINDS, DROP_PENDING_MS };
+53 -2
View File
@@ -35,6 +35,13 @@
// redeploy) plays the deploy clip and restores the normal look; `setDown(null)` on a dead view lets it fade out.
// An operator that enters a battle already knocked out (联防, user playtest #5 item 2: sim 'die' reason 'forcedExit')
// goes down with `die(true)`: straight to the held end of the clip, no fall.
// Prep landings (PR #416 by @Cromemadnd): `land()` plays a prep piece's deploy clip (Start) again with its landing sound
// — the round start's replay of the own board (render/app.js replayDeploys), a purchase, a move onto or across the board.
// One landing, one sound: a piece whose Start still plays (on its model, owed to a model still loading, or cued less than
// a clip ago) keeps it and sounds nothing more, and only an idle prep piece is ever pulled into it — never a battle unit
// or one in an attack, skill, death or form clip. The sound is `ctx.audio.deployCue` (public/js/audio.js: the unit's own
// battle deploy sound, through the SFX volume, mute and the battle limiter); `onDeploy` itself — the sim's 'deploy'
// events — stays silent: audio.handleBattleEvents sounds those.
// Enemy modes (the `form` of a sim fx — shared/protocol.js fxForm — → `setForm(form, fx)`): 掠海漂移体 dropping to 爬行模式
// (user playtest #5 item 1) plays its skeleton's 'Change' clip once, then the crawl set (*_02); 暴鸰 flies on without its
// bomb (*_2) after the drop (feedback D4); 转译基底's forms, the 逐火 embers, 再生's puppet, the leaders' 重生 and 守墓石像
@@ -149,6 +156,11 @@ export const SPINE_RETRY_MS = Object.freeze([2000, 6000, 15000, 30000]);
* [ASSUMED] the length: a healthy load finishes within a few seconds once the tab is visible.
*/
export const SPINE_STUCK_MS = 5000;
/**
* Seconds a prep landing (UnitView.land) counts as playing when the model's Start clip length is unknown (no manifest entry
* yet): the operators' Start clips run 0.77–1.2 s, most of them 1 s (data/assets.json). [ASSUMED]
*/
export const START_CLIP_FALLBACK = 1;
/** Heights above this count as standing on a raised top (bench pads are the lowest raised tiles, 0.16). */
const RAISED_Z = 0.12;
@@ -447,9 +459,9 @@ function bar(P, parent, color, alpha = 1) {
}
/**
* Shared context handed to every view by app.js.
* Shared context handed to every view by app.js (`audio`: the audio manager of public/js/audio.js — prep landings, land()).
* @typedef {{ P: any, layers: { shadow: any, units: any, bars: any, groundFx: any },
* assets: any, cam: () => any, heightAt: (r:number,c:number)=>number, fx: any, time: () => number,
* assets: any, audio?: any, cam: () => any, heightAt: (r:number,c:number)=>number, fx: any, time: () => number,
* settings: { damageNumbers: boolean, quality: string } }} ViewCtx
*/
@@ -565,6 +577,7 @@ export class UnitView {
this.spineReady = false;
this._modelDirty = false; // died / stood up since the last frame: update() checks Front ⇄ Back (_syncModel)
this._pendingDeployElapsed = null; // elapsed game seconds until a late model can continue Start
this._landUntil = 0; // a prep landing (land) owns the Start clip until then (ms, performance clock)
this._spineBusy = false; // a Spine load of this view is in flight
this._spineTries = 0; // failed loads since the last model (SPINE_RETRY_MS)
this._retryAt = 0; // when the next retry is due (ms, performance clock; 0 = none)
@@ -1060,6 +1073,44 @@ export class UnitView {
if (this.actor) this.actor.deploy();
}
/**
* A prep piece lands (PR #416 by @Cromemadnd; see the header): its Start clip again — a model still loading continues it
* by the time gone (onDeploy, 0.2.3) — and its landing sound, once. Refused (false) for anything but an idle prep piece
* (a battle unit, one dying, lifted by a drag, or in another clip) and for a piece whose Start already plays: a second
* trigger of the same landing — a purchase then a move, the round start's replay over a piece just put down — changes
* nothing and sounds nothing. Refused in a hidden tab too: no frame shows it there, and the clip and the suspended audio
* would only play it, stale, once the tab is back.
* @returns {boolean} whether the Start clip started and the landing sound was asked for
*/
land() {
if (this.destroyed || !this.prep || this.isEnemy || !this.alive || this.dying > 0 || this.lift > 0) return false;
if (globalThis.document?.hidden) return false;
if (this.deploying()) return false;
if (this.actor && this.actor.mode !== 'base') return false;
this.onDeploy();
this._landUntil = nowMs() + this._startDur() * 1000;
try { this.ctx.audio?.deployCue?.({ def: this.info.spine || this.info.defId, defId: this.info.defId, kind: this.info.kind }, this.id); } catch { /* the sound never stops the landing */ }
return true;
}
/**
* Whether the Start clip plays now: on the model, owed to a model still loading (onDeploy), or a landing (land) cued less
* than a clip ago — the last covers a model without a Start clip and a view without a model.
*/
deploying() {
if (this.actor && this.actor.deployElapsed() != null) return true;
if (!this.actor && this._pendingDeployElapsed != null && this._pendingDeployElapsed < this._startDur()) return true;
return nowMs() < this._landUntil;
}
/** Seconds of the Start clip of the model asked for (its manifest entry), START_CLIP_FALLBACK without one. */
_startDur() {
const e = this.entry;
const name = e && e.anims && typeof e.anims.deploy === 'string' ? e.anims.deploy : null;
const d = name && e.animations && Object.hasOwn(e.animations, name) ? Number(e.animations[name]) : NaN;
return Number.isFinite(d) && d > 0 ? d : START_CLIP_FALLBACK;
}
onStatus(key, on) {
if (typeof key !== 'string') return;
if (on) this.statuses.add(key); else this.statuses.delete(key);