Merge remote-tracking branch 'github.com/master' into webrtc
authorgparant <g.parant@thecodingmachine.com>
Fri, 1 May 2020 22:36:04 +0000 (00:36 +0200)
committergparant <g.parant@thecodingmachine.com>
Fri, 1 May 2020 22:36:04 +0000 (00:36 +0200)
# Conflicts:
# back/src/Model/Group.ts
# back/src/Model/World.ts

1  2 
back/src/Model/Group.ts
back/src/Model/World.ts
front/src/Phaser/Player/Player.ts

index 099e871b2c2bfe7b3c703148eff778075d3d8963,caf9b926d02e0c66a26c16e4179102e15f4937ba..39128c96f66704232de0831848252891e82ef6f6
@@@ -1,7 -1,6 +1,7 @@@
- import {MessageUserPosition} from "./Websocket/MessageUserPosition";
  import { World } from "./World";
  import { UserInterface } from "./UserInterface";
+ import {PositionInterface} from "_Model/PositionInterface";
 +import {uuid} from "uuidv4";
  
  export class Group {
      static readonly MAX_PER_GROUP = 4;
          return this.users;
      }
  
 +    getId() : string{
 +        return this.id;
 +    }
 +
+     /**
+      * Returns the barycenter of all users (i.e. the center of the group)
+      */
+     getPosition(): PositionInterface {
+         let x = 0;
+         let y = 0;
+         // Let's compute the barycenter of all users.
+         this.users.forEach((user: UserInterface) => {
+             x += user.position.x;
+             y += user.position.y;
+         });
+         x /= this.users.length;
+         y /= this.users.length;
+         return {
+             x,
+             y
+         };
+     }
      isFull(): boolean {
          return this.users.length >= Group.MAX_PER_GROUP;
      }
      join(user: UserInterface): void
      {
          // Broadcast on the right event
-         for(let i = 0; i < this.users.length; i++){
-             let groupUser : UserInterface = this.users[i];
+         this.users.forEach((groupUser: UserInterface) => {
 -            this.connectCallback(user.id, groupUser.id);
 +            this.connectCallback(user.id, groupUser.id, this);
-         }
+         });
          this.users.push(user);
          user.group = this;
      }
Simple merge
Simple merge