(sentence: ISentence)
| 14 | * @param sentence |
| 15 | */ |
| 16 | export const setTransform = (sentence: ISentence): IPerform => { |
| 17 | const animationName = uuid(); |
| 18 | const animationString = sentence.content; |
| 19 | let animationObj: AnimationFrame[]; |
| 20 | |
| 21 | const duration = getNumberArgByKey(sentence, 'duration') ?? 500; |
| 22 | const ease = getStringArgByKey(sentence, 'ease') ?? ''; |
| 23 | const writeDefault = getBooleanArgByKey(sentence, 'writeDefault') ?? false; |
| 24 | const target = getStringArgByKey(sentence, 'target') ?? '0'; |
| 25 | const keep = getBooleanArgByKey(sentence, 'keep') ?? false; |
| 26 | const parallel = getBooleanArgByKey(sentence, 'parallel') ?? false; |
| 27 | const writeFullEffect = !parallel && !(getBooleanArgByKey(sentence, 'ignoreDefault') ?? false); |
| 28 | |
| 29 | const performInitName = `animation-${target}`; |
| 30 | const performName = parallel ? `${performInitName}#${animationName}` : performInitName; |
| 31 | |
| 32 | if (!parallel) WebGAL.gameplay.performController.unmountPerform(performInitName, true); |
| 33 | |
| 34 | try { |
| 35 | const frame = JSON.parse(animationString) as AnimationFrame; |
| 36 | animationObj = generateTransformAnimationObj(target, frame, duration, ease, writeFullEffect); |
| 37 | console.log('animationObj:', animationObj); |
| 38 | } catch (e) { |
| 39 | // 解析都错误了,歇逼吧 |
| 40 | animationObj = []; |
| 41 | } |
| 42 | |
| 43 | const newAnimation: IUserAnimation = { name: animationName, effects: animationObj }; |
| 44 | WebGAL.animationManager.addAnimation(newAnimation); |
| 45 | const animationDuration = getAnimateDuration(animationName); |
| 46 | const animationTimeline = applyAnimationEndState(animationName, target, writeDefault, writeFullEffect); |
| 47 | const key = `${target}-${animationName}-${animationDuration}`; |
| 48 | let keepAnimationStopped = false; |
| 49 | const startFunction = () => { |
| 50 | if (keep && keepAnimationStopped) { |
| 51 | return; |
| 52 | } |
| 53 | WebGAL.gameplay.pixiStage?.stopPresetAnimationOnTarget(target); |
| 54 | const animationObj: IAnimationObject | null = animationTimeline |
| 55 | ? generateTimelineObj(animationTimeline, target, animationDuration, false) |
| 56 | : null; |
| 57 | if (animationObj) { |
| 58 | logger.debug(`动画${animationName}作用在${target}`, animationDuration); |
| 59 | WebGAL.gameplay.pixiStage?.registerAnimation(animationObj, key, target); |
| 60 | } |
| 61 | }; |
| 62 | const stopFunction = () => { |
| 63 | if (keep) { |
| 64 | WebGAL.gameplay.pixiStage?.removeAnimationWithoutSetEndState(key); |
| 65 | keepAnimationStopped = true; |
| 66 | return; |
| 67 | } |
| 68 | WebGAL.gameplay.pixiStage?.removeAnimationWithSetEffects(key); |
| 69 | }; |
| 70 | |
| 71 | return { |
| 72 | performName: performName, |
| 73 | duration: animationDuration, |
nothing calls this directly
no test coverage detected