Migrating position notification into the User class

This commit is contained in:
David Négrier 2020-09-25 15:25:06 +02:00
parent 892d1555b8
commit 23cea1c835
7 changed files with 59 additions and 52 deletions

View file

@ -57,8 +57,9 @@ export class Group implements Movable {
let y = 0;
// Let's compute the barycenter of all users.
this.users.forEach((user: User) => {
x += user.position.x;
y += user.position.y;
const position = user.getPosition();
x += position.x;
y += position.y;
});
x /= this.users.size;
y /= this.users.size;
@ -69,8 +70,7 @@ export class Group implements Movable {
this.y = y;
if (oldX === undefined) {
// TODO: do we need a "create"
this.positionNotifier.updatePosition(this, {x, y}, {x, y});
this.positionNotifier.enter(this);
} else {
this.positionNotifier.updatePosition(this, {x, y}, {x: oldX, y: oldY});
}