diff --git a/public/static/js/game.js b/public/static/js/game.js index 48ede67..4519d62 100644 --- a/public/static/js/game.js +++ b/public/static/js/game.js @@ -132,14 +132,19 @@ } if (data.place) { - Game.readyToContinue = false; + Game.readyToContinue = data.readyToContinue; Game.panoId = data.place.panoId; Game.pov = data.place.pov; document.getElementById('multi').style.visibility = 'hidden'; - document.getElementById('panoCover').style.visibility = 'hidden'; - Game.startNewRound(); + if (Game.rounds.length === 0 || !Game.rounds[Game.rounds.length - 1].position) { + document.getElementById('panoCover').style.visibility = 'hidden'; + Game.startNewRound(); + } else { + Game.loadPano(Game.panoId, Game.pov); + Game.showResultFromHistory(data.history[data.history.length - 1].result); + } } document.getElementById('loading').style.visibility = 'hidden'; @@ -203,7 +208,7 @@ document.getElementById('guessButton').disabled = true; document.getElementById('panoCover').style.visibility = 'visible'; - Game.showResults(data.position, null, { distance: NaN, score: 0 }, data.allResults); + Game.receiveResult(data.position, data.result.guessPosition, { distance: data.result.distance, score: data.result.score }, data.allResults); } }, @@ -411,18 +416,7 @@ Game.panorama.setPano(panoId); }, - showResults: function (position, guessPosition, result, allResults) { - if (Game.adaptGuess) { - document.getElementById('guess').classList.remove('adapt'); - } - - if (Game.guessMarker) { - Game.guessMarker.setMap(null); - Game.guessMarker = null; - } - - document.getElementById('guess').classList.add('result'); - + receiveResult: function (position, guessPosition, result, allResults) { Game.scoreSum += result.score; document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE); @@ -445,13 +439,46 @@ } } + Game.showResultMap(result, resultBounds); + }, + + showResultFromHistory: function (result) { + var round = Game.rounds[Game.rounds.length - 1]; + var resultBounds = new google.maps.LatLngBounds(); + + round.realMarker.setVisible(true); + resultBounds.extend(round.position); + + for (var j = 0; j < round.guessMarkers.length; ++j) { + var guessMarker = round.guessMarkers[j]; + guessMarker.marker.setVisible(true); + guessMarker.line.setVisible(true); + + resultBounds.extend(guessMarker.marker.getPosition()); + } + + Game.showResultMap(result, resultBounds); + }, + + showResultMap: function (result, resultBounds) { + if (Game.adaptGuess) { + document.getElementById('guess').classList.remove('adapt'); + } + + if (Game.guessMarker) { + Game.guessMarker.setMap(null); + Game.guessMarker = null; + } + + document.getElementById('guess').classList.add('result'); + Game.map.setOptions({ draggableCursor: 'grab' }); Game.map.fitBounds(resultBounds); var distanceInfo = document.getElementById('distanceInfo'); - if (Number.isNaN(result.distance)) { + if (result.distance === null) { distanceInfo.children[0].style.display = 'none'; distanceInfo.children[1].style.display = 'block'; } else { @@ -506,7 +533,7 @@ return; } - Game.showResults(this.response.position, guessPosition, this.response.result, this.response.allResults); + Game.receiveResult(this.response.position, guessPosition, this.response.result, this.response.allResults); if (this.response.place) { Game.panoId = this.response.place.panoId;