fix: register checkQTE once in constructor instead of per-scene
Previously goToScene added a new checkQTE closure to onTimeUpdate on every scene transition, accumulating stale closures that re-triggered old QTE. Now checkQTE is an arrow property registered once in the constructor, reading this.currentScene directly — no closure, no stale references, no guard condition needed.
This commit is contained in:
@@ -27,6 +27,8 @@ export class Engine {
|
||||
this.stateManager = new StateManager()
|
||||
this.choiceSystem = new ChoiceSystem()
|
||||
this.qteSystem = new QTESystem()
|
||||
|
||||
this.videoManager.onTimeUpdate(this.checkQTE)
|
||||
}
|
||||
|
||||
on(event: EngineEvent, handler: EventHandler) {
|
||||
@@ -70,10 +72,6 @@ export class Engine {
|
||||
}
|
||||
})
|
||||
|
||||
this.videoManager.onTimeUpdate((time) => {
|
||||
this.checkQTE(scene, time)
|
||||
})
|
||||
|
||||
if (this.isInitialScene) {
|
||||
this.isInitialScene = false
|
||||
this.videoManager.playInitial(scene.videoUrl, preloadUrls)
|
||||
@@ -84,9 +82,9 @@ export class Engine {
|
||||
this.emit('sceneChange', scene)
|
||||
}
|
||||
|
||||
private checkQTE(scene: SceneNode, time: number) {
|
||||
if (this.currentScene?.id !== scene.id) return
|
||||
if (!scene.qte || this.qteTriggered) return
|
||||
private checkQTE = (time: number) => {
|
||||
const scene = this.currentScene
|
||||
if (!scene?.qte || this.qteTriggered) return
|
||||
if (time >= scene.qte.triggerTime) {
|
||||
this.qteTriggered = true
|
||||
const qte = scene.qte
|
||||
|
||||
Reference in New Issue
Block a user