<commit_before>/*global define*/

define([
  'app',
  'jquery',
  'backbone',
  'views/game/main',
  'views/game/dice',
  'views/game/next-player',
  'views/game/test-game',
  'views/game/sraz',
  'collections/boards',
  'logic/game'
], function(
  app,
  $,
  Backbone,
  GameView,
  DiceView,
  NextPlayerView,
  TestGameView,
  SrazView,
  BoardCollection,
  GameLogic
) {
  'use strict';

  var GameRouter = Backbone.Router.extend({
    routes: {
      'game': 'index',
      'game/test/:name': 'test'
    },

    diceResult: null,
    game: null,
    currentPlayer: null,
    gameView: null,

    index: function() {
      var board = app.currentGame.board;
      this.game = GameLogic.create({
        board: board.toJSON()
      });
      this.gameView = new GameView({
        game: this.game,
        board: board
      });
      this.gameView.on('pawn:eat', this.goSraz, this);
      this.gameView.on('dice:throw', this.move, this);

      var players = [];
      for (var i = 0; i < app.currentGame.players.length; i++) {
        var name = app.currentGame.players[i];
        players.push({
          id: i,
          name: name,
          color: board.get('colors')[i].player
        });
      }
      app.currentGame.players = players;

      this.gameView.render();
      app.switchView(this.gameView);

      this.game.start();
    },

    move: function() {
      var newPlayer = this.game.getCurrentPlayerId();
      if (newPlayer !== this.currentPlayer) {
        this.currentPlayer = newPlayer;
        this.gameView.setPlayer(this.currentPlayer);
        this.nextPlayer(this.currentPlayer);
      } else {
        this.dice(this.currentPlayer);
      }
    },

    dice: function() {
      var me = this;
      var view = new DiceView({
        // TODO: promjeniti ovo za network game
        local: true,
        game: this.game
      });
      view.on('dice:result', function(result) {
        me.diceResult = result;
      });
      view.on('animation:end', function() {
        $('.overlay').hide();
        view.remove();
      });
      view.render();
      $('.overlay').html(view.el).show();
    },
<commit_msg>dice event fix<commit_after>/*global define*/

define([
  'app',
  'jquery',
  'backbone',
  'views/game/main',
  'views/game/dice',
  'views/game/next-player',
  'views/game/test-game',
  'views/game/sraz',
  'collections/boards',
  'logic/game'
], function(
  app,
  $,
  Backbone,
  GameView,
  DiceView,
  NextPlayerView,
  TestGameView,
  SrazView,
  BoardCollection,
  GameLogic
) {
  'use strict';

  var GameRouter = Backbone.Router.extend({
    routes: {
      'game': 'index',
      'game/test/:name': 'test'
    },

    diceResult: null,
    game: null,
    currentPlayer: null,
    gameView: null,
    diceEvents: true,

    index: function() {
      var board = app.currentGame.board;
      this.game = GameLogic.create({
        board: board.toJSON()
      });
      this.gameView = new GameView({
        game: this.game,
        board: board
      });
      this.gameView.on('pawn:eat', this.goSraz, this);
      this.gameView.on('dice:throw', this.move, this);

      var players = [];
      for (var i = 0; i < app.currentGame.players.length; i++) {
        var name = app.currentGame.players[i];
        players.push({
          id: i,
          name: name,
          color: board.get('colors')[i].player
        });
      }
      app.currentGame.players = players;

      this.gameView.render();
      app.switchView(this.gameView);

      this.game.start();
    },

    move: function() {
      var newPlayer = this.game.getCurrentPlayerId();
      if (newPlayer !== this.currentPlayer) {
        this.currentPlayer = newPlayer;
        this.gameView.setPlayer(this.currentPlayer);
        this.nextPlayer(this.currentPlayer);
      } else {
        this.dice(this.currentPlayer);
      }
    },

    dice: function() {
      if (!this.diceEvents) {
        return;
      }
      this.diceEvents = false;
      var me = this;
      var view = new DiceView({
        // TODO: promjeniti ovo za network game
        local: true,
        game: this.game
      });
      view.on('dice:result', function(result) {
        me.diceResult = result;
      });
      view.on('animation:end', function() {
        $('.overlay').hide();
        view.remove();
        me.diceEvents = true;
      });
      view.render();
      $('.overlay').html(view.el).show();
    },

{'fraction_non_alphanumeric': 0.15633484162895928, 'fraction_numerical': 0.00045248868778280545, 'mean_word_length': 2.119971771347918, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1521616', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1459, 'n_words': 271}