refactor: extract enterScene as single source of truth for scene transitions
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user