Compare commits

..

No commits in common. "ac0b71fe09eeeb955817ada4720745fda8be57c7" and "7d2588f7cd443d1b8666c1ae7802793f69bd002b" have entirely different histories.

2 changed files with 60 additions and 98 deletions

View File

@ -165,18 +165,9 @@ class MultiGame {
} }
_endRound(room, round) { _endRound(room, round) {
var allResults = this._collectResultsInRound(room, round); var data = { position: round.place.position, allResults: this._collectResultsInRound(room, round) };
var self = this; var self = this;
room.members.forEach(function (member, token) { room.members.forEach(function (member) {
var result = { guessPosition: null, distance: null, score: 0 };
if (round.results.has(token)) {
result = round.results.get(token);
} else {
round.results.set(token, result);
}
var data = { position: round.place.position, result: result, allResults: allResults };
self._sendToMember(member, 'end_round', data); self._sendToMember(member, 'end_round', data);
}); });
} }
@ -192,13 +183,9 @@ class MultiGame {
} }
data.history = []; data.history = [];
for (var i = 0; i <= room.currentRound; ++i) { for (var i = 0; i < room.currentRound; ++i) {
var round = room.rounds[i]; var round = room.rounds[i];
if (i === room.currentRound && !round.results.has(token)) {
continue;
}
var result = { guessPosition: null, distance: null, score: 0 }; var result = { guessPosition: null, distance: null, score: 0 };
var allResults = []; var allResults = [];
@ -223,8 +210,6 @@ class MultiGame {
data.members.push({ userName: currentMember.userName, me: member === currentMember }); data.members.push({ userName: currentMember.userName, me: member === currentMember });
}); });
data.readyToContinue = room.currentRound >= 0 && room.members.size === room.rounds[room.currentRound].results.size
this._sendToMember(member, 'initialize', data); this._sendToMember(member, 'initialize', data);
} }

View File

@ -97,57 +97,52 @@
}, },
initialize: function (data) { initialize: function (data) {
if (data.history.length === 0 && !data.place) { if (data.history) {
var div = document.getElementById('players'); for (var i = 0; i < data.history.length; ++i) {
var round = data.history[i];
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
Game.addPositionToResultMap(true);
if (round.result.guessPosition) {
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
}
Game.scoreSum += round.result.score;
for (var i = 0; i < data.members.length; ++i) { for (var j = 0; j < round.allResults.length; ++j) {
var member = data.members[i]; var result = round.allResults[j];
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
var p = document.createElement('p'); }
p.innerHTML = member.userName + (member.me ? ' (me)' : '');
div.appendChild(p);
} }
document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS);
document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE);
} }
for (var i = 0; i < data.history.length; ++i) {
var round = data.history[i];
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
Game.addPositionToResultMap(true);
if (round.result.guessPosition) {
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
}
Game.scoreSum += round.result.score;
for (var j = 0; j < round.allResults.length; ++j) {
var result = round.allResults[j];
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
}
}
document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS);
document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE);
if (data.timeout) { if (data.timeout) {
Game.startCountdown(data.timeout); Game.startCountdown(data.timeout);
} }
if (data.place) { if (data.place) {
Game.readyToContinue = data.readyToContinue; Game.readyToContinue = false;
Game.panoId = data.place.panoId; Game.panoId = data.place.panoId;
Game.pov = data.place.pov; Game.pov = data.place.pov;
document.getElementById('multi').style.visibility = 'hidden'; document.getElementById('multi').style.visibility = 'hidden';
document.getElementById('panoCover').style.visibility = 'hidden';
if (Game.rounds.length === 0 || !Game.rounds[Game.rounds.length - 1].position) { Game.startNewRound();
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'; document.getElementById('loading').style.visibility = 'hidden';
var div = document.getElementById('players');
for (var i = 0; i < data.members.length; ++i) {
var member = data.members[i];
var p = document.createElement('p');
p.innerHTML = member.userName + (member.me ? ' (me)' : '');
div.appendChild(p);
}
}, },
memberJoined: function (data) { memberJoined: function (data) {
@ -208,7 +203,7 @@
document.getElementById('guessButton').disabled = true; document.getElementById('guessButton').disabled = true;
document.getElementById('panoCover').style.visibility = 'visible'; document.getElementById('panoCover').style.visibility = 'visible';
Game.receiveResult(data.position, data.result.guessPosition, { distance: data.result.distance, score: data.result.score }, data.allResults); Game.showResults(data.position, null, { distance: NaN, score: 0 }, data.allResults);
} }
}, },
@ -258,6 +253,8 @@
initialize: function () { initialize: function () {
document.getElementById('panoCover').style.visibility = 'visible'; document.getElementById('panoCover').style.visibility = 'visible';
document.getElementById('currentRound').innerHTML = '1/' + String(Game.NUMBER_OF_ROUNDS);
document.getElementById('currentScoreSum').innerHTML = '0/0';
Game.map.setOptions({ Game.map.setOptions({
draggableCursor: 'crosshair' draggableCursor: 'crosshair'
@ -282,16 +279,18 @@
Game.panoId = this.response.place.panoId; Game.panoId = this.response.place.panoId;
Game.pov = this.response.place.pov; Game.pov = this.response.place.pov;
for (var i = 0; i < this.response.history.length; ++i) { if (this.response.history) {
var round = this.response.history[i]; for (var i = 0; i < this.response.history.length; ++i) {
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] }); var round = this.response.history[i];
Game.addPositionToResultMap(true); Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true); Game.addPositionToResultMap(true);
Game.scoreSum += round.result.score; Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
} Game.scoreSum += round.result.score;
}
document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS); document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS);
document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE); document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE);
}
Game.startNewRound(); Game.startNewRound();
}); });
@ -416,7 +415,18 @@
Game.panorama.setPano(panoId); Game.panorama.setPano(panoId);
}, },
receiveResult: function (position, guessPosition, result, allResults) { 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');
Game.scoreSum += result.score; Game.scoreSum += result.score;
document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE); document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE);
@ -439,46 +449,13 @@
} }
} }
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({ Game.map.setOptions({
draggableCursor: 'grab' draggableCursor: 'grab'
}); });
Game.map.fitBounds(resultBounds); Game.map.fitBounds(resultBounds);
var distanceInfo = document.getElementById('distanceInfo'); var distanceInfo = document.getElementById('distanceInfo');
if (result.distance === null) { if (Number.isNaN(result.distance)) {
distanceInfo.children[0].style.display = 'none'; distanceInfo.children[0].style.display = 'none';
distanceInfo.children[1].style.display = 'block'; distanceInfo.children[1].style.display = 'block';
} else { } else {
@ -533,7 +510,7 @@
return; return;
} }
Game.receiveResult(this.response.position, guessPosition, this.response.result, this.response.allResults); Game.showResults(this.response.position, guessPosition, this.response.result, this.response.allResults);
if (this.response.place) { if (this.response.place) {
Game.panoId = this.response.place.panoId; Game.panoId = this.response.place.panoId;