| 12 | type ValueListMap = {[prop:string]: Array<number>}; |
| 13 | |
| 14 | export class ITween { |
| 15 | private _target:any = null; |
| 16 | private _duration:number; |
| 17 | private _isPlaying:boolean = false; |
| 18 | private _currentTime:number = 0; |
| 19 | private _repeats:number = 0; |
| 20 | private _timeKeeper:Runtime.TimeKeeper; |
| 21 | private _timer:Runtime.Timer; |
| 22 | public easing:Function = Tween.linear; |
| 23 | public step:Function = () => {}; |
| 24 | |
| 25 | constructor(target:any, duration:number = 0) { |
| 26 | this._target = target; |
| 27 | this._duration = duration; |
| 28 | this._timeKeeper = new Runtime.TimeKeeper(); |
| 29 | this._timer = new Runtime.Timer(40); |
| 30 | |
| 31 | // Timer related |
| 32 | var self:ITween = this; |
| 33 | this._timer.addEventListener("timer", () => { |
| 34 | self._onTimerEvent(); |
| 35 | }); |
| 36 | } |
| 37 | |
| 38 | private _onTimerEvent():void { |
| 39 | // Ignore all the timer events if we're not playing |
| 40 | if (this._isPlaying) { |
| 41 | this._currentTime += this._timeKeeper.elapsed; |
| 42 | this._timeKeeper.reset(); |
| 43 | this.step(this._target, this._currentTime, this._duration); |
| 44 | if (this._currentTime >= this._duration) { |
| 45 | this._repeats--; |
| 46 | if (this._repeats < 0) { |
| 47 | this.stop(); |
| 48 | this._currentTime = this._duration; |
| 49 | } else { |
| 50 | this._currentTime = 0; |
| 51 | } |
| 52 | this.step(this._target, this._currentTime, this._duration); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | set duration(dur:number) { |
| 58 | this._duration = dur; |
| 59 | } |
| 60 | |
| 61 | get duration():number { |
| 62 | return this._duration; |
| 63 | } |
| 64 | |
| 65 | set position(position:number) { |
| 66 | this._currentTime = position; |
| 67 | } |
| 68 | |
| 69 | get position():number { |
| 70 | return this._currentTime; |
| 71 | } |
nothing calls this directly
no outgoing calls
no test coverage detected