2020-05-21 23:43:17 +02:00
|
|
|
'use strict';
|
|
|
|
|
2021-05-18 19:55:05 +02:00
|
|
|
const GameType = Object.freeze({ 'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2 });
|
2021-05-12 13:51:06 +02:00
|
|
|
|
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-05-12 13:51:06 +02:00
|
|
|
type: GameType.SINGLE,
|
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-05-13 19:48:25 +02:00
|
|
|
history: [],
|
2021-05-20 20:55:44 +02:00
|
|
|
restrictions: null,
|
2020-05-20 03:19:53 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-05-18 19:55:05 +02:00
|
|
|
getGameIdentifier: function () {
|
|
|
|
switch (Game.type) {
|
2021-05-12 13:51:06 +02:00
|
|
|
case GameType.SINGLE:
|
|
|
|
return '/game/' + mapId;
|
|
|
|
case GameType.MULTI:
|
|
|
|
return '/multiGame/' + roomId;
|
|
|
|
case GameType.CHALLENGE:
|
|
|
|
return '/challenge/' + challengeToken;
|
|
|
|
default:
|
|
|
|
return '/game/' + mapId;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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-05-12 13:51:06 +02:00
|
|
|
var url = Game.getGameIdentifier() + '/prepare.json';
|
2021-03-19 22:59:09 +01:00
|
|
|
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';
|
2021-05-12 13:51:06 +02:00
|
|
|
MapGuesser.httpRequest('POST', Game.getGameIdentifier() + '/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-05-22 11:34:55 +02:00
|
|
|
Game.loadHistory(this.response);
|
2021-05-13 19:48:25 +02:00
|
|
|
|
2021-05-22 20:54:58 +02:00
|
|
|
Game.restrictions = this.response.restrictions;
|
|
|
|
Game.displayRestrictions();
|
|
|
|
|
2021-05-18 18:06:02 +02:00
|
|
|
if (this.response.finished) {
|
2021-05-13 19:48:25 +02:00
|
|
|
|
2021-05-18 18:06:02 +02:00
|
|
|
Game.transitToResultMap();
|
|
|
|
Game.showSummary();
|
2021-05-18 19:55:05 +02:00
|
|
|
|
2021-05-18 18:06:02 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
Game.panoId = this.response.place.panoId;
|
|
|
|
Game.pov = this.response.place.pov;
|
|
|
|
|
|
|
|
Game.startNewRound();
|
2020-05-25 19:51:02 +02:00
|
|
|
}
|
2020-05-23 01:25:43 +02:00
|
|
|
|
2021-05-18 18:06:02 +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-05-12 21:01:26 +02:00
|
|
|
|
2021-05-20 20:55:44 +02:00
|
|
|
enableRestrictions: function () {
|
|
|
|
if (!Game.restrictions) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Game.panorama.setOptions({
|
|
|
|
clickToGo: !Game.restrictions.noMove,
|
|
|
|
linksControl: !(Game.restrictions.noMove || Game.restrictions.noPan),
|
|
|
|
scrollwheel: !Game.restrictions.noZoom
|
|
|
|
});
|
|
|
|
|
|
|
|
if (Game.restrictions.noPan) {
|
|
|
|
document.getElementById('panningBlockerCover').style.display = 'block';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Game.restrictions.timeLimit) {
|
2021-05-22 11:34:55 +02:00
|
|
|
Game.startCountdown(Game.restrictions.timeLimit, function () {
|
2021-05-20 20:55:44 +02:00
|
|
|
Game.guess();
|
|
|
|
});
|
|
|
|
}
|
2021-05-22 21:17:49 +02:00
|
|
|
|
2021-05-22 20:54:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
displayRestrictions: function () {
|
|
|
|
if (!Game.restrictions) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var restrictionsForDisplay = [];
|
|
|
|
if (Game.restrictions.timeLimit) {
|
|
|
|
restrictionsForDisplay.push('time limit per ' + Game.restrictions.timeLimitType);
|
|
|
|
}
|
|
|
|
if (Game.restrictions.noPan) {
|
|
|
|
restrictionsForDisplay.push('no camera change');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (Game.restrictions.noMove) {
|
|
|
|
restrictionsForDisplay.push('no move');
|
|
|
|
}
|
|
|
|
if (Game.restrictions.noZoom) {
|
|
|
|
restrictionsForDisplay.push('no zoom');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-22 21:00:54 +02:00
|
|
|
if (restrictionsForDisplay.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-22 20:54:58 +02:00
|
|
|
// create restrictions span for header
|
|
|
|
var restrictions = document.createElement('span');
|
|
|
|
restrictions.setAttribute('id', 'restrictions');
|
|
|
|
restrictions.setAttribute('class', 'hideOnNarrowScreen');
|
|
|
|
var restrictionsTitle = document.createElement('span');
|
|
|
|
restrictionsTitle.setAttribute('class', 'bold');
|
|
|
|
restrictionsTitle.innerText = 'Restrictions: ';
|
|
|
|
var restrictionsList = document.createElement('span');
|
|
|
|
restrictionsList.innerText = restrictionsForDisplay.join(', ');
|
|
|
|
restrictions.appendChild(restrictionsTitle);
|
|
|
|
restrictions.appendChild(restrictionsList);
|
|
|
|
|
|
|
|
var roundContainer = document.getElementById('roundContainer');
|
|
|
|
var header = roundContainer.parentNode;
|
|
|
|
header.insertBefore(restrictions, roundContainer);
|
2021-05-20 20:55:44 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
disableRestrictions: function () {
|
2021-05-22 11:34:55 +02:00
|
|
|
|
2021-05-20 20:55:44 +02:00
|
|
|
Game.panorama.setOptions({
|
|
|
|
clickToGo: true,
|
|
|
|
linksControl: true,
|
|
|
|
scrollwheel: true
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('panningBlockerCover').style.display = null;
|
|
|
|
|
|
|
|
Game.startCountdown(0);
|
2021-05-20 21:32:01 +02:00
|
|
|
Game.timeoutEnd = null;
|
2021-05-20 20:55:44 +02:00
|
|
|
},
|
|
|
|
|
2021-05-22 21:17:49 +02:00
|
|
|
hideRestrictions: function () {
|
2021-05-22 20:54:58 +02:00
|
|
|
var restrictions = document.getElementById('restrictions');
|
|
|
|
if (restrictions) {
|
|
|
|
var header = restrictions.parentNode;
|
|
|
|
header.removeChild(restrictions);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-05-18 19:55:05 +02:00
|
|
|
transitToResultMap: function () {
|
2021-05-18 18:06:02 +02:00
|
|
|
// TODO: refactor - it is necessary for mobile
|
|
|
|
if (window.getComputedStyle(document.getElementById('guess')).visibility === 'hidden') {
|
|
|
|
document.getElementById('showGuessButton').click();
|
|
|
|
}
|
2021-05-12 21:01:26 +02:00
|
|
|
|
2021-05-18 18:06:02 +02:00
|
|
|
if (Game.adaptGuess) {
|
|
|
|
document.getElementById('guess').classList.remove('adapt');
|
|
|
|
}
|
2021-05-12 21:01:26 +02:00
|
|
|
|
2021-05-18 18:06:02 +02:00
|
|
|
if (Game.guessMarker) {
|
|
|
|
Game.guessMarker.setMap(null);
|
|
|
|
Game.guessMarker = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('guess').classList.add('result');
|
|
|
|
|
|
|
|
Game.map.setOptions({
|
|
|
|
draggableCursor: 'grab'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (Game.rounds.length === Game.NUMBER_OF_ROUNDS) {
|
|
|
|
document.getElementById('continueButton').style.display = 'none';
|
|
|
|
document.getElementById('showSummaryButton').style.display = 'block';
|
|
|
|
} else if (Game.type == GameType.MULTI) {
|
|
|
|
if (Game.multi.owner) {
|
|
|
|
if (!Game.readyToContinue) {
|
|
|
|
document.getElementById('continueButton').disabled = true;
|
2021-05-12 21:01:26 +02:00
|
|
|
}
|
2021-05-18 18:06:02 +02:00
|
|
|
} else {
|
|
|
|
document.getElementById('continueButton').style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-05-12 21:01:26 +02:00
|
|
|
|
2021-05-22 11:34:55 +02:00
|
|
|
loadHistory: function (response) {
|
|
|
|
if (!response.history)
|
2021-05-18 18:06:02 +02:00
|
|
|
return;
|
2021-05-12 21:01:26 +02:00
|
|
|
|
2021-05-22 11:34:55 +02:00
|
|
|
Game.history = response.history;
|
2021-05-12 21:01:26 +02:00
|
|
|
|
2021-05-18 18:06:02 +02:00
|
|
|
for (var i = 0; i < Game.rounds.length; ++i) {
|
|
|
|
var round = Game.rounds[i];
|
2021-05-13 13:06:24 +02:00
|
|
|
|
2021-05-18 18:06:02 +02:00
|
|
|
if (round.realMarker) {
|
|
|
|
round.realMarker.setMap(null);
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
2021-05-12 21:01:26 +02:00
|
|
|
}
|
2021-05-18 18:06:02 +02:00
|
|
|
}
|
|
|
|
Game.rounds = [];
|
2021-05-12 21:01:26 +02:00
|
|
|
|
2021-05-21 15:40:43 +02:00
|
|
|
Game.scoreSum = 0;
|
2021-05-18 18:06:02 +02:00
|
|
|
for (var i = 0; i < Game.history.length; ++i) {
|
|
|
|
var round = Game.history[i];
|
2021-05-12 21:01:26 +02:00
|
|
|
|
2021-05-18 18:06:02 +02:00
|
|
|
if (round.result) {
|
|
|
|
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
|
|
|
|
Game.addPositionToResultMap(true);
|
|
|
|
if (round.result.guessPosition) {
|
2021-05-21 14:44:28 +02:00
|
|
|
Game.addGuessPositionToResultMap(round.result.guessPosition, round.result, true);
|
2021-05-18 18:06:02 +02:00
|
|
|
}
|
|
|
|
Game.scoreSum += round.result.score;
|
2021-04-04 20:52:28 +02:00
|
|
|
|
2021-05-18 19:55:05 +02:00
|
|
|
|
|
|
|
if (round.allResults !== undefined) {
|
2021-05-18 18:06:02 +02:00
|
|
|
for (var j = 0; j < round.allResults.length; ++j) {
|
|
|
|
var result = round.allResults[j];
|
|
|
|
if (result.guessPosition) {
|
|
|
|
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
2021-05-22 11:34:55 +02:00
|
|
|
document.getElementById('summaryInfo').innerHTML = "Game finished."
|
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';
|
|
|
|
|
2021-05-20 20:55:44 +02:00
|
|
|
Game.disableRestrictions();
|
2021-05-22 20:54:58 +02:00
|
|
|
Game.hideRestrictions();
|
2021-05-20 20:55:44 +02:00
|
|
|
|
2021-05-19 21:16:59 +02:00
|
|
|
document.getElementById('panningBlockerCover').style.display = null;
|
|
|
|
|
2021-05-22 11:34:55 +02:00
|
|
|
Game.history = [];
|
|
|
|
|
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);
|
2021-04-28 18:26:46 +02:00
|
|
|
|
2021-04-28 20:33:17 +02:00
|
|
|
// update the compass
|
|
|
|
const heading = Game.panorama.getPov().heading;
|
2021-04-29 09:18:24 +02:00
|
|
|
document.getElementById("compass").style.transform = "translateY(-50%) rotate(" + heading + "deg)";
|
2021-05-20 20:55:44 +02:00
|
|
|
|
|
|
|
Game.enableRestrictions();
|
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;
|
|
|
|
|
2021-05-08 18:03:17 +02:00
|
|
|
case 'game_not_found':
|
2021-05-18 19:55:05 +02:00
|
|
|
MapGuesser.showModalWithContent('Error', 'The game was not found by this ID. Please check the link.');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'anonymous_user':
|
|
|
|
MapGuesser.showModalWithContent('Error', 'You have to login to join a challenge!');
|
2021-05-08 18:03:17 +02:00
|
|
|
break;
|
|
|
|
|
2021-03-21 14:37:08 +01:00
|
|
|
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) {
|
2021-05-21 14:44:28 +02:00
|
|
|
Game.addGuessPositionToResultMap(guessPosition, result);
|
2021-04-04 01:07:34 +02:00
|
|
|
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-05-18 19:55:05 +02:00
|
|
|
|
2021-05-18 18:06:02 +02:00
|
|
|
Game.transitToResultMap();
|
2021-04-04 23:40:27 +02:00
|
|
|
|
2021-04-04 01:07:34 +02:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2021-04-03 13:38:16 +02:00
|
|
|
guess: function () {
|
2020-06-05 00:23:07 +02:00
|
|
|
|
2021-05-20 20:55:44 +02:00
|
|
|
var data = new FormData();
|
2020-05-21 23:43:17 +02:00
|
|
|
|
2021-05-20 21:32:01 +02:00
|
|
|
if (Game.timeoutEnd) {
|
|
|
|
var timeLeft = Math.ceil((Game.timeoutEnd - new Date()) / 1000);
|
|
|
|
data.append('timeLeft', timeLeft);
|
|
|
|
}
|
2021-05-22 11:34:55 +02:00
|
|
|
|
2021-05-20 21:32:01 +02:00
|
|
|
Game.disableRestrictions();
|
|
|
|
|
2021-05-20 20:55:44 +02:00
|
|
|
if (Game.guessMarker) {
|
|
|
|
var guessPosition = Game.guessMarker.getPosition().toJSON();
|
|
|
|
Game.rounds[Game.rounds.length - 1].guessPosition = guessPosition;
|
2020-05-22 01:31:32 +02:00
|
|
|
|
2021-05-20 20:55:44 +02:00
|
|
|
data.append('lat', String(guessPosition.lat));
|
|
|
|
data.append('lng', String(guessPosition.lng));
|
|
|
|
}
|
2020-05-26 23:23:49 +02:00
|
|
|
|
2021-05-20 20:55:44 +02:00
|
|
|
document.getElementById('guessButton').disabled = true;
|
|
|
|
document.getElementById('panoCover').style.visibility = 'visible';
|
2021-03-21 14:37:08 +01:00
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
2021-05-12 21:01:26 +02:00
|
|
|
var url = Game.getGameIdentifier() + '/guess.json';
|
2021-05-20 20:55:44 +02:00
|
|
|
|
2021-03-19 22:59:09 +01:00
|
|
|
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-05-22 11:34:55 +02:00
|
|
|
Game.loadHistory(this.response);
|
2021-05-20 20:55:44 +02:00
|
|
|
Game.restrictions = this.response.restrictions;
|
2021-05-13 19:48:25 +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
|
|
|
}
|
2021-05-13 19:48:25 +02: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 };
|
2021-05-21 14:44:28 +02:00
|
|
|
var markerSvg = result && result.userName ? 'marker-gray-empty.svg' : 'marker-blue-empty.svg';
|
|
|
|
var markerLabel = result && result.userName ? result.userName.charAt(0).toUpperCase() : '?';
|
2021-04-03 22:10:21 +02:00
|
|
|
|
|
|
|
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) {
|
2021-05-21 14:44:28 +02:00
|
|
|
const userName = result.userName ? result.userName : 'me';
|
2021-04-03 22:10:21 +02:00
|
|
|
guessMarker.info = new google.maps.InfoWindow({
|
2021-05-21 14:44:28 +02:00
|
|
|
content: '<p class="small bold">' + userName + '</p>' +
|
2021-04-03 22:10:21 +02:00
|
|
|
'<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 };
|
|
|
|
},
|
|
|
|
|
2021-05-22 11:34:55 +02:00
|
|
|
calculateHighScores: function () {
|
|
|
|
|
|
|
|
var highscores = new Map();
|
|
|
|
highscores.set('me', Game.scoreSum);
|
|
|
|
|
2021-05-26 08:16:32 +02:00
|
|
|
// collect the results of users who are through the last round
|
|
|
|
const round = Game.history[Game.history.length - 1];
|
|
|
|
if (round.allResults) {
|
|
|
|
for (const result of round.allResults) {
|
|
|
|
highscores.set(result.userName, result.score);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add up scores only for the finishers
|
|
|
|
for (var i = Game.history.length - 2; i >= 0; --i) {
|
2021-05-22 11:34:55 +02:00
|
|
|
const round = Game.history[i];
|
|
|
|
if (round.allResults) {
|
|
|
|
for (const result of round.allResults) {
|
2021-05-26 08:16:32 +02:00
|
|
|
if (highscores.has(result.userName)) {
|
|
|
|
highscores.set(result.userName, highscores.get(result.userName) + result.score);
|
2021-05-22 11:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var sortedHighscores = Array.from(highscores, ([userName, score]) => ({ 'userName': userName, 'score': score }))
|
|
|
|
.sort(function (resultA, resultB) { return resultB.score - resultA.score });
|
|
|
|
return sortedHighscores;
|
|
|
|
},
|
|
|
|
|
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-05-18 20:22:43 +02:00
|
|
|
if (Game.type == GameType.SINGLE || 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-05-18 20:22:43 +02:00
|
|
|
} else if (Game.type == GameType.CHALLENGE) {
|
|
|
|
document.getElementById('goToStart').style.display = 'block';
|
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;
|
2021-05-22 11:34:55 +02:00
|
|
|
|
2021-05-22 20:54:58 +02:00
|
|
|
Game.showHighscores();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2021-05-22 21:17:49 +02:00
|
|
|
showHighscores: function () {
|
2021-05-22 20:54:58 +02:00
|
|
|
|
2021-05-22 11:34:55 +02:00
|
|
|
if (Game.type == GameType.CHALLENGE) {
|
|
|
|
var highscores = this.calculateHighScores();
|
|
|
|
var summaryInfo = document.getElementById('summaryInfo');
|
|
|
|
|
|
|
|
if (highscores.length > 2) {
|
|
|
|
var table = document.getElementById('highscoresTable');
|
|
|
|
for (const result of highscores) {
|
|
|
|
var userName = document.createElement('td');
|
|
|
|
userName.innerHTML = result.userName;
|
|
|
|
var score = document.createElement('td');
|
|
|
|
score.innerHTML = result.score;
|
|
|
|
var line = document.createElement('tr');
|
|
|
|
line.appendChild(userName);
|
|
|
|
line.appendChild(score);
|
|
|
|
table.appendChild(line);
|
|
|
|
|
|
|
|
if (result.userName === 'me') {
|
|
|
|
line.setAttribute('class', 'ownPlayer');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MapGuesser.showModal('highscores');
|
|
|
|
} else if (highscores.length == 2) {
|
|
|
|
|
|
|
|
if (highscores[0].userName === 'me') {
|
2021-05-22 20:54:58 +02:00
|
|
|
summaryInfo.innerHTML = 'You won! <span class="hideOnNarrowScreen">' + highscores[1].userName + ' got only ' + highscores[1].score + ' points.</span>';
|
2021-05-22 11:34:55 +02:00
|
|
|
} else {
|
2021-05-22 20:54:58 +02:00
|
|
|
summaryInfo.innerHTML = 'You lost! <span class="hideOnNarrowScreen">' + highscores[0].userName + ' won with ' + highscores[0].score + ' points.</span>';
|
2021-05-22 11:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (highscores.length == 1) {
|
2021-05-22 20:54:58 +02:00
|
|
|
summaryInfo.innerHTML = 'You are the first to finish. <span class="hideOnNarrowScreen">Invite your friends by sending them the link.</span>'
|
2021-05-22 11:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-05-21 23:43:17 +02:00
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2021-05-20 20:55:44 +02:00
|
|
|
startCountdown: function (timeout, timedOutHandler) {
|
2021-04-04 13:54:19 +02:00
|
|
|
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) {
|
2021-05-20 20:55:44 +02:00
|
|
|
if (typeof timedOutHandler === 'function') {
|
|
|
|
timedOutHandler();
|
|
|
|
} else {
|
|
|
|
document.getElementById('panoCover').style.visibility = 'visible';
|
|
|
|
}
|
|
|
|
|
2021-04-04 13:54:19 +02:00
|
|
|
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();
|
2021-04-28 20:33:17 +02:00
|
|
|
|
|
|
|
const heading = Game.panorama.getPov().heading;
|
2021-04-29 09:18:24 +02:00
|
|
|
document.getElementById("compass").style.transform = "translateY(-50%) rotate(" + heading + "deg)";
|
2020-05-19 16:18:12 +02:00
|
|
|
});
|
|
|
|
|
2021-05-18 19:55:05 +02:00
|
|
|
if (roomId !== null) {
|
2021-05-12 13:51:06 +02:00
|
|
|
Game.type = GameType.MULTI;
|
2021-05-18 19:55:05 +02:00
|
|
|
} else if (challengeToken !== null) {
|
2021-05-12 13:51:06 +02:00
|
|
|
Game.type = GameType.CHALLENGE;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2021-04-29 12:39:44 +02:00
|
|
|
|
|
|
|
document.getElementById('compassContainer').onclick = function () {
|
|
|
|
Game.panorama.setPov({ heading: 0, pitch: Game.panorama.getPov().pitch });
|
|
|
|
}
|
2021-05-22 11:34:55 +02:00
|
|
|
|
|
|
|
document.getElementById('closeHighscoresButton').onclick = function () {
|
|
|
|
MapGuesser.hideModal();
|
|
|
|
};
|
2020-05-20 03:19:53 +02:00
|
|
|
})();
|