Skip to content

Commit

Permalink
new scene loader
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyMakesThings committed Oct 10, 2024
1 parent d5db2eb commit 391d56e
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -3562,7 +3562,8 @@ class Runtime extends EventEmitter {
[defaultSceneId]: {
name: "my scene",
id: defaultSceneId,
preview: undefined
preview: undefined,
temporary: false
}
}

Expand All @@ -3575,7 +3576,7 @@ class Runtime extends EventEmitter {
* @param {object} optScene an old scene object to base on.
* @returns {*}
*/
createScene (scene, optScene) {
createScene (scene, temporary, optScene) {
const usedNames = Object.values(this.scenes).map(s => s.name);
scene = StringUtil.unusedName(scene, usedNames);

Expand All @@ -3584,10 +3585,13 @@ class Runtime extends EventEmitter {
this.scenes[sceneId] = {
name: scene,
id: sceneId,
preview: undefined
preview: undefined,
temporary: !!temporary
};

this.updateScenePreview(sceneId);

return this.scenes[sceneId];
}

/**
Expand Down Expand Up @@ -3627,6 +3631,26 @@ class Runtime extends EventEmitter {
this.camera.loadSceneState(sceneId);
}

/**
* Load into a scene by its name.
* @param {string} sceneName the name of the scene.
*/
createOrLoadSceneFromName(sceneName) {
const usedNames = Object.values(this.scenes).map(s => s.name);

if (!usedNames.includes(sceneName)) {
const newScene = this.createScene(sceneName, true);
this.loadScene(newScene.id);
} else {
let scenesByName = {}
for (const s in this.scenes) {
scenesByName[s.name] = s.id;
}

this.loadScene(scenesByName[sceneName]);
}
}

/**
* Handle that the project has loaded in the Virtual Machine.
*/
Expand Down

0 comments on commit 391d56e

Please sign in to comment.