Skip to content

Commit 368f613

Browse files
fix: perform duplicate problem
1 parent aee308c commit 368f613

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

packages/webgal/src/Core/Modules/perform/performController.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ export class PerformController {
1818
public timeoutList: Array<ReturnType<typeof setTimeout>> = [];
1919

2020
public arrangeNewPerform(perform: IPerform, script: ISentence, syncPerformState = true) {
21+
// 检查演出列表内是否有相同的演出,如果有,一定是出了什么问题
22+
const dupPerformIndex = this.performList.findIndex((p) => p.performName === perform.performName);
23+
if (dupPerformIndex > -1) {
24+
// 结束并删除全部重复演出
25+
for (let i = 0; i < this.performList.length; i++) {
26+
const e = this.performList[i];
27+
if (e.performName === perform.performName) {
28+
e.stopFunction();
29+
clearTimeout(e.stopTimeout as unknown as number);
30+
this.performList.splice(i, 1);
31+
i--;
32+
}
33+
}
34+
}
35+
2136
// 语句不执行演出
2237
if (perform.performName === 'none') {
2338
return;

packages/webgal/src/Core/gameScripts/playEffect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ export const playEffect = (sentence: ISentence): IPerform => {
5656
const seVol = mainVol * 0.01 * (userDataState.optionData?.seVolume ?? 100) * 0.01 * volume * 0.01;
5757
seElement.volume = seVol;
5858
seElement.currentTime = 0;
59-
const perform = {
59+
const perform: IPerform = {
6060
performName: performInitName,
6161
duration: 1000 * 60 * 60,
6262
isHoldOn: isLoop,
6363
skipNextCollect: true,
6464
stopFunction: () => {
6565
// 演出已经结束了,所以不用播放效果音了
6666
seElement.pause();
67+
seElement.remove();
6768
},
6869
blockingNext: () => false,
6970
blockingAuto: () => {

packages/webgal/src/store/stageReducer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ const stageSlice = createSlice({
124124
}
125125
},
126126
addPerform: (state, action: PayloadAction<IRunPerform>) => {
127+
// 先检查是否有重复的,全部干掉
128+
const dupPerformIndex = state.PerformList.findIndex((p) => p.id === action.payload.id);
129+
if (dupPerformIndex > -1) {
130+
const dupId = action.payload.id;
131+
// 删除全部重复演出
132+
for (let i = 0; i < state.PerformList.length; i++) {
133+
const performItem: IRunPerform = state.PerformList[i];
134+
if (performItem.id === dupId) {
135+
state.PerformList.splice(i, 1);
136+
i--;
137+
}
138+
}
139+
}
127140
state.PerformList.push(action.payload);
128141
},
129142
removePerformByName: (state, action: PayloadAction<string>) => {

0 commit comments

Comments
 (0)