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.stateManager = new StateManager()
|
||||||
this.choiceSystem = new ChoiceSystem()
|
this.choiceSystem = new ChoiceSystem()
|
||||||
this.qteSystem = new QTESystem()
|
this.qteSystem = new QTESystem()
|
||||||
|
|
||||||
|
this.videoManager.onTimeUpdate(this.checkQTE)
|
||||||
}
|
}
|
||||||
|
|
||||||
on(event: EngineEvent, handler: EventHandler) {
|
on(event: EngineEvent, handler: EventHandler) {
|
||||||
@@ -70,10 +72,6 @@ export class Engine {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.videoManager.onTimeUpdate((time) => {
|
|
||||||
this.checkQTE(scene, time)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (this.isInitialScene) {
|
if (this.isInitialScene) {
|
||||||
this.isInitialScene = false
|
this.isInitialScene = false
|
||||||
this.videoManager.playInitial(scene.videoUrl, preloadUrls)
|
this.videoManager.playInitial(scene.videoUrl, preloadUrls)
|
||||||
@@ -84,9 +82,9 @@ export class Engine {
|
|||||||
this.emit('sceneChange', scene)
|
this.emit('sceneChange', scene)
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkQTE(scene: SceneNode, time: number) {
|
private checkQTE = (time: number) => {
|
||||||
if (this.currentScene?.id !== scene.id) return
|
const scene = this.currentScene
|
||||||
if (!scene.qte || this.qteTriggered) return
|
if (!scene?.qte || this.qteTriggered) return
|
||||||
if (time >= scene.qte.triggerTime) {
|
if (time >= scene.qte.triggerTime) {
|
||||||
this.qteTriggered = true
|
this.qteTriggered = true
|
||||||
const qte = scene.qte
|
const qte = scene.qte
|
||||||
|
|||||||
Reference in New Issue
Block a user