MAPG-235 fixed sending history to initializer and fixed pov data format

This commit is contained in:
balazs committed 2021-05-17 21:30:07 +02:00
1 parent 45ddb7f56a
commit 30f4b7ad19
3 files changed
+38 -28

No files matched your search

+37 -25
View File
@@ -141,42 +141,54 @@ class GameFlowController
return new JsonContent(['ok' => true]);
}
private function prepareChallengeResponse(int $userId, Challenge $challenge, int $currentRound): array
private function prepareChallengeResponse(int $userId, Challenge $challenge, int $currentRound, bool $withHistory = false): array
{
$allGuessesInChallenge = iterator_to_array($this->guessRepository->getAllInChallenge($challenge));
foreach ($allGuessesInChallenge as $guess) {
$round = $guess->getPlaceInChallenge()->getRound();
if ($guess->getUser()->getId() === $userId) {
$response['history'][$round]['position'] =
$guess->getPlaceInChallenge()->getPlace()->getPosition()->toArray();
$response['history'][$round]['result'] = [
$currentPlace = $this->placeRepository->getByRoundInChallenge($challenge, $currentRound);
if (!isset($currentPlace) || $withHistory) {
foreach ($this->guessRepository->getAllInChallenge($challenge) as $guess) {
$round = $guess->getPlaceInChallenge()->getRound();
if ($guess->getUser()->getId() === $userId) {
$response['history'][$round]['position'] =
$guess->getPlaceInChallenge()->getPlace()->getPosition()->toArray();
$response['history'][$round]['result'] = [
'guessPosition' => $guess->getPosition()->toArray(),
'distance' => $guess->getDistance(),
'score' => $guess->getScore()
];
} else {
$response['history'][$round]['allResults'][] = [
'userName' => $guess->getUser()->getDisplayName(),
'guessPosition' => $guess->getPosition()->toArray(),
'distance' => $guess->getDistance(),
'score' => $guess->getScore()
];
} else {
$response['history'][$round]['allResults'][] = [
'userName' => $guess->getUser()->getDisplayName(),
'guessPosition' => $guess->getPosition()->toArray(),
'distance' => $guess->getDistance(),
'score' => $guess->getScore()
];
];
}
}
}
$currentPlace = $this->placeRepository->getByRoundInChallenge($challenge, $currentRound);
if(!isset($currentPlace)) { // game finished
if (!isset($currentPlace)) { // game finished
$response['finished'] = true;
} else { // continue game
$response['place'] = [
'panoId' => $currentPlace->getPanoIdCached(),
'pov' => [$currentPlace->getPov()->toArray()]
'pov' => $currentPlace->getPov()->toArray()
];
$prevRound = $currentRound - 1;
if ($prevRound >= 0) {
foreach ($this->guessRepository->getAllInChallengeByRound($prevRound, $challenge) as $guess) {
if ($guess->getUser()->getId() != $userId) {
$response['allResults'][] = [
'userName' => $guess->getUser()->getDisplayName(),
'guessPosition' => $guess->getPosition()->toArray(),
'distance' => $guess->getDistance(),
'score' => $guess->getScore()
];
}
}
}
}
return $response;
@@ -196,7 +208,7 @@ class GameFlowController
$challenge = $userInChallenge->getChallenge();
$currentRound = $userInChallenge->getCurrentRound();
$response = $this->prepareChallengeResponse($userId, $challenge, $currentRound);
$response = $this->prepareChallengeResponse($userId, $challenge, $currentRound, true);
return new JsonContent($response);
}