Skip to content

Commit 6f923aa

Browse files
committed
fix: duration args not work on enter animation and exit animation when using changeBg and changeFigure
#701
1 parent d29410f commit 6f923aa

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

packages/webgal/src/Core/gameScripts/changeBg/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ export const changeBg = (sentence: ISentence): IPerform => {
4242

4343
// 处理 transform 和 默认 transform
4444
const transformString = getSentenceArgByKey(sentence, 'transform');
45-
let duration = getSentenceArgByKey(sentence, 'duration');
45+
let durationFromArg = getSentenceArgByKey(sentence, 'duration');
4646
let ease = getSentenceArgByKey(sentence, 'ease')?.toString() ?? '';
47-
if (!duration || typeof duration !== 'number') {
48-
duration = 1000;
47+
let duration = 1000;
48+
if (typeof durationFromArg === 'number' && !isNaN(durationFromArg)) {
49+
duration = durationFromArg;
4950
}
5051
let animationObj: AnimationFrame[];
5152
if (transformString) {
@@ -59,6 +60,11 @@ export const changeBg = (sentence: ISentence): IPerform => {
5960
WebGAL.animationManager.addAnimation(newAnimation);
6061
duration = getAnimateDuration(animationName);
6162
WebGAL.animationManager.nextEnterAnimationName.set('bg-main', animationName);
63+
64+
let exitAnimationObj = [...animationObj].reverse();
65+
exitAnimationObj[0].alpha = 1;
66+
const exitAnimationName = (Math.random() * 10).toString(16);
67+
WebGAL.animationManager.nextExitAnimationName.set('bg-main-off', exitAnimationName);
6268
} catch (e) {
6369
// 解析都错误了,歇逼吧
6470
applyDefaultTransform();
@@ -78,6 +84,11 @@ export const changeBg = (sentence: ISentence): IPerform => {
7884
WebGAL.animationManager.addAnimation(newAnimation);
7985
duration = getAnimateDuration(animationName);
8086
WebGAL.animationManager.nextEnterAnimationName.set('bg-main', animationName);
87+
88+
let exitAnimationObj = [...animationObj].reverse();
89+
exitAnimationObj[0].alpha = 1;
90+
const exitAnimationName = (Math.random() * 10).toString(16);
91+
WebGAL.animationManager.nextExitAnimationName.set('bg-main-off', exitAnimationName);
8192
}
8293

8394
// 应用动画的优先级更高一点

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,18 @@ export function changeFigure(sentence: ISentence): IPerform {
165165
dispatch(stageActions.setFigureMetaData([deleteKey, 'zIndex', 0, true]));
166166
dispatch(stageActions.setFigureMetaData([deleteKey2, 'zIndex', 0, true]));
167167
}
168+
168169
const setAnimationNames = (key: string, sentence: ISentence) => {
169170
// 处理 transform 和 默认 transform
170171
const transformString = getSentenceArgByKey(sentence, 'transform');
171172
const durationFromArg = getSentenceArgByKey(sentence, 'duration');
172173
const ease = getSentenceArgByKey(sentence, 'ease')?.toString() ?? '';
173-
if (durationFromArg && typeof durationFromArg === 'number') {
174+
let animationObj: AnimationFrame[];
175+
176+
if (typeof durationFromArg === 'number' && !isNaN(durationFromArg)) {
174177
duration = durationFromArg;
175178
}
176-
let animationObj: AnimationFrame[];
179+
177180
if (transformString) {
178181
console.log(transformString);
179182
try {
@@ -186,6 +189,11 @@ export function changeFigure(sentence: ISentence): IPerform {
186189
WebGAL.animationManager.addAnimation(newAnimation);
187190
duration = getAnimateDuration(animationName);
188191
WebGAL.animationManager.nextEnterAnimationName.set(key, animationName);
192+
193+
let exitAnimationObj = [...animationObj].reverse();
194+
exitAnimationObj[0].alpha = 1;
195+
const exitAnimationName = (Math.random() * 10).toString(16);
196+
WebGAL.animationManager.nextExitAnimationName.set(key + '-off', exitAnimationName);
189197
} catch (e) {
190198
// 解析都错误了,歇逼吧
191199
applyDefaultTransform();
@@ -205,7 +213,13 @@ export function changeFigure(sentence: ISentence): IPerform {
205213
WebGAL.animationManager.addAnimation(newAnimation);
206214
duration = getAnimateDuration(animationName);
207215
WebGAL.animationManager.nextEnterAnimationName.set(key, animationName);
216+
217+
let exitAnimationObj = [...animationObj].reverse();
218+
exitAnimationObj[0].alpha = 1;
219+
const exitAnimationName = (Math.random() * 10).toString(16);
220+
WebGAL.animationManager.nextExitAnimationName.set(key + '-off', exitAnimationName);
208221
}
222+
209223
const enterAnim = getSentenceArgByKey(sentence, 'enter');
210224
const exitAnim = getSentenceArgByKey(sentence, 'exit');
211225
if (enterAnim) {
@@ -217,6 +231,7 @@ export function changeFigure(sentence: ISentence): IPerform {
217231
duration = getAnimateDuration(exitAnim.toString());
218232
}
219233
};
234+
220235
if (isFreeFigure) {
221236
/**
222237
* 下面的代码是设置自由立绘的

0 commit comments

Comments
 (0)