Skip to content

Commit

Permalink
Fixed bug with save and load functions
Browse files Browse the repository at this point in the history
  • Loading branch information
angarg12 committed Feb 14, 2015
1 parent 81df4d2 commit 083532d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ <h2>Time: {{getSprintTime()}}</h2>
<h2>{{player.sprintTimes}}</h2>
<h2>Goal<sup ng-if="currentPrestige > 0">{{currentPrestige}}</sup>: <span ng-bind-html="trustedPrettifyNumber(prestigeGoal[currentPrestige])"/></h2>
<div class="progress-striped" style="margin-bottom:0;width:80%;">
<div ng-if="!player.sprintFinished">
<div ng-if="!sprintFinished">
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="0" style="width:{{player.currency.div(prestigeGoal[currentPrestige])*100}}%" ng-if="!logscale">
{{Math.max(Math.floor((player.currency.div(prestigeGoal[currentPrestige]))*1000)/10,0)}}%
</div>
<div class="progress-bar-log" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="0" style="width:{{player.currency.ln().div(prestigeGoal[currentPrestige].ln())*100}}%" ng-if="logscale">
{{Math.max(Math.floor((player.currency.ln().div(prestigeGoal[currentPrestige].ln()))*1000)/10,0)}}%
</div>
</div>
<div ng-if="player.sprintFinished">
<div ng-if="sprintFinished">
<div class="progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="0" style="width:100%">
100%
</div>
Expand All @@ -54,7 +54,7 @@ <h3 ng-if="clickUpgradePower.length > 0">Click power upgrades</h3>
<div id="options">
<h2>Options</h2>
<table id="optionTable">
<tr ng-if="player.sprintFinished && prestigeGoal.length > player.maxPrestige+1">
<tr ng-if="sprintFinished && prestigeGoal.length > player.maxPrestige+1">
<td>
<button id="prestige" ng-click="prestige()">Prestige</button>
</td>
Expand Down
35 changes: 23 additions & 12 deletions js/exponential.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ angular.module('incremental',[])
$scope.version = '0.8.2';
$scope.Math = window.Math;

var startPlayer = {
const startPlayer = {
cashPerClick: new Decimal(1),
multiplier: new Decimal(10),
multiplierUpgradeLevel: [],
Expand All @@ -13,14 +13,22 @@ angular.module('incremental',[])
currency: new Decimal(0),
maxPrestige: 0,
version: $scope.version,
sprintFinished: false,
sprintTimes: [],
preferences: {logscale: $scope.logscale}
};

// Procedurally generated
var multiplierUpgradeBasePrice = [];
$scope.multiplierUpgradePower = [];
$scope.clickUpgradePower = [];

// Variables
$scope.sprintFinished = false;
$scope.currentPrestige = 0;
var timer;
var timerSeconds = 0;

// Constants
$scope.prestigeGoal = [new Decimal("1e4"),
new Decimal("1e6"),
new Decimal("1e16"),
Expand All @@ -33,9 +41,6 @@ angular.module('incremental',[])
new Decimal("1e50000"),
new Decimal("1e100000"),
new Decimal("1e9000000000000000")];
$scope.currentPrestige = 0;
var timer;
var timerSeconds = 0;

$scope.trustedPrettifyNumber = function(value) {
return $sce.trustAsHtml(prettifyNumber(value));
Expand Down Expand Up @@ -71,13 +76,18 @@ angular.module('incremental',[])
$scope.save = function save() {
localStorage.setItem("playerStored", JSON.stringify($scope.player));
localStorage.setItem("timerSeconds", timerSeconds);
localStorage.setItem("sprintFinished", $scope.sprintFinished);
localStorage.setItem("currentPrestige", $scope.currentPrestige);
var d = new Date();
$scope.lastSave = d.toLocaleTimeString();
}

$scope.load = function load() {
$scope.player = JSON.parse(localStorage.getItem("playerStored"));
seconds = localStorage.getItem("timerSeconds");
seconds = parseInt(localStorage.getItem("timerSeconds"));
// Have to do this, otherwise is read as string
$scope.sprintFinished = localStorage.getItem("sprintFinished") === "true";
$scope.currentPrestige = parseInt(localStorage.getItem("currentPrestige"));

timerSet(seconds);
$scope.player.currency = new Decimal($scope.player.currency);
Expand Down Expand Up @@ -255,9 +265,9 @@ angular.module('incremental',[])
};

function adjustCurrency(currency){
if(currency.comparedTo($scope.prestigeGoal[$scope.player.maxPrestige]) >= 0){
if($scope.player.sprintFinished == false){
$scope.player.sprintFinished = true;
if(currency.comparedTo($scope.prestigeGoal[$scope.currentPrestige]) >= 0){
if($scope.sprintFinished == false){
$scope.sprintFinished = true;
timerStop();
if($scope.player.sprintTimes.length < $scope.currentPrestige){
throw new Error("Inconsistent prestige value: "+$scope.currentPrestige);
Expand All @@ -267,13 +277,14 @@ angular.module('incremental',[])
$scope.player.sprintTimes[$scope.currentPrestige] = timerSeconds;
}
}
currency = $scope.prestigeGoal[$scope.player.maxPrestige];
currency = $scope.prestigeGoal[$scope.currentPrestige];
}
return currency;
}

function init(){
$scope.player = angular.copy(startPlayer);
$scope.sprintFinished = false;
};

$document.ready(function(){
Expand All @@ -296,7 +307,7 @@ angular.module('incremental',[])

function timerSet(seconds){
timerSeconds = seconds;
if($scope.player.sprintFinished == true){
if($scope.sprintFinished == true){
timerStop();
}
}
Expand All @@ -306,7 +317,7 @@ angular.module('incremental',[])
}

function timerStart() {
if(angular.isDefined(timer) || $scope.player.sprintFinished == true){
if(angular.isDefined(timer) || $scope.sprintFinished == true){
return;
}
timer = $interval(timerAdd,1000);
Expand Down

0 comments on commit 083532d

Please sign in to comment.