diff --git a/engine/core/Engine.ts b/engine/core/Engine.ts index 970e98c..9d26d98 100644 --- a/engine/core/Engine.ts +++ b/engine/core/Engine.ts @@ -62,11 +62,6 @@ export class Engine { } private goToScene(scene: SceneNode) { - this.currentScene = scene - this.qteTriggered = false - this.qteResolved = false - this.loopActive = false - const chapter = this.sceneManager.getChapterBySceneId(scene.id) if (chapter) { this.onUnlockChapter?.(chapter.id) @@ -96,6 +91,15 @@ export class Engine { this.audioSystem.stop(scene.bgmCrossFade ?? 2.0) } + this.enterScene(scene) + } + + private enterScene(scene: SceneNode) { + this.currentScene = scene + this.qteTriggered = false + this.qteResolved = false + this.loopActive = false + if (scene.type === 'image') { this.justCameFromImage = true this.isInitialScene = false @@ -380,34 +384,7 @@ export class Engine { this.ended = false this.isInitialScene = false - this.currentScene = scene - - if (scene.type === 'image') { - this.emit('sceneChange', scene) - const visible = this.getVisibleHotspots(scene) - if (visible.length > 0) { - this.emit('hotspotRequest', visible) - } - return - } - - const preloadUrls = this.sceneManager.getCandidateUrls( - scene, - (conds) => conds ? this.stateManager.evaluate(conds) : true - ) - - this.videoManager.onEnd(() => { - this.emit('videoEnd', scene) - this.onVideoEnd(scene) - }) - - const activeEl = this.videoManager.getActiveVideoElement() - activeEl?.pause() - - this.videoManager.switchTo(scene.videoUrl, preloadUrls) - - this.currentScene = scene - this.emit('sceneChange', scene) + this.enterScene(scene) } destroy() {