@@ -13,6 +13,7 @@ import { AnimationFrame, IUserAnimation } from '@/Core/Modules/animations';
1313import cloneDeep from 'lodash/cloneDeep' ;
1414import { getAnimateDuration } from '@/Core/Modules/animationFunctions' ;
1515import { WebGAL } from '@/Core/WebGAL' ;
16+ import { DEFAULT_BG_OUT_DURATION } from '@/Core/constants' ;
1617
1718/**
1819 * 进行背景图片的切换
@@ -24,7 +25,10 @@ export const changeBg = (sentence: ISentence): IPerform => {
2425 const unlockName = getStringArgByKey ( sentence , 'unlockname' ) ?? '' ;
2526 const series = getStringArgByKey ( sentence , 'series' ) ?? 'default' ;
2627 const transformString = getStringArgByKey ( sentence , 'transform' ) ;
27- let duration = getNumberArgByKey ( sentence , 'duration' ) ?? 1000 ;
28+ let duration = getNumberArgByKey ( sentence , 'duration' ) ?? DEFAULT_BG_OUT_DURATION ;
29+ const enterDuration = getNumberArgByKey ( sentence , 'enterDuration' ) ?? duration ;
30+ duration = enterDuration ;
31+ const exitDuration = getNumberArgByKey ( sentence , 'exitDuration' ) ?? DEFAULT_BG_OUT_DURATION ;
2832 const ease = getStringArgByKey ( sentence , 'ease' ) ?? '' ;
2933
3034 const dispatch = webgalStore . dispatch ;
@@ -42,21 +46,24 @@ export const changeBg = (sentence: ISentence): IPerform => {
4246 */
4347 if ( isUrlChanged ) {
4448 dispatch ( stageActions . removeEffectByTargetId ( `bg-main` ) ) ;
49+ dispatch ( stageActions . removeAnimationSettingsByTarget ( `bg-main` ) ) ;
4550 }
4651
4752 // 处理 transform 和 默认 transform
4853 let animationObj : AnimationFrame [ ] ;
4954 if ( transformString ) {
5055 try {
5156 const frame = JSON . parse ( transformString . toString ( ) ) as AnimationFrame ;
52- animationObj = generateTransformAnimationObj ( 'bg-main' , frame , duration , ease ) ;
57+ animationObj = generateTransformAnimationObj ( 'bg-main' , frame , enterDuration , ease ) ;
5358 // 因为是切换,必须把一开始的 alpha 改为 0
5459 animationObj [ 0 ] . alpha = 0 ;
5560 const animationName = ( Math . random ( ) * 10 ) . toString ( 16 ) ;
5661 const newAnimation : IUserAnimation = { name : animationName , effects : animationObj } ;
5762 WebGAL . animationManager . addAnimation ( newAnimation ) ;
5863 duration = getAnimateDuration ( animationName ) ;
59- WebGAL . animationManager . nextEnterAnimationName . set ( 'bg-main' , animationName ) ;
64+ webgalStore . dispatch (
65+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'enterAnimationName' , value : animationName } ) ,
66+ ) ;
6067 } catch ( e ) {
6168 // 解析都错误了,歇逼吧
6269 applyDefaultTransform ( ) ;
@@ -75,20 +82,36 @@ export const changeBg = (sentence: ISentence): IPerform => {
7582 const newAnimation : IUserAnimation = { name : animationName , effects : animationObj } ;
7683 WebGAL . animationManager . addAnimation ( newAnimation ) ;
7784 duration = getAnimateDuration ( animationName ) ;
78- WebGAL . animationManager . nextEnterAnimationName . set ( 'bg-main' , animationName ) ;
85+ webgalStore . dispatch (
86+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'enterAnimationName' , value : animationName } ) ,
87+ ) ;
7988 }
8089
8190 // 应用动画的优先级更高一点
8291 const enterAnimation = getStringArgByKey ( sentence , 'enter' ) ;
8392 const exitAnimation = getStringArgByKey ( sentence , 'exit' ) ;
8493 if ( enterAnimation ) {
85- WebGAL . animationManager . nextEnterAnimationName . set ( 'bg-main' , enterAnimation ) ;
94+ webgalStore . dispatch (
95+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'enterAnimationName' , value : enterAnimation } ) ,
96+ ) ;
8697 duration = getAnimateDuration ( enterAnimation ) ;
8798 }
8899 if ( exitAnimation ) {
89- WebGAL . animationManager . nextExitAnimationName . set ( 'bg-main-off' , exitAnimation ) ;
100+ webgalStore . dispatch (
101+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'exitAnimationName' , value : exitAnimation } ) ,
102+ ) ;
90103 duration = getAnimateDuration ( exitAnimation ) ;
91104 }
105+ if ( enterDuration >= 0 ) {
106+ webgalStore . dispatch (
107+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'enterDuration' , value : enterDuration } ) ,
108+ ) ;
109+ }
110+ if ( exitDuration >= 0 ) {
111+ webgalStore . dispatch (
112+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'exitDuration' , value : exitDuration } ) ,
113+ ) ;
114+ }
92115
93116 /**
94117 * 背景状态后处理
0 commit comments