<commit_before>var _ = require('underscore');
var Popup = require('./popup');
var GobanUX = require('./goban-ux');
var socket = io.connect();

var Game = module.exports = function (id, goban) {
  _.bindAll(this, 'joinGameAsWhite', 'joinGameAsBlack', 'observeGame', 'putStone');

  var createPopup = new Popup('create');
  var joinPopup = new Popup('join');
  var blackChoice = document.querySelector('.popup.join .choice.black');
  var whiteChoice = document.querySelector('.popup.join .choice.white');
  var observerChoice = document.querySelector('.popup.join .choice.observer');

  this.id = id;
  this.goban = goban;
  this.gobanUX = new GobanUX(goban);

  socket.on('stone:put', this.putStone);
  this.gobanUX.on('stone:put', this.putStone);
  createPopup.hide(joinPopup.show);
  document.getElementById('game').appendChild(this.gobanUX.render().el);
  if (!!whiteChoice) whiteChoice.addEventListener('click', this.joinGameAsWhite);
  if (!!blackChoice) blackChoice.addEventListener('click', this.joinGameAsBlack);
  if (!!observerChoice) observerChoice.addEventListener('click', this.observeGame);
};

var game = Game.prototype;

game.joinGameAsWhite = function () {
  this.joinGame('white');
};

game.joinGameAsBlack = function () {
  this.joinGame('black');
};

game.joinGame = function (color) {
  var that = this;
  var joinPopup = new Popup('join');
  var opponent = (color === 'black' ? 'white' : 'black');

  this.color = color;
  oboe({method: 'POST', url: '/game/' + this.id + '/player', body: {color: color}}).done(function (data) {
    that.token = data.token;
    that.gobanUX.setColor(color);
    socket.emit('join', {id: that.id, token: data.token});
    socket.on('game:start', that.gobanUX.unlock);
    joinPopup.hide();
  });
};

game.observeGame = function () {
  var joinPopup = new Popup('join');
  socket.on('goban:reset', this.goban.reset);
  socket.emit('observe', {id: this.id});
  joinPopup.hide();
};

game.sendPutStone = function (evt) {
  var params = _.extend(evt, {
    color: this.color,
    token: this.token
  });

  oboe({method: 'POST', url: '/game/' + this.id + '/stone', body: params});
};

game.putStone = function (evt) {
  if (this.goban.putStone(evt.row, evt.col, evt.color) && evt.ux) {
    this.sendPutStone(_.omit(evt, 'ux'));
  }
};<commit_msg>close #12 : notify turn on title bar<commit_after>var _ = require('underscore');
var Popup = require('./popup');
var GobanUX = require('./goban-ux');
var notify = require('./notify');
var socket = io.connect();

var Game = module.exports = function (id, goban) {
  _.bindAll(this, 'joinGameAsWhite', 'joinGameAsBlack', 'observeGame', 'putStone');

  var createPopup = new Popup('create');
  var joinPopup = new Popup('join');
  var blackChoice = document.querySelector('.popup.join .choice.black');
  var whiteChoice = document.querySelector('.popup.join .choice.white');
  var observerChoice = document.querySelector('.popup.join .choice.observer');

  this.id = id;
  this.goban = goban;
  this.gobanUX = new GobanUX(goban);

  socket.on('stone:put', this.putStone);
  this.gobanUX.on('stone:put', this.putStone);
  createPopup.hide(joinPopup.show);
  document.getElementById('game').appendChild(this.gobanUX.render().el);
  if (!!whiteChoice) whiteChoice.addEventListener('click', this.joinGameAsWhite);
  if (!!blackChoice) blackChoice.addEventListener('click', this.joinGameAsBlack);
  if (!!observerChoice) observerChoice.addEventListener('click', this.observeGame);
};

var game = Game.prototype;

game.joinGameAsWhite = function () {
  this.joinGame('white');
};

game.joinGameAsBlack = function () {
  this.joinGame('black');
};

game.joinGame = function (color) {
  var that = this;
  var joinPopup = new Popup('join');
  var opponent = (color === 'black' ? 'white' : 'black');

  this.color = color;
  oboe({method: 'POST', url: '/game/' + this.id + '/player', body: {color: color}}).done(function (data) {
    that.token = data.token;
    that.gobanUX.setColor(color);
    socket.emit('join', {id: that.id, token: data.token});
    socket.on('game:start', that.gobanUX.unlock);
    socket.on('game:turn:' + color, function () {
      notify('Your turn');
    });
    joinPopup.hide();
  });
};

game.observeGame = function () {
  var joinPopup = new Popup('join');
  socket.on('goban:reset', this.goban.reset);
  socket.emit('observe', {id: this.id});
  joinPopup.hide();
};

game.sendPutStone = function (evt) {
  var params = _.extend(evt, {
    color: this.color,
    token: this.token
  });

  oboe({method: 'POST', url: '/game/' + this.id + '/stone', body: params});
};

game.putStone = function (evt) {
  if (this.goban.putStone(evt.row, evt.col, evt.color) && evt.ux) {
    this.sendPutStone(_.omit(evt, 'ux'));
  }
};
{'fraction_non_alphanumeric': 0.1878698224852071, 'fraction_numerical': 0.00042265426880811494, 'mean_word_length': 4.440229885057471, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7417003', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1626, 'n_words': 324}