@@ -5,6 +5,7 @@ import cloneDeep from 'lodash/cloneDeep';
55import { resetStageState , stageActions } from '@/store/stageReducer' ;
66import { nextSentence } from '@/Core/controller/gamePlay/nextSentence' ;
77import { IRunPerform } from '@/store/stageInterface' ;
8+ import { WEBGAL_NONE } from '@/Core/constants' ;
89
910/**
1011 * 获取随机演出名称
@@ -18,8 +19,23 @@ export class PerformController {
1819 public timeoutList : Array < ReturnType < typeof setTimeout > > = [ ] ;
1920
2021 public arrangeNewPerform ( perform : IPerform , script : ISentence , syncPerformState = true ) {
22+ // 检查演出列表内是否有相同的演出,如果有,一定是出了什么问题
23+ const dupPerformIndex = this . performList . findIndex ( ( p ) => p . performName === perform . performName ) ;
24+ if ( dupPerformIndex > - 1 ) {
25+ // 结束并删除全部重复演出
26+ for ( let i = 0 ; i < this . performList . length ; i ++ ) {
27+ const e = this . performList [ i ] ;
28+ if ( e . performName === perform . performName ) {
29+ e . stopFunction ( ) ;
30+ clearTimeout ( e . stopTimeout as unknown as number ) ;
31+ this . performList . splice ( i , 1 ) ;
32+ i -- ;
33+ }
34+ }
35+ }
36+
2137 // 语句不执行演出
22- if ( perform . performName === 'none' ) {
38+ if ( perform . performName === WEBGAL_NONE ) {
2339 return ;
2440 }
2541 // 同步演出状态
@@ -50,12 +66,19 @@ export class PerformController {
5066 if ( ! e . isHoldOn && e . performName === name ) {
5167 e . stopFunction ( ) ;
5268 clearTimeout ( e . stopTimeout as unknown as number ) ;
69+ /**
70+ * 在演出列表里删除演出对象的操作必须在调用 goNextWhenOver 之前
71+ * 因为 goNextWhenOver 会调用 nextSentence,而 nextSentence 会清除目前未结束的演出
72+ * 那么 nextSentence 函数就会删除这个演出,但是此时,在这个上下文,i 已经被确定了
73+ * 所以 goNextWhenOver 后的代码会多删东西,解决方法就是在调用 goNextWhenOver 前先删掉这个演出对象
74+ * 此问题对所有 goNextWhenOver 属性为真的演出都有影响,但只有 2 个演出有此问题
75+ */
76+ this . performList . splice ( i , 1 ) ;
77+ i -- ;
5378 if ( e . goNextWhenOver ) {
5479 // nextSentence();
5580 this . goNextWhenOver ( ) ;
5681 }
57- this . performList . splice ( i , 1 ) ;
58- i -- ;
5982 }
6083 }
6184 } else {
0 commit comments