<commit_before>/* globals __DEV__ */
import Phaser from 'phaser'
import SpaceShipFactory from "../sprites/SpaceShipFactory";
import {commands, DELIMETER, TARGET_DELIMETER} from "../commands";

export default class extends Phaser.State {
  init (websocket, roomId, players) {
      this.websocket = websocket;
      this.roomId = roomId;
      this.players = players;
  }

  preload () {
      // Log errors
      this.websocket.onerror = function (error) {
          console.log('WebSocket Error ' + error);
      };

      this.websocket.onmessage = function (message) {
          console.log("<<", message.data);
          this.parse(message.data)
      }.bind(this);
  }

    parse(message) {
        let mySplit = message.split(DELIMETER);
        if (mySplit.length == 3) {
            let cmd = mySplit[0];
            let target = mySplit[1];
            let payload = mySplit[2];
            if (cmd == 'message') {
                let playerId = target.split(TARGET_DELIMETER)[2];
                this.spaceShips.get(playerId).movement = payload;
            }
            if (cmd == commands.LEFTROLL){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.spaceShips.get(playerId).movement = cmd;
            }
            if (cmd == commands.RIGHTROLL){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.spaceShips.get(playerId).movement = cmd;
            }
            if (cmd == commands.THRUST){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.spaceShips.get(playerId).movement = cmd;
            }
            if (cmd == commands.NONE){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.spaceShips.get(playerId).movement = cmd;
            }
            if (cmd == commands.LOGOUT){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.removeSpaceShip(this.spaceShips, playerId);
            }

        }
    }

  create () {
    let offset = 100;
    this.factory = new SpaceShipFactory({game:this.game});
    this.spaceShips = new Map();

      for(let i = 0; i < this.players.length; i++) {
          this.spaceShips.set(this.players[i].id, this.factory.getSpaceShip(this.world.centerX + (offset * (i - 2)), this.world.centerY, 'spaceship'));
          this.spaceShips.get(this.players[i].id).scale.setTo(4,4);
      }
  }

  update () {
        for (let spaceShip of this.spaceShips.values()) {

          if (spaceShip.movement == 'thrust') {
              this.game.physics.arcade.accelerationFromRotation(spaceShip.rotation - Math.PI / 2, 800, spaceShip.body.acceleration);
          } else {
              spaceShip.body.acceleration.set(0);
          }<commit_msg>Scaling defined as variable in Game.js::create<commit_after>/* globals __DEV__ */
import Phaser from 'phaser'
import SpaceShipFactory from "../sprites/SpaceShipFactory";
import {commands, DELIMETER, TARGET_DELIMETER} from "../commands";

export default class extends Phaser.State {
  init (websocket, roomId, players) {
      this.websocket = websocket;
      this.roomId = roomId;
      this.players = players;
  }

  preload () {
      // Log errors
      this.websocket.onerror = function (error) {
          console.log('WebSocket Error ' + error);
      };

      this.websocket.onmessage = function (message) {
          console.log("<<", message.data);
          this.parse(message.data)
      }.bind(this);
  }

    parse(message) {
        let mySplit = message.split(DELIMETER);
        if (mySplit.length == 3) {
            let cmd = mySplit[0];
            let target = mySplit[1];
            let payload = mySplit[2];
            if (cmd == 'message') {
                let playerId = target.split(TARGET_DELIMETER)[2];
                this.spaceShips.get(playerId).movement = payload;
            }
            if (cmd == commands.LEFTROLL){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.spaceShips.get(playerId).movement = cmd;
            }
            if (cmd == commands.RIGHTROLL){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.spaceShips.get(playerId).movement = cmd;
            }
            if (cmd == commands.THRUST){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.spaceShips.get(playerId).movement = cmd;
            }
            if (cmd == commands.NONE){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.spaceShips.get(playerId).movement = cmd;
            }
            if (cmd == commands.LOGOUT){
              let playerId = target.split(TARGET_DELIMETER)[2];
              this.removeSpaceShip(this.spaceShips, playerId);
            }

        }
    }

  create () {
    let scalefact = 1
    let offset = 100;
    this.factory = new SpaceShipFactory({game:this.game});
    this.spaceShips = new Map();

      for(let i = 0; i < this.players.length; i++) {
          this.spaceShips.set(this.players[i].id, this.factory.getSpaceShip(this.world.centerX + (offset * (i - 2)), this.world.centerY, 'spaceship'));
          this.spaceShips.get(this.players[i].id).scale.setTo(scalefact,scalefact);
      }
  }

  update () {
        for (let spaceShip of this.spaceShips.values()) {

          if (spaceShip.movement == 'thrust') {
              this.game.physics.arcade.accelerationFromRotation(spaceShip.rotation - Math.PI / 2, 800, spaceShip.body.acceleration);
          } else {
              spaceShip.body.acceleration.set(0);
          }
{'fraction_non_alphanumeric': 0.12995871477293125, 'fraction_numerical': 0.007718542451983486, 'mean_word_length': 2.026615969581749, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '895404', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1701, 'n_words': 312}