Compare commits

..

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

2 changed files with 32 additions and 60 deletions

View File

@ -97,15 +97,28 @@ class MultiGame {
room.updated = new Date();
var round = room.rounds[room.currentRound];
clearTimeout(round.timeoutHandler);
round.timeout = round.timeout - (new Date() - round.timeoutStarted);
if (round.timeout > MultiGame.ROUND_TIMEOUT_DIVIDER * MultiGame.ROUND_TIMEOUT_MINIMUM) {
round.timeout = round.timeout / MultiGame.ROUND_TIMEOUT_DIVIDER;
} else if (round.timeout > MultiGame.ROUND_TIMEOUT_MINIMUM) {
round.timeout = MultiGame.ROUND_TIMEOUT_MINIMUM;
}
round.timeoutStarted = new Date();
var self = this;
round.timeoutHandler = setTimeout(function () {
self._endRoundTimeout(room, round);
}, round.timeout + MultiGame.ROUND_TIMEOUT_OFFSET);
var member = room.members.get(token);
var allResults = this._collectResultsInRound(room, round);
this._broadcastTimeout(room, round);
this._broadcastGuess(room, member.userName, guessPosition, distance, score);
round.results.set(token, { guessPosition: guessPosition, distance: distance, score: score });
this._setNewTimeout(room, round);
return allResults;
}
@ -126,7 +139,7 @@ class MultiGame {
round.timeoutStarted = new Date();
var self = this;
round.timeoutHandler = setTimeout(function () {
self._endRound(room, round);
self._endRoundTimeout(room, round);
}, round.timeout + MultiGame.ROUND_TIMEOUT_OFFSET);
var data = {};
@ -139,35 +152,16 @@ class MultiGame {
});
}
_setNewTimeout(room, round) {
_endRoundTimeout(room, round) {
clearTimeout(round.timeoutHandler);
if (room.members.size === round.results.size) {
round.timeout = 0;
round.timeoutStarted = new Date();
this._endRound(room, round);
} else {
round.timeout = round.timeout - (new Date() - round.timeoutStarted);
if (round.timeout > MultiGame.ROUND_TIMEOUT_DIVIDER * MultiGame.ROUND_TIMEOUT_MINIMUM) {
round.timeout = round.timeout / MultiGame.ROUND_TIMEOUT_DIVIDER;
} else if (round.timeout > MultiGame.ROUND_TIMEOUT_MINIMUM) {
round.timeout = MultiGame.ROUND_TIMEOUT_MINIMUM;
}
round.timeoutStarted = new Date();
var self = this;
round.timeoutHandler = setTimeout(function () {
self._endRound(room, round);
}, round.timeout + MultiGame.ROUND_TIMEOUT_OFFSET);
this._broadcastTimeout(room, round);
}
}
_endRound(room, round) {
var data = { position: round.place.position, allResults: this._collectResultsInRound(room, round) };
var self = this;
room.members.forEach(function (member) {
room.members.forEach(function (member, token) {
if (round.results.has(token)) {
return;
}
self._sendToMember(member, 'end_round', data);
});
}

View File

@ -17,7 +17,6 @@
adaptGuess: false,
googleLink: null,
readyToContinue: false,
timeoutEnd: null,
countdownHandler: null,
@ -122,7 +121,6 @@
}
if (data.place) {
Game.readyToContinue = false;
Game.panoId = data.place.panoId;
Game.pov = data.place.pov;
@ -158,7 +156,6 @@
Game.reset();
}
Game.readyToContinue = false;
Game.panoId = data.place.panoId;
Game.pov = data.place.pov;
@ -183,18 +180,6 @@
},
endRound: function (data) {
Game.readyToContinue = true;
Game.startCountdown(0);
if (Game.rounds[Game.rounds.length - 1].guessPosition || Game.rounds[Game.rounds.length - 1].position) {
if (Game.multi.owner) {
document.getElementById('continueButton').disabled = false;
document.getElementById('startNewGameButton').disabled = false;
}
return;
}
// TODO: refactor - it is necessary for mobile
if (window.getComputedStyle(document.getElementById('guess')).visibility === 'hidden') {
document.getElementById('showGuessButton').click();
@ -204,6 +189,10 @@
document.getElementById('panoCover').style.visibility = 'visible';
Game.showResults(data.position, null, { distance: NaN, score: 0 }, data.allResults);
if (!Game.multi.owner) {
document.getElementById('continueButton').style.display = 'none';
}
}
},
@ -474,14 +463,6 @@
if (Game.rounds.length === Game.NUMBER_OF_ROUNDS) {
document.getElementById('continueButton').style.display = 'none';
document.getElementById('showSummaryButton').style.display = 'block';
} else if (roomId) {
if (Game.multi.owner) {
if (!Game.readyToContinue) {
document.getElementById('continueButton').disabled = true;
}
} else {
document.getElementById('continueButton').style.display = 'none';
}
}
},
@ -515,6 +496,10 @@
if (this.response.place) {
Game.panoId = this.response.place.panoId;
Game.pov = this.response.place.pov;
} else {
if (!Game.multi.owner) {
document.getElementById('continueButton').style.display = 'none';
}
}
}, data);
},
@ -640,9 +625,6 @@
if (!roomId || Game.multi.owner) {
document.getElementById('startNewGameButton').style.display = 'block';
if (!Game.readyToContinue) {
document.getElementById('startNewGameButton').disabled = true;
}
}
var resultBounds = new google.maps.LatLngBounds();
@ -712,10 +694,6 @@
clearInterval(Game.countdownHandler);
}
if (timeout <= 0) {
return;
}
Game.timeoutEnd = new Date(new Date().getTime() + timeout);
Game.countdownElement = document.getElementById('countdown');
Game.countdownTimeElement = document.getElementById('countdownTime');
@ -780,7 +758,7 @@
});
Game.map.addListener('click', function (e) {
if (Game.rounds[Game.rounds.length - 1].guessPosition || Game.rounds[Game.rounds.length - 1].position) {
if (Game.rounds[Game.rounds.length - 1].guessPosition) {
return;
}
@ -848,7 +826,7 @@
document.getElementById('continueButton').onclick = function () {
if (roomId) {
if (!Game.multi.owner || !Game.readyToContinue) {
if (!Game.multi.owner) {
return;
}