2020-05-21 23:43:17 +02:00
|
|
|
'use strict';
|
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
(function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
var Game = {
|
2020-05-21 23:43:17 +02:00
|
|
|
NUMBER_OF_ROUNDS: 5,
|
2020-05-20 03:19:53 +02:00
|
|
|
MAX_SCORE: 1000,
|
|
|
|
|
2021-03-19 22:59:09 +01:00
|
|
|
mapBounds: null,
|
|
|
|
multi: { token: null, owner: false },
|
2020-05-21 23:43:17 +02:00
|
|
|
rounds: [],
|
|
|
|
scoreSum: 0,
|
2020-05-25 19:51:02 +02:00
|
|
|
panoId: null,
|
2020-07-04 01:11:04 +02:00
|
|
|
pov: null,
|
2020-05-20 03:19:53 +02:00
|
|
|
panorama: null,
|
2020-05-22 23:23:54 +02:00
|
|
|
map: null,
|
2020-05-20 03:19:53 +02:00
|
|
|
guessMarker: null,
|
2020-05-21 23:43:17 +02:00
|
|
|
adaptGuess: false,
|
2020-05-20 03:19:53 +02:00
|
|
|
googleLink: null,
|
|
|
|
|
2021-04-29 13:57:32 +02:00
|
|
|
readyToContinue: true,
|
2021-04-04 13:54:19 +02:00
|
|
|
timeoutEnd: null,
|
|
|
|
countdownHandler: null,
|
|
|
|
|
2021-03-19 22:59:09 +01:00
|
|
|
MultiConnector: {
|
|
|
|
connection: null,
|
|
|
|
reconnectCounter: 0,
|
|
|
|
|
|
|
|
connect: function () {
|
|
|
|
if (Game.MultiConnector.connection && Game.MultiConnector.connection.readyState !== WebSocket.CLOSED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Game.MultiConnector.connection = new WebSocket((MapGuesser.isSecure ? 'wss' : 'ws') + '://' + multiUrl);
|
|
|
|
|
|
|
|
Game.MultiConnector.connection.onopen = function () {
|
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
|
|
|
Game.MultiConnector.reconnectCounter = 0;
|
|
|
|
Game.MultiConnector.connection.send(JSON.stringify({ func: 'connect_to_room', args: { roomId: roomId, token: Game.multi.token } }));
|
|
|
|
};
|
|
|
|
|
|
|
|
Game.MultiConnector.connection.onclose = Game.MultiConnector.noConnection;
|
|
|
|
|
|
|
|
Game.MultiConnector.connection.onerror = function (event) {
|
|
|
|
console.error('WebSocket error in Game.MultiConnector:', event);
|
|
|
|
};
|
|
|
|
|
|
|
|
Game.MultiConnector.connection.onmessage = function (message) {
|
|
|
|
var json;
|
|
|
|
|
|
|
|
try {
|
|
|
|
json = JSON.parse(message.data);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Cannot parse message!');
|
|
|
|
console.error(message.data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (json.type) {
|
|
|
|
case 'initialize':
|
|
|
|
Game.MultiConnector.initialize(json.data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'member_joined':
|
|
|
|
Game.MultiConnector.memberJoined(json.data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'new_round':
|
|
|
|
Game.MultiConnector.newRound(json.data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'guess':
|
2021-04-03 22:10:21 +02:00
|
|
|
Game.MultiConnector.guess(json.data);
|
2021-03-19 22:59:09 +01:00
|
|
|
break;
|
2021-04-04 01:07:34 +02:00
|
|
|
|
2021-04-04 13:54:19 +02:00
|
|
|
case 'timeout_changed':
|
|
|
|
Game.MultiConnector.timeoutChanged(json.data);
|
|
|
|
break;
|
|
|
|
|
2021-04-04 01:07:34 +02:00
|
|
|
case 'end_round':
|
|
|
|
Game.MultiConnector.endRound(json.data);
|
|
|
|
break;
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
noConnection: function () {
|
|
|
|
if (Game.MultiConnector.reconnectCounter === 2) {
|
|
|
|
console.error('Could not reconnect WebSocket for Game.MultiConnector...')
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
Game.MultiConnector.reconnectCounter++;
|
|
|
|
|
|
|
|
console.log('Reconnecting WebSocket for Game.MultiConnector... ' + Game.MultiConnector.reconnectCounter);
|
|
|
|
Game.MultiConnector.connect();
|
|
|
|
}, 1000 + Math.min(Game.MultiConnector.reconnectCounter * 500, 9000));
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function (data) {
|
2021-04-29 13:57:32 +02:00
|
|
|
Game.readyToContinue = false;
|
|
|
|
|
2021-04-04 20:52:28 +02:00
|
|
|
if (data.history.length === 0 && !data.place) {
|
|
|
|
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);
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
2021-04-04 20:52:28 +02:00
|
|
|
}
|
2021-03-19 22:59:09 +01:00
|
|
|
|
2021-04-04 20:52:28 +02:00
|
|
|
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];
|
2021-04-04 23:01:01 +02:00
|
|
|
if (result.guessPosition) {
|
|
|
|
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
|
|
|
|
}
|
2021-04-04 20:52:28 +02:00
|
|
|
}
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
|
|
|
|
2021-04-04 20:52:28 +02:00
|
|
|
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);
|
|
|
|
|
2021-04-04 13:54:19 +02:00
|
|
|
if (data.timeout) {
|
|
|
|
Game.startCountdown(data.timeout);
|
|
|
|
}
|
|
|
|
|
2021-03-19 22:59:09 +01:00
|
|
|
if (data.place) {
|
2021-04-04 22:24:40 +02:00
|
|
|
Game.readyToContinue = data.readyToContinue;
|
2021-03-19 22:59:09 +01:00
|
|
|
Game.panoId = data.place.panoId;
|
|
|
|
Game.pov = data.place.pov;
|
|
|
|
|
2021-03-21 12:45:57 +01:00
|
|
|
document.getElementById('multi').style.visibility = 'hidden';
|
2021-03-19 22:59:09 +01:00
|
|
|
|
2021-04-04 22:24:40 +02:00
|
|
|
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);
|
|
|
|
}
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
|
|
|
},
|
|
|
|
|
|
|
|
memberJoined: function (data) {
|
|
|
|
var div = document.getElementById('players');
|
|
|
|
|
|
|
|
var p = document.createElement('p');
|
|
|
|
p.innerHTML = data.userName;
|
|
|
|
div.appendChild(p);
|
|
|
|
},
|
|
|
|
|
|
|
|
newRound: function (data) {
|
|
|
|
if (Game.rounds.length === Game.NUMBER_OF_ROUNDS) {
|
|
|
|
Game.reset();
|
|
|
|
}
|
|
|
|
|
2021-04-04 18:48:31 +02:00
|
|
|
Game.readyToContinue = false;
|
2021-03-19 22:59:09 +01:00
|
|
|
Game.panoId = data.place.panoId;
|
|
|
|
Game.pov = data.place.pov;
|
|
|
|
|
2021-03-21 12:45:57 +01:00
|
|
|
document.getElementById('multi').style.visibility = 'hidden';
|
2021-03-19 22:59:09 +01:00
|
|
|
Game.resetRound();
|
|
|
|
Game.startNewRound();
|
2021-04-04 13:54:19 +02:00
|
|
|
|
|
|
|
Game.startCountdown(data.timeout);
|
2021-04-03 22:10:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
guess: function (data) {
|
|
|
|
var resultBounds = Game.map.getBounds();
|
|
|
|
|
|
|
|
Game.addGuessPositionToResultMap(data.guessPosition, data);
|
|
|
|
resultBounds.extend(data.guessPosition);
|
|
|
|
|
|
|
|
Game.map.fitBounds(resultBounds);
|
2021-04-04 01:07:34 +02:00
|
|
|
},
|
|
|
|
|
2021-04-04 13:54:19 +02:00
|
|
|
timeoutChanged: function (data) {
|
|
|
|
Game.startCountdown(data.timeout);
|
|
|
|
},
|
|
|
|
|
2021-04-04 01:07:34 +02:00
|
|
|
endRound: function (data) {
|
2021-04-04 18:48:31 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-04 01:07:34 +02:00
|
|
|
document.getElementById('guessButton').disabled = true;
|
|
|
|
document.getElementById('panoCover').style.visibility = 'visible';
|
|
|
|
|
2021-04-04 22:24:40 +02:00
|
|
|
Game.receiveResult(data.position, data.result.guessPosition, { distance: data.result.distance, score: data.result.score }, data.allResults);
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
prepare: function () {
|
|
|
|
var data = new FormData();
|
|
|
|
var userNames;
|
|
|
|
|
|
|
|
if (roomId) {
|
|
|
|
var userNames = localStorage.userNames ? JSON.parse(localStorage.userNames) : {};
|
|
|
|
if (!userNames.hasOwnProperty(roomId)) {
|
|
|
|
userNames[roomId] = prompt('Your name: ');
|
|
|
|
localStorage.userNames = JSON.stringify(userNames);
|
|
|
|
}
|
|
|
|
|
|
|
|
data.append('userName', userNames[roomId]);
|
|
|
|
}
|
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
2021-03-19 22:59:09 +01:00
|
|
|
var url = roomId ? '/multiGame/' + roomId + '/prepare.json' : '/game/' + mapId + '/prepare.json';
|
|
|
|
MapGuesser.httpRequest('POST', url, function () {
|
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
|
|
|
|
2021-03-21 14:37:08 +01:00
|
|
|
if (this.response.error) {
|
|
|
|
Game.handleErrorResponse(this.response.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-19 22:59:09 +01:00
|
|
|
document.getElementById('mapName').innerHTML = this.response.mapName;
|
|
|
|
Game.mapBounds = this.response.bounds;
|
|
|
|
|
|
|
|
Game.initialize();
|
|
|
|
|
|
|
|
if (roomId) {
|
|
|
|
Game.multi.token = this.response.token;
|
|
|
|
Game.multi.owner = this.response.owner;
|
|
|
|
|
2021-03-21 12:45:57 +01:00
|
|
|
document.getElementById('multi').style.visibility = 'visible';
|
2021-03-19 22:59:09 +01:00
|
|
|
if (Game.multi.owner) {
|
|
|
|
document.getElementById('startMultiGameButton').style.display = 'block';
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
|
|
|
Game.MultiConnector.connect();
|
|
|
|
}
|
|
|
|
}, data);
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
2020-06-25 14:02:39 +02:00
|
|
|
document.getElementById('panoCover').style.visibility = 'visible';
|
2020-05-25 19:51:02 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.setOptions({
|
2020-05-26 23:23:49 +02:00
|
|
|
draggableCursor: 'crosshair'
|
|
|
|
});
|
2021-03-19 22:59:09 +01:00
|
|
|
Game.map.fitBounds(Game.mapBounds);
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2021-03-19 22:59:09 +01:00
|
|
|
if (roomId) {
|
|
|
|
// if it is multiplayer mode, data is sent via WS
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
|
|
|
MapGuesser.httpRequest('POST', '/game/' + mapId + '/initialData.json', function () {
|
2020-06-05 19:36:47 +02:00
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
2020-06-25 14:02:39 +02:00
|
|
|
document.getElementById('panoCover').style.visibility = 'hidden';
|
2020-06-05 19:36:47 +02:00
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
if (this.response.error) {
|
2021-03-21 14:37:08 +01:00
|
|
|
Game.handleErrorResponse(this.response.error);
|
2020-05-26 23:23:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-15 12:28:25 +01:00
|
|
|
Game.panoId = this.response.place.panoId;
|
|
|
|
Game.pov = this.response.place.pov;
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2021-04-04 20:52:28 +02:00
|
|
|
for (var i = 0; i < this.response.history.length; ++i) {
|
|
|
|
var round = this.response.history[i];
|
|
|
|
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
|
|
|
|
Game.addPositionToResultMap(true);
|
|
|
|
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
|
|
|
|
Game.scoreSum += round.result.score;
|
2020-05-25 19:51:02 +02:00
|
|
|
}
|
2020-05-23 01:25:43 +02:00
|
|
|
|
2021-04-04 20:52:28 +02:00
|
|
|
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);
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.startNewRound();
|
2020-06-13 22:39:44 +02:00
|
|
|
});
|
2020-05-22 01:31:32 +02:00
|
|
|
},
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
reset: function () {
|
|
|
|
if (Game.guessMarker) {
|
|
|
|
Game.guessMarker.setMap(null);
|
|
|
|
Game.guessMarker = null;
|
2020-05-30 18:05:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
for (var i = 0; i < Game.rounds.length; ++i) {
|
|
|
|
var round = Game.rounds[i];
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2021-03-19 22:59:09 +01:00
|
|
|
if (round.realMarker) {
|
2020-05-26 23:23:49 +02:00
|
|
|
round.realMarker.setMap(null);
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
2021-04-03 22:10:21 +02:00
|
|
|
for (var j = 0; j < round.guessMarkers.length; ++j) {
|
|
|
|
var guessMarker = round.guessMarkers[j];
|
|
|
|
guessMarker.marker.setMap(null);
|
|
|
|
guessMarker.line.setMap(null);
|
|
|
|
if (guessMarker.info) {
|
|
|
|
guessMarker.info.close();
|
|
|
|
}
|
2020-05-26 23:23:49 +02:00
|
|
|
}
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.rounds = [];
|
|
|
|
Game.scoreSum = 0;
|
2020-05-21 23:43:17 +02:00
|
|
|
|
|
|
|
var distanceInfo = document.getElementById('distanceInfo');
|
|
|
|
distanceInfo.children[0].style.display = null;
|
|
|
|
distanceInfo.children[1].style.display = null;
|
2021-04-04 01:07:34 +02:00
|
|
|
distanceInfo.children[2].style.display = null;
|
2020-05-21 23:43:17 +02:00
|
|
|
var scoreInfo = document.getElementById('scoreInfo');
|
|
|
|
scoreInfo.children[0].style.display = null;
|
|
|
|
scoreInfo.children[1].style.display = null;
|
|
|
|
document.getElementById('continueButton').style.display = null;
|
2021-04-04 23:01:01 +02:00
|
|
|
document.getElementById('showSummaryButton').style.display = null;
|
2020-05-21 23:43:17 +02:00
|
|
|
document.getElementById('startNewGameButton').style.display = null;
|
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
document.getElementById('showGuessButton').style.visibility = null;
|
|
|
|
document.getElementById('guess').style.visibility = null;
|
|
|
|
document.getElementById('guess').classList.remove('result');
|
2020-05-23 01:25:43 +02:00
|
|
|
|
2021-04-29 08:24:20 +02:00
|
|
|
// needs to be set visible after the show guess map hid it in mobile view
|
|
|
|
document.getElementById("navigation").style.visibility = 'visible';
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.initialize();
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
resetRound: function () {
|
2020-05-21 23:43:17 +02:00
|
|
|
document.getElementById('scoreBar').style.width = null;
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
if (Game.rounds.length > 0) {
|
|
|
|
var lastRound = Game.rounds[Game.rounds.length - 1];
|
2020-05-22 23:22:11 +02:00
|
|
|
|
|
|
|
lastRound.realMarker.setVisible(false);
|
2021-04-03 22:10:21 +02:00
|
|
|
for (var i = 0; i < lastRound.guessMarkers.length; ++i) {
|
|
|
|
var guessMarker = lastRound.guessMarkers[i];
|
|
|
|
guessMarker.marker.setVisible(false);
|
|
|
|
guessMarker.line.setVisible(false);
|
|
|
|
if (guessMarker.info) {
|
|
|
|
guessMarker.info.close();
|
|
|
|
}
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
2021-04-03 22:10:21 +02:00
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 14:02:39 +02:00
|
|
|
document.getElementById('panoCover').style.visibility = 'hidden';
|
2020-05-21 23:43:17 +02:00
|
|
|
document.getElementById('showGuessButton').style.visibility = null;
|
|
|
|
document.getElementById('guess').style.visibility = null;
|
2021-04-29 09:07:44 +02:00
|
|
|
document.getElementById('guess').classList.remove('result');
|
|
|
|
|
|
|
|
// needs to be set visible after the show guess map hid it in mobile view
|
|
|
|
document.getElementById("navigation").style.visibility = 'visible';
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.setOptions({
|
2020-05-22 23:22:11 +02:00
|
|
|
draggableCursor: 'crosshair'
|
|
|
|
});
|
2021-03-19 22:59:09 +01:00
|
|
|
Game.map.fitBounds(Game.mapBounds);
|
|
|
|
|
|
|
|
if (roomId) {
|
|
|
|
// if it is multiplayer mode, data is sent via WS
|
|
|
|
return;
|
|
|
|
}
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.startNewRound();
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
startNewRound: function () {
|
2021-04-03 22:10:21 +02:00
|
|
|
Game.rounds.push({ position: null, guessPosition: null, realMarker: null, guessMarkers: [] });
|
2020-05-20 15:54:09 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS);
|
2020-05-23 01:25:43 +02:00
|
|
|
|
2020-07-04 01:11:04 +02:00
|
|
|
Game.loadPano(Game.panoId, Game.pov);
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
handleErrorResponse: function (error) {
|
2021-03-21 14:37:08 +01:00
|
|
|
switch (error) {
|
|
|
|
case 'no_session_found':
|
|
|
|
MapGuesser.showModalWithContent('Error', 'Your session is invalid!', [{
|
|
|
|
type: 'button',
|
|
|
|
classNames: [],
|
|
|
|
text: 'Restart game',
|
|
|
|
onclick: function () {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
}]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'game_already_started':
|
|
|
|
MapGuesser.showModalWithContent('Error', 'This game is already started, you cannot join.');
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MapGuesser.showModalWithContent('Error', 'Error code: \'' + error + '\'');
|
|
|
|
break
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
2020-05-20 03:19:53 +02:00
|
|
|
},
|
|
|
|
|
2020-07-04 01:11:04 +02:00
|
|
|
loadPano: function (panoId, pov) {
|
2020-06-05 00:23:07 +02:00
|
|
|
if (Game.adaptGuess) {
|
2020-05-21 03:24:09 +02:00
|
|
|
document.getElementById('guess').classList.add('adapt');
|
|
|
|
}
|
|
|
|
|
2020-07-04 01:11:04 +02:00
|
|
|
Game.panorama.setPov({ heading: pov.heading, pitch: pov.pitch });
|
|
|
|
Game.panorama.setZoom(pov.zoom);
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panorama.setPano(panoId);
|
2020-05-20 03:19:53 +02:00
|
|
|
},
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2021-04-04 22:24:40 +02:00
|
|
|
receiveResult: function (position, guessPosition, result, allResults) {
|
2021-04-04 01:07:34 +02:00
|
|
|
Game.scoreSum += result.score;
|
|
|
|
document.getElementById('currentScoreSum').innerHTML = String(Game.scoreSum) + '/' + String(Game.rounds.length * Game.MAX_SCORE);
|
|
|
|
|
|
|
|
var resultBounds = new google.maps.LatLngBounds();
|
|
|
|
|
|
|
|
Game.rounds[Game.rounds.length - 1].position = position;
|
|
|
|
Game.addPositionToResultMap();
|
|
|
|
resultBounds.extend(position);
|
|
|
|
|
|
|
|
if (guessPosition) {
|
|
|
|
Game.addGuessPositionToResultMap(guessPosition);
|
|
|
|
resultBounds.extend(guessPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allResults) {
|
|
|
|
for (var i = 0; i < allResults.length; ++i) {
|
|
|
|
var currentResult = allResults[i];
|
2021-04-04 23:01:01 +02:00
|
|
|
if (currentResult.guessPosition) {
|
|
|
|
Game.addGuessPositionToResultMap(currentResult.guessPosition, currentResult);
|
|
|
|
resultBounds.extend(currentResult.guessPosition);
|
|
|
|
}
|
2021-04-04 01:07:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-04 22:24:40 +02:00
|
|
|
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) {
|
2021-04-04 23:40:27 +02:00
|
|
|
// TODO: refactor - it is necessary for mobile
|
|
|
|
if (window.getComputedStyle(document.getElementById('guess')).visibility === 'hidden') {
|
|
|
|
document.getElementById('showGuessButton').click();
|
|
|
|
}
|
|
|
|
|
2021-04-04 22:24:40 +02:00
|
|
|
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');
|
|
|
|
|
2021-04-04 01:07:34 +02:00
|
|
|
Game.map.setOptions({
|
|
|
|
draggableCursor: 'grab'
|
|
|
|
});
|
|
|
|
Game.map.fitBounds(resultBounds);
|
|
|
|
|
|
|
|
var distanceInfo = document.getElementById('distanceInfo');
|
2021-04-04 22:24:40 +02:00
|
|
|
if (result.distance === null) {
|
2021-04-04 01:07:34 +02:00
|
|
|
distanceInfo.children[0].style.display = 'none';
|
|
|
|
distanceInfo.children[1].style.display = 'block';
|
|
|
|
} else {
|
|
|
|
distanceInfo.children[0].style.display = 'block';
|
|
|
|
distanceInfo.children[1].style.display = 'none';
|
|
|
|
document.getElementById('distance').innerHTML = Util.printDistanceForHuman(result.distance);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('score').innerHTML = result.score;
|
|
|
|
|
|
|
|
var scoreBarProperties = Game.calculateScoreBarProperties(result.score, Game.MAX_SCORE);
|
|
|
|
var scoreBar = document.getElementById('scoreBar');
|
|
|
|
scoreBar.style.backgroundColor = scoreBarProperties.backgroundColor;
|
|
|
|
scoreBar.style.width = scoreBarProperties.width;
|
|
|
|
|
|
|
|
if (Game.rounds.length === Game.NUMBER_OF_ROUNDS) {
|
|
|
|
document.getElementById('continueButton').style.display = 'none';
|
|
|
|
document.getElementById('showSummaryButton').style.display = 'block';
|
2021-04-04 18:48:31 +02:00
|
|
|
} else if (roomId) {
|
|
|
|
if (Game.multi.owner) {
|
|
|
|
if (!Game.readyToContinue) {
|
|
|
|
document.getElementById('continueButton').disabled = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.getElementById('continueButton').style.display = 'none';
|
|
|
|
}
|
2021-04-04 01:07:34 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-04-03 13:38:16 +02:00
|
|
|
guess: function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
if (!Game.guessMarker) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var guessPosition = Game.guessMarker.getPosition().toJSON();
|
|
|
|
Game.rounds[Game.rounds.length - 1].guessPosition = guessPosition;
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
document.getElementById('guessButton').disabled = true;
|
2020-06-25 14:02:39 +02:00
|
|
|
document.getElementById('panoCover').style.visibility = 'visible';
|
2020-05-22 01:31:32 +02:00
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
var data = new FormData();
|
|
|
|
data.append('lat', String(guessPosition.lat));
|
|
|
|
data.append('lng', String(guessPosition.lng));
|
|
|
|
|
2021-03-21 14:37:08 +01:00
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
2021-03-19 22:59:09 +01:00
|
|
|
var url = roomId ? '/multiGame/' + roomId + '/guess.json' : '/game/' + mapId + '/guess.json';
|
|
|
|
MapGuesser.httpRequest('POST', url, function () {
|
2021-03-21 14:37:08 +01:00
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
|
|
|
|
2020-05-26 23:23:49 +02:00
|
|
|
if (this.response.error) {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.handleErrorResponse(this.response.error);
|
2020-05-26 23:23:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-05-23 01:25:43 +02:00
|
|
|
|
2021-04-04 22:24:40 +02:00
|
|
|
Game.receiveResult(this.response.position, guessPosition, this.response.result, this.response.allResults);
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2021-03-17 22:54:06 +01:00
|
|
|
if (this.response.place) {
|
|
|
|
Game.panoId = this.response.place.panoId;
|
|
|
|
Game.pov = this.response.place.pov;
|
2021-03-15 12:28:25 +01:00
|
|
|
}
|
2020-06-13 22:39:44 +02:00
|
|
|
}, data);
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
2021-04-03 22:10:21 +02:00
|
|
|
addPositionToResultMap: function (hidden) {
|
2020-06-05 00:23:07 +02:00
|
|
|
var round = Game.rounds[Game.rounds.length - 1];
|
2021-04-03 22:10:21 +02:00
|
|
|
var position = round.position;
|
2020-05-21 23:43:17 +02:00
|
|
|
|
|
|
|
round.realMarker = new google.maps.Marker({
|
2020-06-05 00:23:07 +02:00
|
|
|
map: Game.map,
|
2020-05-22 23:22:11 +02:00
|
|
|
visible: !hidden,
|
2020-05-25 19:51:02 +02:00
|
|
|
position: position,
|
2020-05-22 23:55:09 +02:00
|
|
|
title: 'Open in Google Maps',
|
2020-06-05 00:23:07 +02:00
|
|
|
zIndex: Game.rounds.length * 2,
|
2020-05-21 23:43:17 +02:00
|
|
|
clickable: true,
|
2020-06-01 20:41:46 +02:00
|
|
|
draggable: false,
|
|
|
|
icon: {
|
2020-06-12 20:13:43 +02:00
|
|
|
url: STATIC_ROOT + '/img/markers/marker-green.svg?rev=' + REVISION,
|
2020-06-01 20:41:46 +02:00
|
|
|
size: new google.maps.Size(24, 32),
|
|
|
|
scaledSize: new google.maps.Size(24, 32),
|
|
|
|
anchor: new google.maps.Point(12, 32)
|
|
|
|
},
|
2020-05-21 23:43:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
round.realMarker.addListener('click', function () {
|
|
|
|
window.open('https://www.google.com/maps/search/?api=1&query=' + this.getPosition().toUrlValue(), '_blank');
|
|
|
|
});
|
2021-04-03 22:10:21 +02:00
|
|
|
},
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2021-04-03 22:10:21 +02:00
|
|
|
addGuessPositionToResultMap: function (guessPosition, result, hidden) {
|
|
|
|
var round = Game.rounds[Game.rounds.length - 1];
|
|
|
|
var position = round.position;
|
2021-03-19 22:59:09 +01:00
|
|
|
|
2021-04-03 22:10:21 +02:00
|
|
|
var guessMarker = { marker: null, line: null, info: null };
|
|
|
|
var markerSvg = result ? 'marker-gray-empty.svg' : 'marker-blue-empty.svg';
|
|
|
|
var markerLabel = result ? result.userName.charAt(0).toUpperCase() : '?';
|
|
|
|
|
|
|
|
guessMarker.marker = new google.maps.Marker({
|
2020-06-05 00:23:07 +02:00
|
|
|
map: Game.map,
|
2020-05-22 23:22:11 +02:00
|
|
|
visible: !hidden,
|
2020-05-21 23:43:17 +02:00
|
|
|
position: guessPosition,
|
2020-06-05 00:23:07 +02:00
|
|
|
zIndex: Game.rounds.length,
|
2021-04-03 22:10:21 +02:00
|
|
|
clickable: !!result,
|
2020-05-21 23:43:17 +02:00
|
|
|
draggable: false,
|
2020-06-01 20:41:46 +02:00
|
|
|
icon: {
|
2021-04-03 22:10:21 +02:00
|
|
|
url: STATIC_ROOT + '/img/markers/' + markerSvg + '?rev=' + REVISION,
|
2020-06-01 20:41:46 +02:00
|
|
|
size: new google.maps.Size(24, 32),
|
|
|
|
scaledSize: new google.maps.Size(24, 32),
|
|
|
|
anchor: new google.maps.Point(12, 32),
|
|
|
|
labelOrigin: new google.maps.Point(12, 14)
|
|
|
|
},
|
2020-05-21 23:43:17 +02:00
|
|
|
label: {
|
|
|
|
color: '#ffffff',
|
|
|
|
fontFamily: 'Roboto',
|
2020-06-01 20:41:46 +02:00
|
|
|
fontSize: '16px',
|
2020-05-21 23:43:17 +02:00
|
|
|
fontWeight: '500',
|
2021-04-03 22:10:21 +02:00
|
|
|
text: markerLabel
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-03 22:10:21 +02:00
|
|
|
guessMarker.line = new google.maps.Polyline({
|
2020-06-05 00:23:07 +02:00
|
|
|
map: Game.map,
|
2020-05-22 23:22:11 +02:00
|
|
|
visible: !hidden,
|
2020-05-21 23:43:17 +02:00
|
|
|
path: [
|
2020-05-25 19:51:02 +02:00
|
|
|
position,
|
2020-05-21 23:43:17 +02:00
|
|
|
guessPosition
|
|
|
|
],
|
|
|
|
geodesic: true,
|
|
|
|
strokeOpacity: 0,
|
|
|
|
icons: [{
|
|
|
|
icon: {
|
|
|
|
path: 'M 0,-1 0,1',
|
|
|
|
strokeOpacity: 1,
|
|
|
|
strokeWeight: 2,
|
|
|
|
scale: 2
|
|
|
|
},
|
|
|
|
offset: '0',
|
|
|
|
repeat: '10px'
|
|
|
|
}],
|
|
|
|
clickable: false,
|
|
|
|
draggable: false,
|
|
|
|
editable: false
|
|
|
|
});
|
2021-04-03 22:10:21 +02:00
|
|
|
|
|
|
|
if (result) {
|
|
|
|
guessMarker.info = new google.maps.InfoWindow({
|
|
|
|
content: '<p class="small bold">' + result.userName + '</p>' +
|
|
|
|
'<p class="small">' + Util.printDistanceForHuman(result.distance) + ' | ' + result.score + ' points</p>',
|
|
|
|
});
|
|
|
|
|
|
|
|
guessMarker.marker.addListener('click', function () {
|
|
|
|
guessMarker.info.open(Game.map, this);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
round.guessMarkers.push(guessMarker);
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
calculateScoreBarProperties: function (score, maxScore) {
|
|
|
|
var percent = Math.floor((score / maxScore) * 100);
|
2020-05-20 03:19:53 +02:00
|
|
|
|
|
|
|
var color;
|
|
|
|
if (percent >= 90) {
|
|
|
|
color = '#11ca00';
|
|
|
|
} else if (percent >= 10) {
|
|
|
|
color = '#ea9000';
|
|
|
|
} else {
|
|
|
|
color = '#ca1100';
|
|
|
|
}
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
return { width: percent + '%', backgroundColor: color };
|
|
|
|
},
|
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
showSummary: function () {
|
|
|
|
var distanceInfo = document.getElementById('distanceInfo');
|
|
|
|
distanceInfo.children[0].style.display = 'none';
|
2021-04-04 01:07:34 +02:00
|
|
|
distanceInfo.children[1].style.display = 'none';
|
|
|
|
distanceInfo.children[2].style.display = 'block';
|
2020-05-21 23:43:17 +02:00
|
|
|
var scoreInfo = document.getElementById('scoreInfo');
|
|
|
|
scoreInfo.children[0].style.display = 'none';
|
|
|
|
scoreInfo.children[1].style.display = 'block';
|
|
|
|
document.getElementById('showSummaryButton').style.display = null;
|
2021-03-19 22:59:09 +01:00
|
|
|
|
2021-03-20 22:24:47 +01:00
|
|
|
if (!roomId || Game.multi.owner) {
|
2021-03-19 22:59:09 +01:00
|
|
|
document.getElementById('startNewGameButton').style.display = 'block';
|
2021-04-04 18:48:31 +02:00
|
|
|
if (!Game.readyToContinue) {
|
|
|
|
document.getElementById('startNewGameButton').disabled = true;
|
|
|
|
}
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
2020-05-21 23:43:17 +02:00
|
|
|
|
|
|
|
var resultBounds = new google.maps.LatLngBounds();
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
for (var i = 0; i < Game.rounds.length; ++i) {
|
|
|
|
var round = Game.rounds[i];
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-01 20:41:46 +02:00
|
|
|
round.realMarker.setIcon({
|
2020-06-12 20:13:43 +02:00
|
|
|
url: STATIC_ROOT + '/img/markers/marker-green-empty.svg?rev=' + REVISION,
|
2020-06-01 20:41:46 +02:00
|
|
|
size: new google.maps.Size(24, 32),
|
|
|
|
scaledSize: new google.maps.Size(24, 32),
|
|
|
|
anchor: new google.maps.Point(12, 32),
|
|
|
|
labelOrigin: new google.maps.Point(12, 14)
|
|
|
|
});
|
2020-05-22 21:08:36 +02:00
|
|
|
round.realMarker.setLabel({
|
2020-06-01 20:41:46 +02:00
|
|
|
color: '#285624',
|
2020-05-22 21:08:36 +02:00
|
|
|
fontFamily: 'Roboto',
|
|
|
|
fontSize: '16px',
|
|
|
|
fontWeight: '500',
|
2020-05-24 14:47:15 +02:00
|
|
|
text: String(i + 1)
|
2020-05-22 21:08:36 +02:00
|
|
|
});
|
2021-03-19 22:59:09 +01:00
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
round.realMarker.setVisible(true);
|
2020-05-25 19:51:02 +02:00
|
|
|
resultBounds.extend(round.position);
|
2021-04-03 22:10:21 +02:00
|
|
|
|
|
|
|
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());
|
2021-03-19 22:59:09 +01:00
|
|
|
}
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.fitBounds(resultBounds);
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
document.getElementById('scoreSum').innerHTML = String(Game.scoreSum);
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
var scoreBarProperties = Game.calculateScoreBarProperties(Game.scoreSum, Game.NUMBER_OF_ROUNDS * Game.MAX_SCORE);
|
2020-05-21 23:43:17 +02:00
|
|
|
var scoreBar = document.getElementById('scoreBar');
|
|
|
|
scoreBar.style.backgroundColor = scoreBarProperties.backgroundColor;
|
|
|
|
scoreBar.style.width = scoreBarProperties.width;
|
|
|
|
},
|
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
rewriteGoogleLink: function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
if (!Game.googleLink) {
|
2020-05-20 03:19:53 +02:00
|
|
|
var anchors = document.getElementById('panorama').getElementsByTagName('a');
|
|
|
|
for (var i = 0; i < anchors.length; i++) {
|
|
|
|
var a = anchors[i];
|
|
|
|
if (a.href.indexOf('maps.google.com/maps') !== -1) {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.googleLink = a;
|
2020-05-20 03:19:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
setTimeout(function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
if (Game.googleLink) {
|
|
|
|
Game.googleLink.title = 'Google Maps';
|
|
|
|
Game.googleLink.href = 'https://maps.google.com/maps';
|
2020-05-22 23:32:17 +02:00
|
|
|
}
|
2020-05-20 03:19:53 +02:00
|
|
|
}, 1);
|
2021-04-04 13:54:19 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
startCountdown: function (timeout) {
|
|
|
|
if (Game.countdownHandler) {
|
|
|
|
clearInterval(Game.countdownHandler);
|
|
|
|
}
|
|
|
|
|
2021-04-04 23:01:01 +02:00
|
|
|
Game.countdownElement = document.getElementById('countdown');
|
|
|
|
Game.countdownTimeElement = document.getElementById('countdownTime');
|
|
|
|
|
|
|
|
Game.setCountdownTime(Math.round(timeout / 1000));
|
|
|
|
|
2021-04-04 18:48:31 +02:00
|
|
|
if (timeout <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-04 13:54:19 +02:00
|
|
|
Game.timeoutEnd = new Date(new Date().getTime() + timeout);
|
|
|
|
|
|
|
|
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;
|
2020-05-19 19:01:35 +02:00
|
|
|
}
|
2020-05-20 03:19:53 +02:00
|
|
|
};
|
2020-05-19 19:01:35 +02:00
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
var Util = {
|
|
|
|
printDistanceForHuman: function (distance) {
|
|
|
|
if (distance < 1000) {
|
|
|
|
return Number.parseFloat(distance).toFixed(0) + ' m';
|
|
|
|
} else if (distance < 10000) {
|
|
|
|
return Number.parseFloat(distance / 1000).toFixed(2) + ' km';
|
|
|
|
} else if (distance < 100000) {
|
|
|
|
return Number.parseFloat(distance / 1000).toFixed(1) + ' km';
|
|
|
|
} else {
|
|
|
|
return Number.parseFloat(distance / 1000).toFixed(0) + ' km';
|
2020-05-17 19:29:06 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-20 03:19:53 +02:00
|
|
|
};
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2021-03-19 22:59:09 +01:00
|
|
|
MapGuesser.sessionAvailableHooks.reinitializeGame = Game.prepare;
|
2020-06-25 14:02:39 +02:00
|
|
|
|
2020-05-21 03:24:09 +02:00
|
|
|
if (!('ontouchstart' in document.documentElement)) {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.adaptGuess = true;
|
2020-05-21 03:24:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map = new google.maps.Map(document.getElementById('map'), {
|
2020-05-17 19:29:06 +02:00
|
|
|
disableDefaultUI: true,
|
|
|
|
clickableIcons: false,
|
2020-05-22 23:22:11 +02:00
|
|
|
draggingCursor: 'grabbing'
|
2020-05-17 19:29:06 +02:00
|
|
|
});
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.map.addListener('click', function (e) {
|
2021-04-04 18:48:31 +02:00
|
|
|
if (Game.rounds[Game.rounds.length - 1].guessPosition || Game.rounds[Game.rounds.length - 1].position) {
|
2020-05-22 23:22:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
if (Game.guessMarker) {
|
|
|
|
Game.guessMarker.setPosition(e.latLng);
|
2020-05-17 19:29:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.guessMarker = new google.maps.Marker({
|
|
|
|
map: Game.map,
|
2020-05-17 19:29:06 +02:00
|
|
|
position: e.latLng,
|
2020-05-19 16:18:12 +02:00
|
|
|
clickable: false,
|
|
|
|
draggable: true,
|
2020-06-01 20:41:46 +02:00
|
|
|
icon: {
|
2021-04-03 22:10:21 +02:00
|
|
|
url: STATIC_ROOT + '/img/markers/marker-blue-empty.svg?rev=' + REVISION,
|
2020-06-01 20:41:46 +02:00
|
|
|
size: new google.maps.Size(24, 32),
|
|
|
|
scaledSize: new google.maps.Size(24, 32),
|
|
|
|
anchor: new google.maps.Point(12, 32),
|
|
|
|
labelOrigin: new google.maps.Point(12, 14)
|
|
|
|
},
|
2020-05-19 16:18:12 +02:00
|
|
|
label: {
|
|
|
|
color: '#ffffff',
|
|
|
|
fontFamily: 'Roboto',
|
2020-06-01 20:41:46 +02:00
|
|
|
fontSize: '16px',
|
2020-05-19 16:18:12 +02:00
|
|
|
fontWeight: '500',
|
|
|
|
text: '?'
|
|
|
|
}
|
2020-05-17 19:29:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('guessButton').disabled = false;
|
|
|
|
});
|
2020-05-19 16:18:12 +02:00
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panorama = new google.maps.StreetViewPanorama(document.getElementById('panorama'), {
|
2020-05-19 16:18:12 +02:00
|
|
|
disableDefaultUI: true,
|
|
|
|
linksControl: true,
|
2020-05-21 12:17:53 +02:00
|
|
|
showRoadLabels: false,
|
|
|
|
motionTracking: false
|
2020-05-19 16:18:12 +02:00
|
|
|
});
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panorama.addListener('position_changed', function () {
|
|
|
|
Game.rewriteGoogleLink();
|
2020-05-19 16:18:12 +02:00
|
|
|
});
|
|
|
|
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.panorama.addListener('pov_changed', function () {
|
|
|
|
Game.rewriteGoogleLink();
|
2020-05-19 16:18:12 +02:00
|
|
|
});
|
|
|
|
|
2021-03-19 22:59:09 +01:00
|
|
|
if (COOKIES_CONSENT) {
|
|
|
|
Game.prepare();
|
|
|
|
}
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-21 01:59:31 +02:00
|
|
|
document.getElementById('showGuessButton').onclick = function () {
|
|
|
|
this.style.visibility = 'hidden';
|
|
|
|
document.getElementById('guess').style.visibility = 'visible';
|
2021-04-28 17:58:48 +02:00
|
|
|
document.getElementById('navigation').style.visibility = 'hidden';
|
2020-05-21 01:59:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('closeGuessButton').onclick = function () {
|
|
|
|
document.getElementById('showGuessButton').style.visibility = null;
|
|
|
|
document.getElementById('guess').style.visibility = null;
|
2021-04-28 17:58:48 +02:00
|
|
|
document.getElementById('navigation').style.visibility = 'visible';
|
2020-05-21 01:59:31 +02:00
|
|
|
}
|
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
document.getElementById('guessButton').onclick = function () {
|
2021-04-03 13:38:16 +02:00
|
|
|
Game.guess();
|
2020-05-20 03:19:53 +02:00
|
|
|
}
|
2020-05-19 16:18:12 +02:00
|
|
|
|
2020-05-20 03:19:53 +02:00
|
|
|
document.getElementById('continueButton').onclick = function () {
|
2021-03-19 22:59:09 +01:00
|
|
|
if (roomId) {
|
2021-04-04 18:48:31 +02:00
|
|
|
if (!Game.multi.owner || !Game.readyToContinue) {
|
2021-03-19 22:59:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
|
|
|
MapGuesser.httpRequest('POST', '/multiGame/' + roomId + '/nextRound.json', function () {
|
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
2021-03-21 14:37:08 +01:00
|
|
|
|
|
|
|
if (this.response.error) {
|
|
|
|
Game.handleErrorResponse(this.response.error);
|
|
|
|
return;
|
|
|
|
}
|
2021-03-19 22:59:09 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Game.resetRound();
|
|
|
|
}
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
2020-05-19 16:18:12 +02:00
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
document.getElementById('showSummaryButton').onclick = function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
Game.showSummary();
|
2020-05-21 23:43:17 +02:00
|
|
|
}
|
2020-05-17 19:29:06 +02:00
|
|
|
|
2020-05-21 23:43:17 +02:00
|
|
|
document.getElementById('startNewGameButton').onclick = function () {
|
2021-03-19 22:59:09 +01:00
|
|
|
if (roomId) {
|
|
|
|
if (!Game.multi.owner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
|
|
|
MapGuesser.httpRequest('POST', '/multiGame/' + roomId + '/initialData.json', function () {
|
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
2021-03-21 14:37:08 +01:00
|
|
|
|
|
|
|
if (this.response.error) {
|
|
|
|
Game.handleErrorResponse(this.response.error);
|
|
|
|
return;
|
|
|
|
}
|
2021-03-19 22:59:09 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Game.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('startMultiGameButton').onclick = function () {
|
|
|
|
if (!roomId || !Game.multi.owner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-21 12:45:57 +01:00
|
|
|
document.getElementById('multi').style.visibility = 'hidden';
|
2021-03-19 22:59:09 +01:00
|
|
|
|
2021-03-21 14:37:08 +01:00
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
2021-03-19 22:59:09 +01:00
|
|
|
MapGuesser.httpRequest('POST', '/multiGame/' + roomId + '/initialData.json', function () {
|
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
2021-03-21 14:37:08 +01:00
|
|
|
|
|
|
|
if (this.response.error) {
|
|
|
|
Game.handleErrorResponse(this.response.error);
|
|
|
|
return;
|
|
|
|
}
|
2021-03-19 22:59:09 +01:00
|
|
|
});
|
2020-05-20 03:19:53 +02:00
|
|
|
}
|
2021-04-28 18:26:46 +02:00
|
|
|
|
|
|
|
document.getElementById('returnToStart').onclick = function () {
|
|
|
|
Game.loadPano(Game.panoId, Game.pov);
|
|
|
|
}
|
2020-05-20 03:19:53 +02:00
|
|
|
})();
|