diff --git a/packages/webgal/src/Core/Modules/animationFunctions.ts b/packages/webgal/src/Core/Modules/animationFunctions.ts index 1c5fa4471..a399013fc 100644 --- a/packages/webgal/src/Core/Modules/animationFunctions.ts +++ b/packages/webgal/src/Core/Modules/animationFunctions.ts @@ -13,6 +13,7 @@ import { DEFAULT_FIG_IN_DURATION, DEFAULT_FIG_OUT_DURATION, } from '../constants'; +import { stageActions } from '@/store/stageReducer'; // eslint-disable-next-line max-params export function getAnimationObject(animationName: string, target: string, duration: number, writeDefault: boolean) { @@ -91,17 +92,20 @@ export function getEnterExitAnimation( duration = DEFAULT_BG_OUT_DURATION; } duration = - webgalStore.getState().stage.animationSettings.find((setting) => setting.target + '-off' === target) - ?.exitDuration ?? duration; + webgalStore.getState().stage.animationSettings.find((setting) => setting.target === target)?.exitDuration ?? + duration; // 走默认动画 let animation: IAnimationObject | null = generateUniversalSoftOffAnimationObj(realTarget ?? target, duration); const animationName = webgalStore .getState() - .stage.animationSettings.find((setting) => setting.target + '-off' === target)?.exitAnimationName; + .stage.animationSettings.find((setting) => setting.target === target)?.exitAnimationName; if (animationName) { logger.debug('取代默认退出动画', target); animation = getAnimationObject(animationName, realTarget ?? target, getAnimateDuration(animationName), false); duration = getAnimateDuration(animationName); + // 退出动画拿完后,删了这个设定 + webgalStore.dispatch(stageActions.removeAnimationSettingsByTargetOff(target)); + logger.debug('删除退出动画设定', target); } return { duration, animation }; } diff --git a/packages/webgal/src/Core/gameScripts/changeFigure.ts b/packages/webgal/src/Core/gameScripts/changeFigure.ts index 907d5ad99..10a8c8891 100644 --- a/packages/webgal/src/Core/gameScripts/changeFigure.ts +++ b/packages/webgal/src/Core/gameScripts/changeFigure.ts @@ -155,6 +155,10 @@ export function changeFigure(sentence: ISentence): IPerform { } } const setAnimationNames = (key: string, sentence: ISentence) => { + // 如果立绘被关闭了,那么就不用设置了 + if (content === '') { + return; + } // 处理 transform 和 默认 transform let animationObj: AnimationFrame[]; if (transformString) { diff --git a/packages/webgal/src/store/stageReducer.ts b/packages/webgal/src/store/stageReducer.ts index 450efbe38..894aad736 100644 --- a/packages/webgal/src/store/stageReducer.ts +++ b/packages/webgal/src/store/stageReducer.ts @@ -155,6 +155,31 @@ const stageSlice = createSlice({ }, removeAnimationSettingsByTarget: (state, action: PayloadAction) => { const index = state.animationSettings.findIndex((a) => a.target === action.payload); + if (index >= 0) { + const prev = state.animationSettings[index]; + state.animationSettings.splice(index, 1); + + if (prev.exitAnimationName) { + // 如果有退出动画设定,保留一个 -off 的设定 + const prevTarget = `${action.payload}-off`; + const prevSetting = { + ...prev, + target: prevTarget, + }; + + const prevIndex = state.animationSettings.findIndex((a) => a.target === prevTarget); + + if (prevIndex >= 0) { + state.animationSettings.splice(prevIndex, 1, prevSetting); + } else { + state.animationSettings.push(prevSetting); + } + } + } + }, + removeAnimationSettingsByTargetOff: (state, action: PayloadAction) => { + // 这里不加 -off 因为传入的就是带 -off 的 + const index = state.animationSettings.findIndex((a) => a.target === `${action.payload}`); if (index >= 0) { state.animationSettings.splice(index, 1); }