-
-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathsetAnimation.ts
More file actions
52 lines (45 loc) · 1.71 KB
/
setAnimation.ts
File metadata and controls
52 lines (45 loc) · 1.71 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
import { ISentence } from '@/Core/controller/scene/sceneInterface';
import { IPerform } from '@/Core/Modules/perform/performInterface';
import { getBooleanArgByKey, getStringArgByKey } from '@/Core/util/getSentenceArg';
import { logger } from '@/Core/util/logger';
import { webgalStore } from '@/store/store';
import {
getAnimateDuration,
registerTimelineAnimation,
removeTimelineAnimation,
} from '@/Core/Modules/animationFunctions';
import { WebGAL } from '@/Core/WebGAL';
/**
* 设置背景动画
* @param sentence
*/
export const setAnimation = (sentence: ISentence): IPerform => {
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 performInitName = `animation-${target}`;
WebGAL.gameplay.performController.unmountPerform(performInitName, true);
const animationKey = `${target}-${animationName}-${animationDuration}`;
let keepAnimationStopped = false;
setTimeout(() => {
if (keep && keepAnimationStopped) {
return;
}
registerTimelineAnimation(animationName, animationKey, target, animationDuration, writeDefault);
}, 0);
const stopFunction = () => {
keepAnimationStopped = removeTimelineAnimation(animationKey, keep);
};
return {
performName: performInitName,
duration: animationDuration,
isHoldOn: keep,
stopFunction,
blockingNext: () => false,
blockingAuto: () => !keep,
stopTimeout: undefined, // 暂时不用,后面会交给自动清除
};
};