Skip to content

Commit

Permalink
Load and save score fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kosinaz committed Nov 27, 2017
1 parent fd24e66 commit 12937c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var loadState = {
},

loadTime: function (response) {
if (!response.success) {
if (!response.success || !response.scores[0]) {
return;
}
var i = parseInt(response.scores[0].extra_data, 10) - 1;
Expand All @@ -117,7 +117,7 @@ var loadState = {
},

loadTotal: function (response) {
if (!response.success) {
if (!response.success || !response.scores[0]) {
return;
}
game.totalTime = {
Expand Down
19 changes: 10 additions & 9 deletions src/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,15 @@ var playState = {
game.currentLevel
);
}
game.times[game.currentLevel - 1].int = Math.min(
this.lastMovement,
game.times[game.currentLevel - 1].int
);
game.times[game.currentLevel - 1].string =
Math.floor(game.times[game.currentLevel - 1].int / 60) + ':' +
(game.times[game.currentLevel - 1].int % 60 < 10 ? '0' : '') +
game.times[game.currentLevel - 1].int % 60;
if (!game.times[game.currentLevel - 1] ||
game.times[game.currentLevel - 1].int > this.lastMovement) {
game.times[game.currentLevel - 1] = {
int: this.lastMovement,
string: Math.floor(this.lastMovement / 60) + ':' +
(this.lastMovement % 60 < 10 ? '0' : '') +
this.lastMovement % 60
}
}

if (game.progress > 20) {
game.totalTime = {
Expand Down Expand Up @@ -382,7 +383,7 @@ var playState = {

updateTotal: function (response) {
if (response.success) {
if (game.totalTime.int < parseInt(response.scores[0].sort, 10)) {
if (game.totalTime.int > parseInt(response.scores[0].sort, 10)) {
return;
}
}
Expand Down

0 comments on commit 12937c8

Please sign in to comment.