Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/webgal/src/Core/Modules/animationFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Comment on lines 94 to +101

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码的可读性和性能,建议将 webgalStore.getState().stage.animationSettings.find(...) 的查找操作提取到一个变量中。这样可以避免重复访问 Redux store 和遍历数组,使代码更高效简洁。

Suggested change
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;
const animationSetting = webgalStore.getState().stage.animationSettings.find((setting) => setting.target === target);
duration = animationSetting?.exitDuration ?? duration;
// 走默认动画
let animation: IAnimationObject | null = generateUniversalSoftOffAnimationObj(realTarget ?? target, duration);
const animationName = animationSetting?.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 };
}
Expand Down
4 changes: 4 additions & 0 deletions packages/webgal/src/Core/gameScripts/changeFigure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions packages/webgal/src/store/stageReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,31 @@ const stageSlice = createSlice({
},
removeAnimationSettingsByTarget: (state, action: PayloadAction<string>) => {
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<string>) => {
// 这里不加 -off 因为传入的就是带 -off 的
const index = state.animationSettings.findIndex((a) => a.target === `${action.payload}`);
if (index >= 0) {
state.animationSettings.splice(index, 1);
}
Expand Down