@@ -5,6 +5,7 @@ import cloneDeep from 'lodash/cloneDeep';
5
5
import { resetStageState , stageActions } from '@/store/stageReducer' ;
6
6
import { nextSentence } from '@/Core/controller/gamePlay/nextSentence' ;
7
7
import { IRunPerform } from '@/store/stageInterface' ;
8
+ import { WEBGAL_NONE } from '@/Core/constants' ;
8
9
9
10
/**
10
11
* 获取随机演出名称
@@ -18,8 +19,23 @@ export class PerformController {
18
19
public timeoutList : Array < ReturnType < typeof setTimeout > > = [ ] ;
19
20
20
21
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
+
21
37
// 语句不执行演出
22
- if ( perform . performName === 'none' ) {
38
+ if ( perform . performName === WEBGAL_NONE ) {
23
39
return ;
24
40
}
25
41
// 同步演出状态
@@ -50,12 +66,19 @@ export class PerformController {
50
66
if ( ! e . isHoldOn && e . performName === name ) {
51
67
e . stopFunction ( ) ;
52
68
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 -- ;
53
78
if ( e . goNextWhenOver ) {
54
79
// nextSentence();
55
80
this . goNextWhenOver ( ) ;
56
81
}
57
- this . performList . splice ( i , 1 ) ;
58
- i -- ;
59
82
}
60
83
}
61
84
} else {
0 commit comments