<commit_before>/*
 * Join.js
 * A scene where the user is waiting for others to join.
 */
'use strict';

var Utils     = require('core/Utils');
var HeaderBar = require('components/HeaderBar');

var COUNTDOWN_INTERVAL = 1000;  // ms

function setCountdownStep(step) {
  this.gameState.globals.countdownStep = step;
  this.gameState.syncCity();
}

module.exports = function (gameState, stage) {
  this.gameState = gameState;

  this.container = new PIXI.DisplayObjectContainer();
  this.container.visible = false;
  stage.addChild(this.container);

  this.headerBar = new HeaderBar(0, 0, 768, 105);
  this.container.addChild(this.headerBar.drawable);

  this.headerBar.onclick = function() {
    // TODO: and what to do if there is no current city?
    if (this.gameState.currentCity && this.gameState.globals) {
      this.gameState.currentCity.ready = true;
      Utils.vibrate(this.gameState.TAP_VIBRATION);
      this.gameState.syncCity();
    }
  }.bind(this);
};

// Renders the scene
module.exports.prototype.render = function () {

  if ( ! this.gameState.hasUpdated) {
    return;
  }

  var gameState = this.gameState;
  var globals   = this.gameState.globals;
  var ready = 0;
  var total = this.gameState.countCities();
  var i;

  // Host decides when we're ready to start playing
  if (this.gameState.host) {
    // TODO make this a method?
    for (i = 0; i < this.gameState.MAX_CITIES; i++) {
      if (gameState.sync[i] && gameState.sync[i].ready) {
        ready++;
      }
    }

    if (ready >= total && total >= 2) {
      // start the countdown and then play
      if ( ! (this.gameState.globals.countdownStep || this.gameState.globals.playing) ) {
        setCountdownStep.call(this, 'ready');
        window.setTimeout(setCountdownStep.bind(this, 'set'),     COUNTDOWN_INTERVAL);
        window.setTimeout(setCountdownStep.bind(this, 'go'),  2 * COUNTDOWN_INTERVAL);
        window.setTimeout(function() {
          this.gameState.countdownStep = false;
          this.gameState.globals.playing = true;
          this.gameState.globals.status = null;
          this.gameState.globals.startTime = Date.now();
          this.gameState.syncCity();
        }.bind(this), 3 * COUNTDOWN_INTERVAL);
      }
    }
  }

  // Stop and go to 'play' scene if the host has set playing=true
  if (globals && globals.playing && gameState.currentCity && gameState.currentCity.ready) {
    gameState.startTime = Date.now() - globals.elapsed;
    return 'play';
  }

  // show connecting message?
  if (this.gameState.cityId == null || this.gameState.globals == null) {
    this.headerBar.show('connecting');
    return;
  }

  // show ready, set, or go?
  if ( gameState.currentCity.ready ) {
    this.headerBar.show(globals.countdownStep || 'ready', {
      leftMessage: { text: "Level " + (this.gameState.globals.level + 1) },
      rightMessage: { text:  total + " player" + (total === 1 ? "" : "s") }
    });
    return;
  }

  // show won/lost message?
  if (globals && globals.status != null ) {
    // can't test truthiness; status === true means won, status === 1 means city 2 blacked out...
    if (globals.status === true) {
      this.headerBar.show('won');
    } else {
      this.headerBar.show('lost', {
        centerMessage: { text: "City " + (status+1) + " blacked out!" }
      });
    }
    return;<commit_msg>Lint/whitespace fixes<commit_after>/*
 * Join.js
 * A scene where the user is waiting for others to join.
 */
'use strict';

var Utils     = require('core/Utils');
var HeaderBar = require('components/HeaderBar');

var COUNTDOWN_INTERVAL = 1000;  // ms

function setCountdownStep(step) {
  // jshint -W040
  this.gameState.globals.countdownStep = step;
  this.gameState.syncCity();
  // jshint +W040
}

module.exports = function (gameState, stage) {
  this.gameState = gameState;

  this.container = new PIXI.DisplayObjectContainer();
  this.container.visible = false;
  stage.addChild(this.container);

  this.headerBar = new HeaderBar(0, 0, 768, 105);
  this.container.addChild(this.headerBar.drawable);

  this.headerBar.onclick = function() {
    // TODO: and what to do if there is no current city?
    if (this.gameState.currentCity && this.gameState.globals) {
      this.gameState.currentCity.ready = true;
      Utils.vibrate(this.gameState.TAP_VIBRATION);
      this.gameState.syncCity();
    }
  }.bind(this);
};

// Renders the scene
module.exports.prototype.render = function () {

  if ( ! this.gameState.hasUpdated) {
    return;
  }

  var gameState = this.gameState;
  var globals   = this.gameState.globals;
  var ready = 0;
  var total = this.gameState.countCities();
  var i;

  // Host decides when we're ready to start playing
  if (this.gameState.host) {
    // TODO make this a method?
    for (i = 0; i < this.gameState.MAX_CITIES; i++) {
      if (gameState.sync[i] && gameState.sync[i].ready) {
        ready++;
      }
    }

    if (ready >= total && total >= 2) {
      // start the countdown and then play
      if ( ! (this.gameState.globals.countdownStep || this.gameState.globals.playing) ) {
        setCountdownStep.call(this, 'ready');
        window.setTimeout(setCountdownStep.bind(this, 'set'),     COUNTDOWN_INTERVAL);
        window.setTimeout(setCountdownStep.bind(this, 'go'),  2 * COUNTDOWN_INTERVAL);
        window.setTimeout(function() {
          this.gameState.countdownStep = false;
          this.gameState.globals.playing = true;
          this.gameState.globals.status = null;
          this.gameState.globals.startTime = Date.now();
          this.gameState.syncCity();
        }.bind(this), 3 * COUNTDOWN_INTERVAL);
      }
    }
  }

  // Stop and go to 'play' scene if the host has set playing=true
  if (globals && globals.playing && gameState.currentCity && gameState.currentCity.ready) {
    gameState.startTime = Date.now() - globals.elapsed;
    return 'play';
  }

  // show connecting message?
  if (this.gameState.cityId == null || this.gameState.globals == null) {
    this.headerBar.show('connecting');
    return;
  }

  // show ready, set, or go?
  if (gameState.currentCity.ready) {
    this.headerBar.show(globals.countdownStep || 'ready', {
      leftMessage: { text: "Level " + (this.gameState.globals.level + 1) },
      rightMessage: { text:  total + " player" + (total === 1 ? "" : "s") }
    });
    return;
  }

  // show won/lost message?
  if (globals && globals.status != null) {
    // can't test truthiness; status === true means won, status === 1 means city 2 blacked out...
    if (globals.status === true) {
      this.headerBar.show('won');
    } else {
      this.headerBar.show('lost', {
        centerMessage: { text: "City " + (status+1) + " blacked out!" }
      });
    }
    return;
{'fraction_non_alphanumeric': 0.14379377142005662, 'fraction_numerical': 0.007450454477723141, 'mean_word_length': 2.8596894767107535, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2595597', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2167, 'n_words': 486}