fix: scope Nepal media playback to explicit scene actions

This commit is contained in:
manjunath22466 committed 2026-09-16 12:14:15 +05:30
1 parent cf0b9927de
commit 621d186de1
10 files changed
+482 -5

No files matched your search

+60 -2
View File
@@ -1009,13 +1009,39 @@ export class SceneDirector {
return Promise.resolve({ started: false, reason: 'destroyed' });
this._sceneSeekGeneration++;
this._interactionTransitions = 0;
return this._trackWork(this._loadShot(sceneId, shotId, options));
const previousGeneration = this._loadGeneration;
const work = this._loadShot(sceneId, shotId, options);
const generation = this._loadGeneration;
const ownsLoad = generation !== previousGeneration;
return this._trackWork(
work.then(
(result) => {
if (
ownsLoad &&
!result?.started &&
generation === this._loadGeneration
)
this._setSceneMediaPlayback();
return result;
},
(error) => {
if (ownsLoad && generation === this._loadGeneration)
this._setSceneMediaPlayback();
throw error;
},
),
);
}
async _loadShot(
sceneId,
shotId,
{ flyDuration = null, fromCamera = null, sceneSeek = null } = {},
{
flyDuration = null,
fromCamera = null,
sceneSeek = null,
playMedia = false,
} = {},
) {
if (this._running) return { started: false, reason: 'already-running' };
const { scene, shot } = this._getShot(sceneId, shotId);
@@ -1034,6 +1060,7 @@ export class SceneDirector {
// manager) rather than merely ignored once it has already committed.
this._cancelActiveSceneTravel();
this._usesAuthoredCamera = !!shot.move;
this._setSceneMediaPlayback();
this._interactions?.clear();
this._dataPacks?.clear();
this._loadAbort?.abort();
@@ -1064,6 +1091,10 @@ export class SceneDirector {
if (token.cancelled) return;
const seekState =
sceneSeek && typeof sceneSeek === 'object' ? sceneSeek : null;
// Previous-scene disable revokes media ownership. Grant the target only
// after release and visual setup have succeeded for this live LOAD.
if (playMedia && !seekState)
this._setSceneMediaPlayback(scene, shot, token);
const layerResult = await this._applyLayerStates(
this._layerStatesForShot(scene, shot, {
cameraSettled: seekState ? seekState.cameraProgress >= 1 : false,
@@ -1159,6 +1190,29 @@ export class SceneDirector {
return layerStatesForShot(scene, shot, this._scenePacks, options);
}
/** Give opt-in media layers a transient, cancellable shot owner. */
_setSceneMediaPlayback(scene = null, shot = null, token = null) {
for (const module of this._sceneMediaModules || [])
module.setSceneMediaPlayback();
this._sceneMediaModules = new Set();
if (!scene || !shot || !token || token.cancelled || token.signal?.aborted)
return;
for (const [id, state] of Object.entries(shot.layers || {})) {
const module = this.dataManager?.layers?.get(id)?.module;
if (
!state?.enabled ||
typeof module?.setSceneMediaPlayback !== 'function'
)
continue;
module.setSceneMediaPlayback({
sceneId: scene.id,
shotId: shot.id,
token,
});
this._sceneMediaModules.add(module);
}
}
/** Keep installed append-pack shots on any surface declared by their source recipe. */
_visualStateForShot(shot) {
return visualStateForShot(
@@ -1314,6 +1368,7 @@ export class SceneDirector {
const previousShot =
scene.shots[(shotIndex - 1 + scene.shots.length) % scene.shots.length];
const result = await this.loadShot(sceneId, shotId, {
playMedia: true,
flyDuration: shot.durationSec || DEFAULT_SHOT_DURATION_SEC,
fromCamera: shot.move
? null
@@ -1658,6 +1713,7 @@ export class SceneDirector {
// load cannot land a stale shot's layers on top of the run's first shot.
// Aborting cancels a layer transition already in flight; bumping the
// generation disowns everything the load has not yet started.
this._setSceneMediaPlayback();
this._cancelActiveSceneTravel();
this._interactions?.clear();
this._dataPacks?.clear();
@@ -1771,6 +1827,7 @@ export class SceneDirector {
* @param {string} [reason='Stopped'] - Human-readable cancellation reason
*/
stopScene(reason = 'Stopped') {
this._setSceneMediaPlayback();
this._interactions?.clear();
this._dataPacks?.clear();
this._sceneSeekGeneration++;
@@ -2314,6 +2371,7 @@ export class SceneDirector {
* and resets UI buttons to the idle state.
*/
_finishRun() {
this._setSceneMediaPlayback();
this._clock.finish();
this._setPlaybackKeyboardEnabled(false);
// Covers the error path too: a run that threw mid-shot must not leave a
+67
View File
@@ -731,6 +731,73 @@ function makeDirector(options = {}) {
return { director, viewer, styleManager, dataManager, restore };
}
test('only Play Shot or a scene run grants transient media authority; LOAD, Stop and replacement revoke it', async () => {
const { director, dataManager, restore } = makeDirector();
let owner = null;
const owners = [];
dataManager.layers = new Map([['flights', { module: {
setSceneMediaPlayback(value = null) { owner = value; if (value) owners.push(value.shotId); },
} }]]);
try {
await director.loadShot('scene-1', 'shot-a', { flyDuration: 0 });
assert.equal(owner, null, 'passive LOAD is not playback');
await director.replayShot('scene-1', 'shot-a');
assert.equal(owner?.shotId, 'shot-a');
assert.equal(owner.token.cancelled, false);
await director.loadShot('missing-scene', 'missing-shot');
assert.equal(owner?.shotId, 'shot-a', 'rejected navigation does not revoke another action');
director._running = true;
await director.loadShot('scene-1', 'shot-b');
assert.equal(owner?.shotId, 'shot-a', 'LOAD refused during a run cannot stop its media');
director._running = false;
await director.loadShot('scene-1', 'shot-b', { flyDuration: 0 });
assert.equal(owner, null, 'replacement LOAD revokes the prior replay');
await director.replayShot('scene-1', 'shot-a');
director.stopScene();
assert.equal(owner, null);
director._sleep = async () => {};
owners.length = 0;
await director.startScene('scene-1', { single: true, preview: false });
assert.deepEqual(owners, ['shot-a'], 'only enabled opt-in layers receive playback authority');
assert.equal(owner, null, 'run completion releases the last shot owner');
} finally { await director.destroy(); restore(); }
});
test('cross-scene replay grants media ownership only after the previous scene releases its layers', async () => {
const { director, dataManager, restore } = makeDirector();
let owner = null;
const events = [];
const media = { setSceneMediaPlayback(value = null) { owner = value; } };
dataManager.layers = new Map([['flights', { module: media }]]);
const setEnabled = dataManager.setEnabled.bind(dataManager);
dataManager.setEnabled = async (id, enabled, options) => {
if (id === 'flights') {
events.push({ enabled, owner: owner?.shotId ?? null });
if (!enabled) media.setSceneMediaPlayback();
}
return setEnabled(id, enabled, options);
};
try {
const previous = director._project.scenes[0];
previous.releaseLayerIds = ['flights'];
const target = structuredClone(previous);
target.id = 'other-media-scene';
director._project.scenes.push(target);
await director.loadShot(previous.id, 'shot-a', { flyDuration: 0 });
events.length = 0;
const result = await director.replayShot(target.id, 'shot-a');
assert.equal(result.started, true);
assert.deepEqual(events.slice(0, 2), [
{ enabled: false, owner: null },
{ enabled: true, owner: 'shot-a' },
], 'old-scene disable must finish before granting the new owner');
assert.equal(owner?.sceneId, target.id);
assert.equal(owner?.token.cancelled, false);
director.stopScene();
assert.equal(owner, null);
} finally { await director.destroy(); restore(); }
});
test('scene camera waits for provider completion and fade rather than the saved media hold', async () => {
const { director, viewer, dataManager, restore } = makeDirector();
let release;
+1
View File
@@ -30,6 +30,7 @@ export function createScenePlaybackAdapter(director, defaultShotDurationSec) {
);
},
async applyLayers({ scene, shot, token }) {
director._setSceneMediaPlayback(scene, shot, token);
const result = await director._applyLayerStates(
director._layerStatesForShot(scene, shot),
token,