<commit_before>Games = new Mongo.Collection("Games");

if (Meteor.isServer) {

  Meteor.startup(function() {

    return Meteor.methods({
      init: function() {
		//Games.remove({});
		Games.insert({Created: new Date(), Turn:{isPlayerOne: true, round:1}, Players:[], Gifs:[]})
      },

      changeTurn: function() {
        var turn = Games.findOne({},{sort:{Created:-1}}).Turn;
		var id = Games.findOne({},{sort:{Created:-1}})._id;
		Games.update(id, {$set:{"Turn.isPlayerOne": !turn.isPlayerOne}});
      },

      openVoting: function() {
		var game = Games.findOne({},{sort:{Created:-1}});
		var id = game._id;
		Games.update(id, {$set:{"Turn.isVotingOpen": true}});

        Meteor.setTimeout(function(){
          Games.update(id, {$set: {"Turn.isVotingOpen": false, "Turn.isPlayerOne": true, "Turn.round": game.Turn.round + 1}});

        },15000);
      },

      voteOne: function() {
        Games.findOne({},{sort:{Created:-1}}).Players.update(
            { number: 1 },
            { $inc: { votes: 1} }
        )
      },

      voteTwo: function() {
        Games.findOne({},{sort:{Created:-1}}).Players.update(
            { number: 2 },
            { $inc: { votes: 1} }
        )
      }
    });
  });
}

if (Meteor.isClient) {
  // This code only runs on the client
  Template.body.helpers({
    players: function () {
      return Games.findOne({},{sort:{Created:-1}}).Players;
    },
    currentGifs: function() {
		var game = Games.findOne({},{sort:{Created:-1}});
		if(game === undefined) return [];
      var currentRound = game.Turn.round;

		var gifs = [];
		for(i = 0; i < game.Gifs.length; i++){
			if(game.Gifs[i].round === game.Turn.round)
			{
				gifs.push(game.Gifs[i]);
			}
		}

      return gifs;
    },
	backgroundGifs: function() {
		var games = Games.find({},{sort:{Created:-1}});
		var gifs = [];
		games.forEach(function(game){
			if(game.Gifs !== undefined) {
				for(i = game.Gifs.length - 1; i > 0; i--){
					gifs.push(game.Gifs[i]);
				}
			}
		});
		return gifs;
	}
  });

  Template.body.events({<commit_msg>Added limits to background image loading<commit_after>Games = new Mongo.Collection("Games");

if (Meteor.isServer) {

  Meteor.startup(function() {

    return Meteor.methods({
      init: function() {
		//Games.remove({});
		Games.insert({Created: new Date(), Turn:{isPlayerOne: true, round:1}, Players:[], Gifs:[]})
      },

      changeTurn: function() {
        var turn = Games.findOne({},{sort:{Created:-1}}).Turn;
		var id = Games.findOne({},{sort:{Created:-1}})._id;
		Games.update(id, {$set:{"Turn.isPlayerOne": !turn.isPlayerOne}});
      },

      openVoting: function() {
		var game = Games.findOne({},{sort:{Created:-1}});
		var id = game._id;
		Games.update(id, {$set:{"Turn.isVotingOpen": true}});

        Meteor.setTimeout(function(){
          Games.update(id, {$set: {"Turn.isVotingOpen": false, "Turn.isPlayerOne": true, "Turn.round": game.Turn.round + 1}});

        },15000);
      },

      voteOne: function() {
        Games.findOne({},{sort:{Created:-1}}).Players.update(
            { number: 1 },
            { $inc: { votes: 1} }
        )
      },

      voteTwo: function() {
        Games.findOne({},{sort:{Created:-1}}).Players.update(
            { number: 2 },
            { $inc: { votes: 1} }
        )
      }
    });
  });
}

if (Meteor.isClient) {
  // This code only runs on the client
  Template.body.helpers({
    players: function () {
      return Games.findOne({},{sort:{Created:-1}}).Players;
    },
    currentGifs: function() {
		var game = Games.findOne({},{sort:{Created:-1}});
		if(game === undefined) return [];
      var currentRound = game.Turn.round;

		var gifs = [];
		for(i = 0; i < game.Gifs.length; i++){
			if(game.Gifs[i].round === game.Turn.round)
			{
				gifs.push(game.Gifs[i]);
			}
		}

      return gifs;
    },
	backgroundGifs: function() {
		var games = Games.find({},{sort:{Created:-1}, limit:10});
		var gifs = [];
		games.forEach(function(game){
			if(game.Gifs !== undefined) {
				for(i = game.Gifs.length - 1; i > 0; i--){
					gifs.push(game.Gifs[i]);
					
					if(gifs.length === 25){
						return gifs;
					}
				}
			}
		});
		return gifs;
	}
  });

  Template.body.events({
{'fraction_non_alphanumeric': 0.20781990521327015, 'fraction_numerical': 0.011374407582938388, 'mean_word_length': 2.5954003407155026, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 5, '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': '3041243', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1471, 'n_words': 259}