mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Authoring: pick any scene again, and select the first scene on load
Restores the scene picker and its selection on load, after a delete and after an import, so PLAY and NEXT work after a reload. Open in GEV selecting a shot and NEW SCENE stay as they are.
This commit is contained in:
1 parent
1cb3e88027
commit
0a39b05cdb
30 files changed
+301
-210
No files matched your search
+9
-29
@@ -189,10 +189,8 @@ export class SceneDirector {
|
||||
this._lastRunJson = '';
|
||||
|
||||
this._project = this._loadProject();
|
||||
// Authoring starts with no scene: the built-in scenes stay in the project
|
||||
// (Stories plays them) but only NEW SCENE or selectShot makes one current.
|
||||
this._selectedSceneId = null;
|
||||
this._selectedShotId = null;
|
||||
this._selectedSceneId = this._project.scenes[0]?.id || null;
|
||||
this._selectedShotId = this._project.scenes[0]?.shots[0]?.id || null;
|
||||
/** @type {string|null} Scene whose layer state most recently landed. */
|
||||
this._loadedSceneId = null;
|
||||
|
||||
@@ -234,9 +232,6 @@ export class SceneDirector {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Upgrading a pack selects its scene; on load nothing is selected.
|
||||
this._selectedSceneId = null;
|
||||
this._selectedShotId = null;
|
||||
}
|
||||
this._initUI();
|
||||
// A status the director wrote itself follows the language; one it was
|
||||
@@ -492,16 +487,12 @@ export class SceneDirector {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep the selection on an existing scene, or on none, and present the
|
||||
* scene's name.
|
||||
*/
|
||||
/** Rebuild the scene dropdown options and sync the selected value. */
|
||||
_renderSceneSelect() {
|
||||
if (
|
||||
!this._project.scenes.some((scene) => scene.id === this._selectedSceneId)
|
||||
) {
|
||||
this._selectedSceneId = null;
|
||||
this._selectedShotId = null;
|
||||
this._selectedSceneId = this._project.scenes[0]?.id || null;
|
||||
}
|
||||
this._publish({ type: 'scene-options-changed' });
|
||||
}
|
||||
@@ -564,10 +555,7 @@ export class SceneDirector {
|
||||
this._publish({ type: 'scene-created', scene });
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the currently selected scene after user confirmation and select
|
||||
* none. Resets to defaults if empty.
|
||||
*/
|
||||
/** Delete the currently selected scene after user confirmation. Resets to defaults if empty. */
|
||||
_deleteSelectedScene() {
|
||||
const scene = this._getSelectedScene();
|
||||
if (!scene) return;
|
||||
@@ -580,9 +568,8 @@ export class SceneDirector {
|
||||
this._project = createDefaultProject();
|
||||
}
|
||||
|
||||
// Authoring goes back to no scene.
|
||||
this._selectedSceneId = null;
|
||||
this._selectedShotId = null;
|
||||
this._selectedSceneId = this._project.scenes[0]?.id || null;
|
||||
this._selectedShotId = this._project.scenes[0]?.shots[0]?.id || null;
|
||||
this._saveProject();
|
||||
this._publish({ type: 'scene-deleted', scene });
|
||||
if (scene.stories) this._publish({ type: 'stories-changed' });
|
||||
@@ -2001,14 +1988,6 @@ export class SceneDirector {
|
||||
* @returns {boolean} False when the scene is not installed.
|
||||
*/
|
||||
selectShot(sceneId, shotId = null) {
|
||||
// No scene: AUTHORING goes back to "No scene yet".
|
||||
if (sceneId == null) {
|
||||
this._selectedSceneId = null;
|
||||
this._selectedShotId = null;
|
||||
this._renderSceneSelect();
|
||||
this._renderShotList();
|
||||
return true;
|
||||
}
|
||||
const scene = this._project.scenes.find(({ id }) => id === sceneId);
|
||||
if (!scene) return false;
|
||||
this._selectedSceneId = scene.id;
|
||||
@@ -2543,12 +2522,13 @@ export class SceneDirector {
|
||||
);
|
||||
this._storageReadError = null;
|
||||
// Keep authoring on the named or current scene, else the first scene
|
||||
// that is not a built-in one, else none.
|
||||
// that is not a built-in one, else the first scene.
|
||||
const builtIn = new Set(SCENE_RECIPES.map(({ id }) => id));
|
||||
const selected =
|
||||
project.scenes.find(({ id }) => id === selection?.sceneId) ||
|
||||
project.scenes.find(({ id }) => id === this._selectedSceneId) ||
|
||||
project.scenes.find(({ id }) => !builtIn.has(id)) ||
|
||||
project.scenes[0] ||
|
||||
null;
|
||||
this._selectedSceneId = selected?.id ?? null;
|
||||
this._selectedShotId =
|
||||
|
||||
@@ -732,9 +732,8 @@ test('a legacy three-shot Nepal browser project bootstraps to the current 25-sho
|
||||
for (const shot of scene.shots.slice(0, 8)) {
|
||||
assert.equal(scene.appliedShotPacks[0].shotBindings[shot.title], shot.id);
|
||||
}
|
||||
// The upgrade selects nothing: authoring starts with no scene.
|
||||
assert.equal(director._selectedSceneId, null);
|
||||
assert.equal(director._selectedShotId, null);
|
||||
assert.equal(director._selectedSceneId, scene.id);
|
||||
assert.equal(director._selectedShotId, scene.shots[0].id);
|
||||
} finally {
|
||||
restore();
|
||||
}
|
||||
@@ -2174,9 +2173,9 @@ test('selectShot selects a scene and shot for authoring, falling back to the fir
|
||||
});
|
||||
assert.equal(director.hasScene(scene.id), true);
|
||||
assert.equal(director.hasScene('no-such-scene'), false);
|
||||
// No scene: back to "No scene yet".
|
||||
assert.equal(director.selectShot(null), true);
|
||||
assert.deepEqual(director.selection(), { sceneId: null, shotId: null });
|
||||
// No scene id changes nothing.
|
||||
assert.equal(director.selectShot(null), false);
|
||||
assert.equal(director._selectedSceneId, scene.id);
|
||||
} finally {
|
||||
restore();
|
||||
}
|
||||
@@ -2391,22 +2390,20 @@ test('deleting a scene or its last shot in Stories publishes stories-changed', (
|
||||
}
|
||||
});
|
||||
|
||||
test('authoring selects no scene on load, with or without a saved project', () => {
|
||||
test('authoring selects the first scene and shot on load, with or without a saved project', () => {
|
||||
for (const options of [{}, { storage: {} }]) {
|
||||
const { director, restore } = makeDirector(options);
|
||||
try {
|
||||
assert.ok(
|
||||
director._project.scenes.length > 0,
|
||||
'the scenes stay in the project',
|
||||
);
|
||||
assert.equal(director._selectedSceneId, null);
|
||||
assert.equal(director._selectedShotId, null);
|
||||
assert.equal(director._getSelectedScene(), null);
|
||||
const [first] = director._project.scenes;
|
||||
assert.ok(first, 'the project has scenes');
|
||||
assert.equal(director._selectedSceneId, first.id);
|
||||
assert.equal(director._selectedShotId, first.shots[0]?.id ?? null);
|
||||
director._selectedSceneId = 'gone';
|
||||
director._renderSceneSelect();
|
||||
assert.equal(
|
||||
director._selectedSceneId,
|
||||
null,
|
||||
'nothing falls back to the first scene',
|
||||
first.id,
|
||||
'a missing scene falls back to the first scene',
|
||||
);
|
||||
} finally {
|
||||
restore();
|
||||
@@ -2417,6 +2414,9 @@ test('authoring selects no scene on load, with or without a saved project', () =
|
||||
test('capture with no scene starts a new scene and captures into it', () => {
|
||||
const { director, restore } = makeDirector();
|
||||
try {
|
||||
// An imported empty project leaves nothing selected.
|
||||
director._selectedSceneId = null;
|
||||
director._selectedShotId = null;
|
||||
const changes = recordChanges(director);
|
||||
const before = director._project.scenes.length;
|
||||
director.captureShot();
|
||||
@@ -2442,6 +2442,7 @@ test('capture with no scene and no camera creates nothing', () => {
|
||||
const { director, styleManager, restore } = makeDirector();
|
||||
try {
|
||||
styleManager.getCameraState = () => null;
|
||||
director._selectedSceneId = null;
|
||||
const before = director._project.scenes.length;
|
||||
director.captureShot();
|
||||
assert.equal(director._project.scenes.length, before);
|
||||
@@ -2451,15 +2452,15 @@ test('capture with no scene and no camera creates nothing', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('deleting the current scene selects none', () => {
|
||||
test('deleting the current scene selects the first scene', () => {
|
||||
const project = structuredClone(PROJECT_FIXTURE);
|
||||
project.scenes.push({ id: 'scene-2', title: 'Second', shots: [] });
|
||||
const { director, restore } = makeDirector({ project });
|
||||
try {
|
||||
director.selectShot('scene-2');
|
||||
director._deleteSelectedScene();
|
||||
assert.equal(director._selectedSceneId, null);
|
||||
assert.equal(director._selectedShotId, null);
|
||||
assert.equal(director._selectedSceneId, 'scene-1');
|
||||
assert.equal(director._selectedShotId, 'shot-a');
|
||||
assert.deepEqual(
|
||||
director._project.scenes.map(({ id }) => id),
|
||||
['scene-1'],
|
||||
@@ -2469,7 +2470,7 @@ test('deleting the current scene selects none', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('an import keeps the current scene, else picks a non-built-in scene, else none', async () => {
|
||||
test('an import keeps the current scene, else picks a non-built-in scene, else the first', async () => {
|
||||
const { director, restore } = makeDirector();
|
||||
try {
|
||||
const exported = stringifySceneDocument(director._project);
|
||||
@@ -2494,8 +2495,8 @@ test('an import keeps the current scene, else picks a non-built-in scene, else n
|
||||
);
|
||||
assert.equal(
|
||||
director._selectedSceneId,
|
||||
null,
|
||||
'a built-in scene is never picked',
|
||||
SCENE_RECIPES[0].id,
|
||||
'a built-in scene only when there is nothing else',
|
||||
);
|
||||
} finally {
|
||||
restore();
|
||||
|
||||
Reference in new issue
Block a user