-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy pathsetTempAnimation.ts
More file actions
74 lines (69 loc) · 2.84 KB
/
setTempAnimation.ts
File metadata and controls
74 lines (69 loc) · 2.84 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
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 { generateTimelineObj } from '@/Core/controller/stage/pixi/animations/timeline';
import cloneDeep from 'lodash/cloneDeep';
import { baseTransform } from '@/store/stageInterface';
import { IUserAnimation } from '../Modules/animations';
import { getAnimateDurationFromObj, getAnimationObject } from '@/Core/Modules/animationFunctions';
import { WebGAL } from '@/Core/WebGAL';
import { v4 as uuid } from 'uuid';
/**
* 设置临时动画
* @param sentence
*/
export const setTempAnimation = (sentence: ISentence): IPerform => {
const startDialogKey = webgalStore.getState().stage.currentDialogKey;
const animationName = uuid();
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 = getAnimateDurationFromObj(newAnimation);
const target = getStringArgByKey(sentence, 'target') ?? '0';
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,
};
};