MAPG-205 show countdown time
All checks were successful
default-pipeline default-pipeline #80
All checks were successful
default-pipeline default-pipeline #80
This commit is contained in:
parent
20914b466e
commit
69329b9f81
@ -17,6 +17,9 @@
|
|||||||
adaptGuess: false,
|
adaptGuess: false,
|
||||||
googleLink: null,
|
googleLink: null,
|
||||||
|
|
||||||
|
timeoutEnd: null,
|
||||||
|
countdownHandler: null,
|
||||||
|
|
||||||
MultiConnector: {
|
MultiConnector: {
|
||||||
connection: null,
|
connection: null,
|
||||||
reconnectCounter: 0,
|
reconnectCounter: 0,
|
||||||
@ -68,6 +71,10 @@
|
|||||||
Game.MultiConnector.guess(json.data);
|
Game.MultiConnector.guess(json.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'timeout_changed':
|
||||||
|
Game.MultiConnector.timeoutChanged(json.data);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'end_round':
|
case 'end_round':
|
||||||
Game.MultiConnector.endRound(json.data);
|
Game.MultiConnector.endRound(json.data);
|
||||||
break;
|
break;
|
||||||
@ -109,6 +116,10 @@
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.timeout) {
|
||||||
|
Game.startCountdown(data.timeout);
|
||||||
|
}
|
||||||
|
|
||||||
if (data.place) {
|
if (data.place) {
|
||||||
Game.panoId = data.place.panoId;
|
Game.panoId = data.place.panoId;
|
||||||
Game.pov = data.place.pov;
|
Game.pov = data.place.pov;
|
||||||
@ -151,6 +162,8 @@
|
|||||||
document.getElementById('multi').style.visibility = 'hidden';
|
document.getElementById('multi').style.visibility = 'hidden';
|
||||||
Game.resetRound();
|
Game.resetRound();
|
||||||
Game.startNewRound();
|
Game.startNewRound();
|
||||||
|
|
||||||
|
Game.startCountdown(data.timeout);
|
||||||
},
|
},
|
||||||
|
|
||||||
guess: function (data) {
|
guess: function (data) {
|
||||||
@ -162,6 +175,10 @@
|
|||||||
Game.map.fitBounds(resultBounds);
|
Game.map.fitBounds(resultBounds);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
timeoutChanged: function (data) {
|
||||||
|
Game.startCountdown(data.timeout);
|
||||||
|
},
|
||||||
|
|
||||||
endRound: function (data) {
|
endRound: function (data) {
|
||||||
// TODO: refactor - it is necessary for mobile
|
// TODO: refactor - it is necessary for mobile
|
||||||
if (window.getComputedStyle(document.getElementById('guess')).visibility === 'hidden') {
|
if (window.getComputedStyle(document.getElementById('guess')).visibility === 'hidden') {
|
||||||
@ -670,6 +687,47 @@
|
|||||||
Game.googleLink.href = 'https://maps.google.com/maps';
|
Game.googleLink.href = 'https://maps.google.com/maps';
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
|
},
|
||||||
|
|
||||||
|
startCountdown: function (timeout) {
|
||||||
|
if (Game.countdownHandler) {
|
||||||
|
clearInterval(Game.countdownHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
Game.timeoutEnd = new Date(new Date().getTime() + timeout);
|
||||||
|
Game.countdownElement = document.getElementById('countdown');
|
||||||
|
Game.countdownTimeElement = document.getElementById('countdownTime');
|
||||||
|
|
||||||
|
Game.setCountdownTime(Math.round(timeout / 1000));
|
||||||
|
|
||||||
|
Game.countdownHandler = setInterval(function () {
|
||||||
|
var timeLeft = Math.round((Game.timeoutEnd - new Date()) / 1000);
|
||||||
|
|
||||||
|
Game.setCountdownTime(timeLeft);
|
||||||
|
|
||||||
|
if (timeLeft <= 0) {
|
||||||
|
document.getElementById('panoCover').style.visibility = 'visible';
|
||||||
|
clearInterval(Game.countdownHandler);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
},
|
||||||
|
|
||||||
|
setCountdownTime: function (time) {
|
||||||
|
if (time <= 0) {
|
||||||
|
Game.countdownElement.style.visibility = 'hidden';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time <= 15) {
|
||||||
|
Game.countdownElement.className = 'red';
|
||||||
|
} else if (time <= 30) {
|
||||||
|
Game.countdownElement.className = 'yellow';
|
||||||
|
} else {
|
||||||
|
Game.countdownElement.className = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
Game.countdownElement.style.visibility = 'visible';
|
||||||
|
Game.countdownTimeElement.innerHTML = time;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user