mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
refactor(director): separate timing clocks and scene pack presentation
This commit is contained in:
1 parent
5728dec24d
commit
8a3c4868b0
19 files changed
+1190
-471
No files matched your search
@@ -0,0 +1,11 @@
|
||||
import { SCENE_APPEND_RECIPES } from '../recipes.js';
|
||||
import { createScenePackRegistry } from './registry.js';
|
||||
import { nepalScenePresentation } from './nepal.js';
|
||||
|
||||
/** Compose the installed scene recipes and their trusted presentation rules. */
|
||||
export function createDefaultScenePacks() {
|
||||
return createScenePackRegistry({
|
||||
recipes: SCENE_APPEND_RECIPES,
|
||||
adapters: [nepalScenePresentation],
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { INCIDENT_OVERVIEW_HOLD_SEC } from '../../data/bhoteKoshiIncidentPlaces.js';
|
||||
|
||||
/** Existing Nepal presentation rules; authored assets and saved shots stay untouched. */
|
||||
export const nepalScenePresentation = {
|
||||
minimumHoldSec(states) {
|
||||
const overview = states['bhote-koshi-locator'];
|
||||
return overview?.enabled &&
|
||||
overview.params?.presentation === 'bhote-koshi-incident-places'
|
||||
? INCIDENT_OVERVIEW_HOLD_SEC
|
||||
: 0;
|
||||
},
|
||||
resolveVisual(shot, visual, isMapStackAvailable) {
|
||||
const isNepalShot =
|
||||
shot?.layers?.['bhote-koshi-2026']?.enabled ||
|
||||
shot?.layers?.['bhote-koshi-locator']?.enabled;
|
||||
// A credential is not proof of a loaded tileset. Resolve actual capability at playback time.
|
||||
return isNepalShot &&
|
||||
visual.mapStack === 'photoreal' &&
|
||||
!isMapStackAvailable('photoreal')
|
||||
? { ...visual, mapStack: 'esri-imagery' }
|
||||
: visual;
|
||||
},
|
||||
cancelMotion(getLayerModule) {
|
||||
getLayerModule('bhote-koshi-locator')?.cancelSceneMotion?.();
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
/** Register trusted scene-pack recipes and presentation adapters at composition time. */
|
||||
export function createScenePackRegistry({ recipes = [], adapters = [] } = {}) {
|
||||
const byId = new Map(recipes.map((recipe) => [recipe.id, recipe]));
|
||||
const rules = [...adapters];
|
||||
return {
|
||||
recipeForShot: (shot) => byId.get(shot?.sourcePackId) || null,
|
||||
minimumHoldSec(states) {
|
||||
return Math.max(
|
||||
0,
|
||||
...rules.map((rule) => rule.minimumHoldSec?.(states) || 0),
|
||||
);
|
||||
},
|
||||
resolveVisual(shot, visual, isMapStackAvailable) {
|
||||
return rules.reduce(
|
||||
(result, rule) =>
|
||||
rule.resolveVisual?.(shot, result, isMapStackAvailable) || result,
|
||||
visual,
|
||||
);
|
||||
},
|
||||
cancelMotion(getLayerModule) {
|
||||
for (const rule of rules) rule.cancelMotion?.(getLayerModule);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createScenePackRegistry } from './registry.js';
|
||||
import {
|
||||
effectiveShotHoldSec,
|
||||
shotRuntimeDurationSec,
|
||||
layerStatesForShot,
|
||||
visualStateForShot,
|
||||
} from '../shotPresentation.js';
|
||||
|
||||
test('registered pack rules apply to another source without editing the Director or saved shots', () => {
|
||||
const recipe = {
|
||||
id: 'sample',
|
||||
runtimeHoldSecByBeat: { arrival: 6 },
|
||||
runtimeControlsByBeat: {
|
||||
arrival: { minimumHoldSec: 8, deferEvidenceUntilCameraSettled: true },
|
||||
},
|
||||
};
|
||||
let cancelled = 0;
|
||||
const packs = createScenePackRegistry({
|
||||
recipes: [recipe],
|
||||
adapters: [
|
||||
{
|
||||
resolveVisual: (_, visual) => ({ ...visual, mapStack: 'osm' }),
|
||||
cancelMotion: (getModule) => getModule('sample').cancelSceneMotion(),
|
||||
},
|
||||
],
|
||||
});
|
||||
const shot = {
|
||||
id: 'a',
|
||||
sourcePackId: 'sample',
|
||||
durationSec: 2,
|
||||
holdSec: 1,
|
||||
visual: { style: 'normal' },
|
||||
layers: {
|
||||
sample: {
|
||||
enabled: true,
|
||||
params: { presentation: 'scene-beat', beatId: 'arrival' },
|
||||
},
|
||||
},
|
||||
};
|
||||
const scene = { id: 'scene', shots: [shot], releaseLayerIds: ['other'] };
|
||||
const before = structuredClone(shot);
|
||||
assert.equal(shotRuntimeDurationSec(scene, shot, packs), 10);
|
||||
assert.equal(effectiveShotHoldSec(scene, shot, packs), 8);
|
||||
const states = layerStatesForShot(scene, shot, packs, {
|
||||
cameraSettled: true,
|
||||
});
|
||||
assert.equal(states.sample.params.sceneControls.cameraSettled, true);
|
||||
assert.equal(states.sample.params.sceneContext.holdSec, 8);
|
||||
assert.equal(states.other.enabled, false);
|
||||
assert.equal(visualStateForShot(shot, packs, () => true).mapStack, 'osm');
|
||||
packs.cancelMotion(() => ({ cancelSceneMotion: () => cancelled++ }));
|
||||
assert.equal(cancelled, 1);
|
||||
assert.deepEqual(shot, before);
|
||||
});
|
||||
Reference in new issue
Block a user