'use strict';
var Point = require('../prefabs/point');

function GameData(object) {
  this.startPoint = object.startPoint;
  this.endPoint = object.endPoint;
  this.points = object.points;
  this.wrongAnswers = 0;
  this.selectedAvatarKey = 'avatar_1';
}
GameData.prototype = {
  markPointAs: function(oldState, newState) {
    for (var i = 0; i < this.points.length; i++) {
      if (this.points[i].state === oldState) {
        this.points[i].state = newState;
        break;
      }
    }
  },
  getTaskForCurrentPoint: function() {
    for (var i = 0; i < this.points.length; i++) {
      if (this.points[i].state === Point.STATES.CURRENT) {
        var randomTaskIndex = Math.floor(Math.random() * this.points[i].tasks.length);
        console.log('Random index between 0 and ' + this.points[i].tasks.length + ' is ' + randomTaskIndex);
        return this.points[i].tasks[randomTaskIndex];
      }
    }
  },
  getBackgroundForCurrentPoint: function() {
    for (var i = 0; i < this.points.length; i++) {
      if (this.points[i].state === Point.STATES.CURRENT) {
        return this.points[i].image;
      }
    }
  },
  isEndReachable: function() {
    for (var i = 0; i < this.points.length; i++) {
      var unvisitedPointsExist = this.points[i].state === Point.STATES.UNVISITED || this.points[i].state === Point.STATES.NEXT;
      if (unvisitedPointsExist) {
        return false;
      }
    }
    return true;
  },
  saveToLocalStorage: function() {
    window.localStorage.setItem('lukuinto-2015', JSON.stringify(this));
  }
};

module.exports = GameData;

@@ -182,16 +182,215 @@
 points;%0A
+%0A  if (object.wrongAnswers !== undefined && object.selectedAvatarKey !== undefined) %7B%0A    this.wrongAnswers = object.wrongAnswers;%0A    this.selectedAvatarKey = object.selectedAvatarKey;%0A  %7D else %7B%0A  
   this.w
@@ -406,16 +406,18 @@
 rs = 0;%0A
+  
   this.s
@@ -447,16 +447,20 @@
 tar_1';%0A
+  %7D%0A
 %7D%0AGameDa

Load number of wrongs answers and used avatar information from local storage, if available.