<commit_before>angular.module('mean.system')
  .factory('game', ['socket', '$timeout', function (socket, $timeout) {

  var game = {
    id: null,
    players: [],
    playerIndex: 0,
    winningCard: -1,
    winningCardPlayer: -1,
    gameWinner: -1,
    table: [],
    czar: null,
    playerMinLimit: 3,
    playerMaxLimit: 6,
    pointLimit: null,
    state: null,
    round: 0,
    curQuestion: null,
    notification: null,
    timeLimits: {}
  };

  var notificationQueue = [];
  var timeout = false;
  var self = this;

  var addToNotificationQueue = function(msg) {
    notificationQueue.push(msg);
    if (!timeout) { // Start a cycle if there isn't one
      setNotification();
    }
  };
  var setNotification = function() {
    if (notificationQueue.length === 0) { // If notificationQueue is empty, stop
      clearInterval(timeout);
      timeout = false;
      game.notification = '';
    } else {
      game.notification = notificationQueue.shift(); // Show a notification and check again in a bit
      timeout = $timeout(setNotification, 1300);
    }
  };

  socket.on('id', function(data) {
    game.id = data.id;
  });

  socket.on('prepareGame', function(data) {
    game.playerMinLimit = data.playerMinLimit;
    game.playerMaxLimit = data.playerMaxLimit;
    game.pointLimit = data.pointLimit;
    game.timeLimits = data.timeLimits;
  });

  socket.on('gameUpdate', function(data) {
    // console.log(data);

    // Cache the index of the player in the players array
    for (var i = 0; i < data.players.length; i++) {
      if (game.id === data.players[i].socketID) {
        game.playerIndex = i;
      }
    }

    // Set these properties on each update
    game.table = data.table;
    game.round = data.round;
    game.winningCard = data.winningCard;
    game.winningCardPlayer = data.winningCardPlayer;
    game.winnerAutopicked = data.winnerAutopicked;
    game.gameWinner = data.gameWinner;
    game.pointLimit = data.pointLimit;

    var newState = (data.state !== game.state);

    if (game.state !== 'waiting for players to pick') {
      game.players = data.players;
    }

    if (newState || game.curQuestion !== data.curQuestion) {
      game.state = data.state;
    }

    if (data.state === 'waiting for players to pick') {
      game.czar = data.czar;
      game.curQuestion = data.curQuestion;

      // Set notifications only when entering state
      if (newState) {
        if (game.czar === game.playerIndex) {
          addToNotificationQueue('You\'re the Card Czar! Players are choosing answers...');
        } else if (game.curQuestion.numAnswers === 1) {
          addToNotificationQueue('Select an answer!');
        } else {
          addToNotificationQueue('Select TWO answers!');
        }
      }<commit_msg>Add logic to only add cards to table that aren't already there (now only NEW cards animate onto the table)<commit_after>angular.module('mean.system')
  .factory('game', ['socket', '$timeout', function (socket, $timeout) {

  var game = {
    id: null,
    players: [],
    playerIndex: 0,
    winningCard: -1,
    winningCardPlayer: -1,
    gameWinner: -1,
    table: [],
    czar: null,
    playerMinLimit: 3,
    playerMaxLimit: 6,
    pointLimit: null,
    state: null,
    round: 0,
    curQuestion: null,
    notification: null,
    timeLimits: {}
  };

  var notificationQueue = [];
  var timeout = false;
  var self = this;

  var addToNotificationQueue = function(msg) {
    notificationQueue.push(msg);
    if (!timeout) { // Start a cycle if there isn't one
      setNotification();
    }
  };
  var setNotification = function() {
    if (notificationQueue.length === 0) { // If notificationQueue is empty, stop
      clearInterval(timeout);
      timeout = false;
      game.notification = '';
    } else {
      game.notification = notificationQueue.shift(); // Show a notification and check again in a bit
      timeout = $timeout(setNotification, 1300);
    }
  };

  socket.on('id', function(data) {
    game.id = data.id;
  });

  socket.on('prepareGame', function(data) {
    game.playerMinLimit = data.playerMinLimit;
    game.playerMaxLimit = data.playerMaxLimit;
    game.pointLimit = data.pointLimit;
    game.timeLimits = data.timeLimits;
  });

  socket.on('gameUpdate', function(data) {
    // console.log(data);

    var i;
    // Cache the index of the player in the players array
    for (i = 0; i < data.players.length; i++) {
      if (game.id === data.players[i].socketID) {
        game.playerIndex = i;
      }
    }

    // Set these properties on each update
    game.round = data.round;
    game.winningCard = data.winningCard;
    game.winningCardPlayer = data.winningCardPlayer;
    game.winnerAutopicked = data.winnerAutopicked;
    game.gameWinner = data.gameWinner;
    game.pointLimit = data.pointLimit;

    // Handle updating game.table
    if (data.table.length === 0) {
      game.table = [];
    } else {
      // All players represented in game.table
      var playersPicked = {};
      for (i = 0; i < game.table.length; i++) {
        playersPicked[game.table[i].player] = true;
      }
      // Only add new player's picks to game.table
      for (i = 0; i < data.table.length; i++) {
        if (!playersPicked[data.table[i].player]) {
          game.table.push(data.table[i]);
        }
      }
    }

    var newState = (data.state !== game.state);

    if (game.state !== 'waiting for players to pick') {
      game.players = data.players;
    }

    if (newState || game.curQuestion !== data.curQuestion) {
      game.state = data.state;
    }

    if (data.state === 'waiting for players to pick') {
      game.czar = data.czar;
      game.curQuestion = data.curQuestion;

      // Set notifications only when entering state
      if (newState) {
        if (game.czar === game.playerIndex) {
          addToNotificationQueue('You\'re the Card Czar! Players are choosing answers...');
        } else if (game.curQuestion.numAnswers === 1) {
          addToNotificationQueue('Select an answer!');
        } else {
          addToNotificationQueue('Select TWO answers!');
        }
      }
{'fraction_non_alphanumeric': 0.13181594891108564, 'fraction_numerical': 0.005076142131979695, 'mean_word_length': 2.5594405594405596, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1045254', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1844, 'n_words': 475}