Skip to content

Commit

Permalink
fix(animations): implement getPosition in browser animation builder
Browse files Browse the repository at this point in the history
  • Loading branch information
literalpie committed Jan 20, 2019
1 parent 73dcd72 commit 93b7b76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions packages/animations/src/players/animation_group_player.ts
Expand Up @@ -132,12 +132,15 @@ export class AnimationGroupPlayer implements AnimationPlayer {
}

getPosition(): number {
let min = 0;
this.players.forEach(player => {
const p = player.getPosition();
min = Math.min(p, min);
});
return min;
const longestPlayer = this.players.reduce((longestSoFar, player) => {
const newPlayerIsLongest = player.totalTime > (longestSoFar! as AnimationPlayer).totalTime;
if (longestSoFar === undefined || newPlayerIsLongest) {
return player;
} else {
return longestSoFar;
}
}, undefined);
return longestPlayer !== undefined ? longestPlayer.getPosition() / longestPlayer.totalTime : 0;
}

beforeDestroy(): void {
Expand Down
Expand Up @@ -89,7 +89,7 @@ export class RendererAnimationPlayer implements AnimationPlayer {

setPosition(p: number): void { this._command('setPosition', p); }

getPosition(): number { return 0; }
getPosition(): number { return this._renderer.engine.players[+this.id].getPosition(); }

public totalTime = 0;
}
Expand Down

0 comments on commit 93b7b76

Please sign in to comment.