feature/MAPG-235-basic-challenge-mode #48

Merged
balazs merged 43 commits from feature/MAPG-235-basic-challenge-mode into develop 2021-05-28 20:41:09 +02:00
3 changed files with 148 additions and 11 deletions
Showing only changes of commit 69964acfb2 - Show all commits

View File

@ -19,6 +19,7 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
guessMarker: null, guessMarker: null,
adaptGuess: false, adaptGuess: false,
googleLink: null, googleLink: null,
history: [],
readyToContinue: true, readyToContinue: true,
timeoutEnd: null, timeoutEnd: null,
@ -294,12 +295,23 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
return; return;
} }
Game.history = this.response.history;
for (var i = 0; i < this.response.history.length; ++i) { for (var i = 0; i < this.response.history.length; ++i) {
var round = this.response.history[i]; var round = this.response.history[i];
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] }); Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
Game.addPositionToResultMap(true); Game.addPositionToResultMap(true);
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true); if (round.result.guessPosition) {
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
}
Game.scoreSum += round.result.score; Game.scoreSum += round.result.score;
for (var j = 0; j < round.allResults.length; ++j) {
var result = round.allResults[j];
if (result.guessPosition) {
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
}
}
} }
if (this.response.finished) { if (this.response.finished) {
@ -598,12 +610,57 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
return; return;
} }
Game.history = this.response.history;
Game.receiveResult(this.response.position, guessPosition, this.response.result, this.response.allResults); Game.receiveResult(this.response.position, guessPosition, this.response.result, this.response.allResults);
if (this.response.place) { if (this.response.place) {
Game.panoId = this.response.place.panoId; Game.panoId = this.response.place.panoId;
Game.pov = this.response.place.pov; Game.pov = this.response.place.pov;
} }
// if(this.response.history) {
// // game finished
// // delete everything but the last round
// for (var i = 0; i < Game.rounds.length -1; ++i) {
// var round = Game.rounds[i];
// 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();
// }
// }
// }
// // Game.rounds = [];
// for (var i = 0; i < this.response.history.length; ++i) {
// var round = this.response.history[i];
// Game.rounds[i] = { 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];
// if (result.guessPosition) {
// Game.addGuessPositionToResultMap(result.guessPosition, result, true);
// }
// }
// }
// }
}, data); }, data);
}, },
@ -717,6 +774,41 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
}, },
showSummary: function () { showSummary: function () {
for (var i = 0; i < Game.rounds.length; ++i) {
var round = Game.rounds[i];
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();
}
}
}
Game.rounds = [];
for (var i = 0; i < Game.history.length; ++i) {
var round = Game.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];
if (result.guessPosition) {
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
}
}
}
var distanceInfo = document.getElementById('distanceInfo'); var distanceInfo = document.getElementById('distanceInfo');
distanceInfo.children[0].style.display = 'none'; distanceInfo.children[0].style.display = 'none';
distanceInfo.children[1].style.display = 'none'; distanceInfo.children[1].style.display = 'none';

View File

@ -160,19 +160,34 @@ class GameFlowController
$response['history'] = []; $response['history'] = [];
$guesses = iterator_to_array($this->guessRepository->getAllInChallengeByUser($userId, $challenge)); $guessesByUser = iterator_to_array($this->guessRepository->getAllInChallengeByUser($userId, $challenge));
$places = iterator_to_array($this->placeRepository->getAllInChallenge($challenge)); $places = iterator_to_array($this->placeRepository->getAllInChallenge($challenge));
for($i = 0; $i < $currentRound; ++$i) {
for($i = 0; $i < $currentRound; ++$i)
{
$response['history'][] = [ $response['history'][] = [
'position' => $places[$i]->getPosition()->toArray(), 'position' => $places[$i]->getPosition()->toArray(),
'result' => [ 'result' => [
'guessPosition' => $guesses[$i]->getPosition()->toArray(), 'guessPosition' => $guessesByUser[$i]->getPosition()->toArray(),
'distance' => $guesses[$i]->getDistance(), 'distance' => $guessesByUser[$i]->getDistance(),
'score' => $guesses[$i]->getScore() 'score' => $guessesByUser[$i]->getScore()
] ],
'allResults' => []
]; ];
foreach($this->guessRepository->getAllInChallengeByRound($i, $challenge) as $guess) {
if($guess->getUserId() != $userId) {
$user = $this->userRepository->getByGuess($guess);
$response['history'][$i]['allResults'][] = [
'userName' => $user->getDisplayName(),
'guessPosition' => $guess->getPosition()->toArray(),
'distance' => $guess->getDistance(),
'score' => $guess->getScore()
];
}
}
} }
if(!isset($currentPlace)) { // game finished if(!isset($currentPlace)) { // game finished
@ -347,11 +362,40 @@ class GameFlowController
'panoId' => $nextPlace->getPanoIdCached(), 'panoId' => $nextPlace->getPanoIdCached(),
'pov' => $nextPlace->getPov()->toArray() 'pov' => $nextPlace->getPov()->toArray()
]; ];
} else {
$guessesByUser = iterator_to_array($this->guessRepository->getAllInChallengeByUser($userId, $challenge));
$places = iterator_to_array($this->placeRepository->getAllInChallenge($challenge));
for($i = 0; $i < $nextRound; ++$i) {
$response['history'][] = [
'position' => $places[$i]->getPosition()->toArray(),
'result' => [
'guessPosition' => $guessesByUser[$i]->getPosition()->toArray(),
'distance' => $guessesByUser[$i]->getDistance(),
'score' => $guessesByUser[$i]->getScore()
],
'allResults' => []
];
foreach($this->guessRepository->getAllInChallengeByRound($i, $challenge) as $guess) {
// if($guess->getUserId() != $userId) {
$user = $this->userRepository->getByGuess($guess);
$response['history'][$i]['allResults'][] = [
'userName' => $user->getDisplayName(),
'guessPosition' => $guess->getPosition()->toArray(),
'distance' => $guess->getDistance(),
'score' => $guess->getScore()
];
// }
}
}
} }
$this->saveVisit($currentPlace->getId()); $this->saveVisit($currentPlace->getId());
return new JsonContent($response); return new JsonContent($response);

View File

@ -55,6 +55,7 @@ class GuessRepository
$select = new Select(\Container::$dbConnection); $select = new Select(\Container::$dbConnection);
$select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']); $select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']);
$select->where('challenge_id', '=', $challenge->getId()); $select->where('challenge_id', '=', $challenge->getId());
$select->orderBy('order');
yield from $this->pdm->selectMultipleFromDb($select, Guess::class); yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
} }