| 582 | } |
| 583 | |
| 584 | export class Timeline implements ITickable { |
| 585 | private queue: IKeyFrame[] = []; |
| 586 | |
| 587 | public reset() { |
| 588 | this.queue.length = 0; |
| 589 | return this; |
| 590 | } |
| 591 | |
| 592 | public after(duration: number, callback?: IRenderCallback) { |
| 593 | this.tween(duration).tween(0, callback); |
| 594 | return this; |
| 595 | } |
| 596 | |
| 597 | public tween(duration: number, callback?: IAnimatedCallback) { |
| 598 | this.queue.push({ duration, callback }); |
| 599 | return this; |
| 600 | } |
| 601 | |
| 602 | public tick(elapsed: number) { |
| 603 | if (this.queue.length === 0) { |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | const anim = this.queue[0]; |
| 608 | const { duration, callback } = anim; |
| 609 | let { startTime } = anim; |
| 610 | |
| 611 | if (startTime == null) { |
| 612 | anim.startTime = startTime = elapsed; |
| 613 | } |
| 614 | |
| 615 | if (elapsed - startTime >= duration) { |
| 616 | if (callback != null) { |
| 617 | callback(1.0); |
| 618 | } |
| 619 | this.queue.shift(); |
| 620 | return this.queue.length > 0; |
| 621 | } else { |
| 622 | if (callback != null) { |
| 623 | callback((elapsed - startTime) / duration); |
| 624 | } |
| 625 | return true; |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | export class Ticker implements ITickable { |
| 631 | public constructor(private callback: IRenderCallback) {} |
nothing calls this directly
no outgoing calls
no test coverage detected