-
-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathsetAnimation.ts
More file actions
62 lines (56 loc) · 2.3 KB
/
setAnimation.ts
File metadata and controls
62 lines (56 loc) · 2.3 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
import { ISentence } from '@/Core/controller/scene/sceneInterface';
import { IPerform } from '@/Core/Modules/perform/performInterface';
import { getBooleanArgByKey, getStringArgByKey } from '@/Core/util/getSentenceArg';
import { IAnimationObject } from '@/Core/controller/stage/pixi/PixiController';
import { logger } from '@/Core/util/logger';
import { webgalStore } from '@/store/store';
import { getAnimateDuration, getAnimationObject } from '@/Core/Modules/animationFunctions';
import { WebGAL } from '@/Core/WebGAL';
/**
* 设置背景动画
* @param sentence
*/
export const setAnimation = (sentence: ISentence): IPerform => {
const startDialogKey = webgalStore.getState().stage.currentDialogKey;
const animationName = sentence.content;
const animationDuration = getAnimateDuration(animationName);
let target = getStringArgByKey(sentence, 'target') ?? '';
target = target !== '' ? target : 'default_id';
const writeDefault = getBooleanArgByKey(sentence, 'writeDefault') ?? false;
const keep = getBooleanArgByKey(sentence, 'keep') ?? false;
const parallel = getBooleanArgByKey(sentence, 'parallel') ?? false;
const key = `${target}-${animationName}-${animationDuration}`;
const performInitName = `animation-${target}`;
if (!parallel) WebGAL.gameplay.performController.unmountPerform(performInitName, true);
let stopFunction;
setTimeout(() => {
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, key, target);
}
}, 0);
stopFunction = () => {
setTimeout(() => {
const endDialogKey = webgalStore.getState().stage.currentDialogKey;
const isHasNext = startDialogKey !== endDialogKey;
WebGAL.gameplay.pixiStage?.removeAnimationWithSetEffects(key);
}, 0);
};
return {
performName: performInitName,
duration: animationDuration,
isHoldOn: keep,
stopFunction,
blockingNext: () => false,
blockingAuto: () => !keep,
stopTimeout: undefined, // 暂时不用,后面会交给自动清除
isParallel: parallel,
};
};