-
-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathsetTempAnimation.ts
More file actions
63 lines (57 loc) · 2.22 KB
/
setTempAnimation.ts
File metadata and controls
63 lines (57 loc) · 2.22 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
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 { generateTimelineObj } from '@/Core/controller/stage/pixi/animations/timeline';
import cloneDeep from 'lodash/cloneDeep';
import { baseTransform } from '@/store/stageInterface';
import { IUserAnimation } from '../Modules/animations';
import {
getAnimateDuration,
registerTimelineAnimation,
removeTimelineAnimation,
} from '@/Core/Modules/animationFunctions';
import { WebGAL } from '@/Core/WebGAL';
/**
* 设置临时动画
* @param sentence
*/
export const setTempAnimation = (sentence: ISentence): IPerform => {
const animationName = (Math.random() * 10).toString(16);
const animationString = sentence.content;
let animationObj;
try {
animationObj = JSON.parse(animationString);
} catch (e) {
animationObj = [];
}
const newAnimation: IUserAnimation = { name: animationName, effects: animationObj };
WebGAL.animationManager.addAnimation(newAnimation);
const animationDuration = getAnimateDuration(animationName);
const target = getStringArgByKey(sentence, 'target') ?? '0';
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, // 暂时不用,后面会交给自动清除
};
};