-
-
Notifications
You must be signed in to change notification settings - Fork 340
Expand file tree
/
Copy pathanimationFunctions.ts
More file actions
151 lines (142 loc) · 5.53 KB
/
animationFunctions.ts
File metadata and controls
151 lines (142 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { generateUniversalSoftInAnimationObj } from '@/Core/controller/stage/pixi/animations/universalSoftIn';
import { logger } from '@/Core/util/logger';
import { generateUniversalSoftOffAnimationObj } from '@/Core/controller/stage/pixi/animations/universalSoftOff';
import { webgalStore } from '@/store/store';
import cloneDeep from 'lodash/cloneDeep';
import { baseTransform } from '@/store/stageInterface';
import { generateTimelineObj } from '@/Core/controller/stage/pixi/animations/timeline';
import { WebGAL } from '@/Core/WebGAL';
import PixiStage, { IAnimationObject } from '@/Core/controller/stage/pixi/PixiController';
import {
DEFAULT_BG_IN_DURATION,
DEFAULT_BG_OUT_DURATION,
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) {
const effect = WebGAL.animationManager.getAnimations().find((ani) => ani.name === animationName);
if (effect) {
const mappedEffects = effect.effects.map((effect) => {
const targetSetEffect = webgalStore.getState().stage.effects.find((e) => e.target === target);
let newEffect;
if (!writeDefault && targetSetEffect && targetSetEffect.transform) {
newEffect = cloneDeep({ ...targetSetEffect.transform, duration: 0, ease: '' });
} else {
newEffect = cloneDeep({ ...baseTransform, duration: 0, ease: '' });
}
PixiStage.assignTransform(newEffect, effect, false);
newEffect.duration = effect.duration;
newEffect.ease = effect.ease;
return newEffect;
});
logger.debug('装载自定义动画', mappedEffects);
return generateTimelineObj(mappedEffects, target, duration);
}
return null;
}
export function getAnimateDuration(animationName: string) {
const effect = WebGAL.animationManager.getAnimations().find((ani) => ani.name === animationName);
if (effect) {
let duration = 0;
effect.effects.forEach((e) => {
duration += e.duration;
});
return duration;
}
return 0;
}
// eslint-disable-next-line max-params
export function getEnterExitAnimation(
target: string,
type: 'enter' | 'exit',
isBg = false,
realTarget?: string, // 用于立绘和背景移除时,以当前时间打上特殊标记
): {
duration: number;
animation: IAnimationObject | null;
} {
if (type === 'enter') {
let duration = DEFAULT_FIG_IN_DURATION;
if (isBg) {
duration = DEFAULT_BG_IN_DURATION;
}
duration =
webgalStore.getState().stage.animationSettings.find((setting) => setting.target === target)?.enterDuration ??
duration;
// 走默认动画
let animation: IAnimationObject | null = generateUniversalSoftInAnimationObj(realTarget ?? target, duration);
const transformState = webgalStore.getState().stage.effects;
const targetEffect = transformState.find((effect) => effect.target === target);
const animationName = webgalStore
.getState()
.stage.animationSettings.find((setting) => setting.target === target)?.enterAnimationName;
if (animationName && !targetEffect) {
logger.debug('取代默认进入动画', target);
animation = getAnimationObject(animationName, realTarget ?? target, getAnimateDuration(animationName), false);
duration = getAnimateDuration(animationName);
}
return { duration, animation };
} else {
// exit
let duration = DEFAULT_FIG_OUT_DURATION;
if (isBg) {
duration = DEFAULT_BG_OUT_DURATION;
}
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 === 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 };
}
}
// eslint-disable-next-line max-params
export function registerTimelineAnimation(
animationName: string,
animationKey: string,
target: string,
animationDuration: number,
writeDefault: boolean,
keep: boolean,
keepAnimationStopped: boolean,
) {
setTimeout(() => {
if (keep && keepAnimationStopped) {
return;
}
WebGAL.gameplay.pixiStage?.stopPresetAnimationOnTarget(target);
const animationObj: IAnimationObject | null = getAnimationObject(
animationName,
target,
animationDuration,
writeDefault,
);
if (animationObj) {
logger.debug(`动画${animationName}作用在${target}`, animationDuration);
WebGAL.gameplay.pixiStage?.registerAnimation(animationObj, animationKey, target);
}
}, 0);
}
export function removeTimelineAnimation(animationKey: string, keep: boolean): boolean {
if (keep) {
WebGAL.gameplay.pixiStage?.removeAnimationWithoutSetEndState(animationKey);
return true;
}
setTimeout(() => {
WebGAL.gameplay.pixiStage?.removeAnimationWithSetEffects(animationKey);
}, 0);
return false;
}