import { Component } from "../core/Component" ; import { Tween } from "../tween/Tween" ; import { TweenManager } from "../tween/TweenManager" ; import { ActionData } from "./Action" ; import { Easing } from "../tween/Easing" ; export class ActionParse { component : Component ; constructor ( component ) { this . component = component ; } param fun paresFunction ( fun ) { let animationData = fun ( ) ; if ( ! ( animationData instanceof ActionData ) ) { throw new Error ( "当前动画解析错误，传入的Function返回值不是ActionData!" ) ; } return animationData ; } param animationData paresTween ( animationData ) { let tween = TweenManager . builder ( this . component ) ; tween . setExpire ( true ) ; tween . time ( animationData . time ) ; tween . easing ( animationData . easingProperty || Easing . linear ( ) ) ; this . paresAmin ( animationData ) ; this . bindAmin ( animationData , tween ) ; return tween ; } param animationData private paresAmin ( animationData ) { switch ( animationData . type ) { case ActionData . fadeTo : this . paresFadeTo ( animationData ) ; break ; case ActionData . fadeIn : this . paresFadeIn ( animationData ) ; break ; case ActionData . fadeOut : this . paresFadeOut ( animationData ) ; break ; case ActionData . moveTo : this . paresMoveTo ( animationData ) ; break ; case ActionData . moveBy : this . paresMoveBy ( animationData ) ; break ; case ActionData . scaleTo : this . paresScaleTo ( animationData ) ; break ; case ActionData . scaleBy : this . paresScaleBy ( animationData ) ; break ; case ActionData . rotateTo : this . paresRotateTo ( animationData ) ; break ; case ActionData . rotateBy : this . paresRotateBy ( animationData ) ; break ; case ActionData . skewTo : this . paresSkewTo ( animationData ) ; break ; case ActionData . skewBy : this . paresSkewBy ( animationData ) ; break ; } } param animationData param tween private bindAmin ( animationData , tween ) { switch ( animationData . type ) { case ActionData . fadeTo : case ActionData . fadeIn : case ActionData . fadeOut : tween . to ( { opacity : animationData . opacity , } ) ; break ; case ActionData . moveTo : case ActionData . moveBy : tween . to ( { x : animationData . x , y : animationData . y , } ) ; break ; case ActionData . scaleTo : case ActionData . scaleBy : tween . to ( { scale : { x : animationData . scaleX , y : animationData . scaleY , } , } ) ; break ; case ActionData . rotateTo : case ActionData . rotateBy : tween . to ( { rotate : animationData . rotation , } ) ; break ; case ActionData . skewTo : case ActionData . skewBy : tween . to ( { skew : { x : animationData . skewX , y : animationData . skewY , } , } ) ; break ; case ActionData . callFunc : if ( animationData . callback != undefined ) { tween . on ( "end" , < any > animationData . callback ) ; } break ; } } param animationData private paresFadeTo ( animationData ) { if ( isNaN ( animationData . opacity ) ) { animationData . opacity = this . component . opacity ; } } param animationData private paresFadeIn ( animationData ) { this . paresFadeTo ( animationData ) ; } param animationData private paresFadeOut ( animationData ) { this . paresFadeTo ( animationData ) ; } param animationData private paresMoveTo ( animationData ) { if ( isNaN ( animationData . x ) ) { animationData . x = this . component . x ; } if ( isNaN ( animationData . y ) ) { animationData . y = this . component . y ; } } param animationData private paresMoveBy ( animationData ) { if ( isNaN ( animationData . x ) ) { animationData . x = this . component . x ; } else { animationData . x += this . component . x ; } if ( isNaN ( animationData . y ) ) { animationData . y = this . component . y ; } else { animationData . y += this . component . y ; } } param animationData private paresScaleTo ( animationData ) { if ( isNaN ( animationData . scaleX ) ) { animationData . scaleX = this . component . scale . x ; } if ( isNaN ( animationData . scaleY ) ) { animationData . scaleY = this . component . scale . y ; } } param animationData private paresScaleBy ( animationData ) { if ( isNaN ( animationData . scaleX ) ) { animationData . scaleX = this . component . scale . x ; } else { animationData . scaleX += this . component . scale . x ; } if ( isNaN ( animationData . scaleY ) ) { animationData . scaleY = this . component . scale . y ; } else { animationData . scaleY += this . component . scale . y ; } } param animationData private paresRotateTo ( animationData ) { if ( isNaN ( animationData . rotation ) ) { animationData . rotation = this . component . rotate ; } } param animationData private paresRotateBy ( animationData ) { if ( isNaN ( animationData . rotation ) ) { animationData . rotation = this . component . rotate ; } else { animationData . rotation += this . component . rotate ; } } param animationData private paresSkewTo ( animationData ) { if ( isNaN ( animationData . skewX ) ) { animationData . skewX = this . component . skew . x ; } if ( isNaN ( animationData . skewY ) ) { animationData . skewY = this . component . skew . y ; } } param animationData private paresSkewBy ( animationData ) { if ( isNaN ( animationData . skewX ) ) { animationData . skewX = this . component . skew . x ; } else { animationData . skewX += this . component . skew . x ; } if ( isNaN ( animationData . skewY ) ) { animationData . skewY = this . component . skew . y ; } else { animationData . skewY += this . component . skew . y ; } } }