MAPG-235 challengeInitialData implemented and first round is loaded

This commit is contained in:
balazs committed 2021-05-12 15:34:15 +02:00
1 parent d7147b30d6
commit 5daed10036
5 files changed
+77 -2

No files matched your search

+55
View File
@@ -6,10 +6,13 @@ use MapGuesser\Util\Geo\Position;
use MapGuesser\Response\JsonContent;
use MapGuesser\Interfaces\Response\IContent;
use MapGuesser\Multi\MultiConnector;
use MapGuesser\PersistentData\Model\UserInChallenge;
use MapGuesser\PersistentData\PersistentDataManager;
use MapGuesser\PersistentData\Model\UserPlayedPlace;
use MapGuesser\Repository\ChallengeRepository;
use MapGuesser\Repository\MultiRoomRepository;
use MapGuesser\Repository\PlaceRepository;
use MapGuesser\Repository\UserInChallengeRepository;
use MapGuesser\Repository\UserPlayedPlaceRepository;
class GameFlowController
@@ -29,6 +32,10 @@ class GameFlowController
private UserPlayedPlaceRepository $userPlayedPlaceRepository;
private ChallengeRepository $challengeRepository;
private UserInChallengeRepository $userInChallengeRepository;
public function __construct(IRequest $request)
{
$this->request = $request;
@@ -37,6 +44,8 @@ class GameFlowController
$this->multiRoomRepository = new MultiRoomRepository();
$this->placeRepository = new PlaceRepository();
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
$this->challengeRepository = new ChallengeRepository();
$this->userInChallengeRepository = new UserInChallengeRepository();
}
public function initialData(): IContent
@@ -115,6 +124,52 @@ class GameFlowController
return new JsonContent(['ok' => true]);
}
public function challengeInitialData(): IContent
{
// TODO
$session = $this->request->session();
$userId = $session->get('userId');
$challengeToken_str = $this->request->query('challengeToken');
$challenge = $this->challengeRepository->getByTokenStr($challengeToken_str);
if (!isset($challenge)) {
return new JsonContent(['error' => 'game_not_found']);
}
$userInChallenge = $this->userInChallengeRepository->getByUserIdAndChallenge($userId, $challenge);
$currentRound = $userInChallenge->getRound();
$currentPlace = $this->placeRepository->getCurrentInChallenge($challenge, $currentRound);
$response = [];
// $last = $state['rounds'][$state['currentRound']];
// $response['place'] = [
// 'panoId' => $last['panoId'],
// 'pov' => $last['pov']->toArray()
// ];
$response['place'] = [
'panoId' => $currentPlace->getPanoIdCached(),
'pov' => [$currentPlace->getPov()->toArray()]
];
$response['history'] = [];
// for ($i = 0; $i < $state['currentRound']; ++$i) {
// $round = $state['rounds'][$i];
// $response['history'][] = [
// 'position' => $round['position']->toArray(),
// 'result' => [
// 'guessPosition' => $round['guessPosition']->toArray(),
// 'distance' => $round['distance'],
// 'score' => $round['score']
// ]
// ];
// }
return new JsonContent($response);
}
public function guess(): IContent
{
$mapId = (int) $this->request->query('mapId');