@@ -25,6 +25,9 @@ export const changeBg = (sentence: ISentence): IPerform => {
2525 const series = getStringArgByKey ( sentence , 'series' ) ?? 'default' ;
2626 const transformString = getStringArgByKey ( sentence , 'transform' ) ;
2727 let duration = getNumberArgByKey ( sentence , 'duration' ) ?? 1000 ;
28+ const enterDuration = getNumberArgByKey ( sentence , 'enterDuration' ) ?? duration ;
29+ duration = enterDuration ;
30+ const exitDuration = getNumberArgByKey ( sentence , 'exitDuration' ) ;
2831 const ease = getStringArgByKey ( sentence , 'ease' ) ?? '' ;
2932
3033 const dispatch = webgalStore . dispatch ;
@@ -42,21 +45,24 @@ export const changeBg = (sentence: ISentence): IPerform => {
4245 */
4346 if ( isUrlChanged ) {
4447 dispatch ( stageActions . removeEffectByTargetId ( `bg-main` ) ) ;
48+ dispatch ( stageActions . removeAnimationSettingsByTarget ( `bg-main` ) ) ;
4549 }
4650
4751 // 处理 transform 和 默认 transform
4852 let animationObj : AnimationFrame [ ] ;
4953 if ( transformString ) {
5054 try {
5155 const frame = JSON . parse ( transformString . toString ( ) ) as AnimationFrame ;
52- animationObj = generateTransformAnimationObj ( 'bg-main' , frame , duration , ease ) ;
56+ animationObj = generateTransformAnimationObj ( 'bg-main' , frame , enterDuration , ease ) ;
5357 // 因为是切换,必须把一开始的 alpha 改为 0
5458 animationObj [ 0 ] . alpha = 0 ;
5559 const animationName = ( Math . random ( ) * 10 ) . toString ( 16 ) ;
5660 const newAnimation : IUserAnimation = { name : animationName , effects : animationObj } ;
5761 WebGAL . animationManager . addAnimation ( newAnimation ) ;
5862 duration = getAnimateDuration ( animationName ) ;
59- WebGAL . animationManager . nextEnterAnimationName . set ( 'bg-main' , animationName ) ;
63+ webgalStore . dispatch (
64+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'enterAnimationName' , value : animationName } ) ,
65+ ) ;
6066 } catch ( e ) {
6167 // 解析都错误了,歇逼吧
6268 applyDefaultTransform ( ) ;
@@ -75,20 +81,36 @@ export const changeBg = (sentence: ISentence): IPerform => {
7581 const newAnimation : IUserAnimation = { name : animationName , effects : animationObj } ;
7682 WebGAL . animationManager . addAnimation ( newAnimation ) ;
7783 duration = getAnimateDuration ( animationName ) ;
78- WebGAL . animationManager . nextEnterAnimationName . set ( 'bg-main' , animationName ) ;
84+ webgalStore . dispatch (
85+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'enterAnimationName' , value : animationName } ) ,
86+ ) ;
7987 }
8088
8189 // 应用动画的优先级更高一点
8290 const enterAnimation = getStringArgByKey ( sentence , 'enter' ) ;
8391 const exitAnimation = getStringArgByKey ( sentence , 'exit' ) ;
8492 if ( enterAnimation ) {
85- WebGAL . animationManager . nextEnterAnimationName . set ( 'bg-main' , enterAnimation ) ;
93+ webgalStore . dispatch (
94+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'enterAnimationName' , value : enterAnimation } ) ,
95+ ) ;
8696 duration = getAnimateDuration ( enterAnimation ) ;
8797 }
8898 if ( exitAnimation ) {
89- WebGAL . animationManager . nextExitAnimationName . set ( 'bg-main-off' , exitAnimation ) ;
99+ webgalStore . dispatch (
100+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'exitAnimationName' , value : exitAnimation } ) ,
101+ ) ;
90102 duration = getAnimateDuration ( exitAnimation ) ;
91103 }
104+ if ( enterDuration ) {
105+ webgalStore . dispatch (
106+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'enterDuration' , value : enterDuration } ) ,
107+ ) ;
108+ }
109+ if ( exitDuration ) {
110+ webgalStore . dispatch (
111+ stageActions . updateAnimationSettings ( { target : 'bg-main' , key : 'exitDuration' , value : exitDuration } ) ,
112+ ) ;
113+ }
92114
93115 /**
94116 * 背景状态后处理
0 commit comments