import { Animation } from "./animation" ; import { ANIME , EASE_TYPE } from "../cubicons/constants" ; import { xGtoW , yGtoW } from "../math/convertUnit" ; import { Vector2 } from "../math/vector" ; import { Geometry } from "../cubicons/geometry" ; /**
 * Translate a geometric cubicon by a specified vector.
 */ export class Translate extends Animation { vector : Vector2 ; constructor ( params ) { super ( { cubicon : params . cubicon , duration : params . duration ?? ANIME . TRANSLATE , ease : params . ease , } ) ; this . vector = params . vector ; } play ( sleepTime ) { this . translateByVector ( this . cubicon , this . vector , sleepTime ) ; } private translateByVector ( cubicon , vector , sleepTime ) { cubicon . moveVector = cubicon . moveVector . add ( vector ) ; cubicon . g_cubiconWrapper . transition ( ) . ease ( this . ease ) . delay ( cubicon . elapsedTime + sleepTime ) . duration ( this . duration ) . attr ( "transform" , `translate(${ xGtoW ( cubicon . moveVector . x ) }, ${ yGtoW ( cubicon . moveVector . y ) }) rotate(${ cubicon . moveAngle })` ) . on ( "end" , ( ) => { cubicon . position = cubicon . position . add ( vector ) ; } ) ; cubicon . elapsedTime += this . duration + sleepTime ; } }