feature/MAPG-235-basic-challenge-mode #48
@ -13,7 +13,7 @@ CREATE TABLE `user_in_challenge` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(10) unsigned NOT NULL,
|
||||
`challenge_id` int(10) unsigned NOT NULL,
|
||||
`round` smallint(5) signed NOT NULL DEFAULT -1,
|
||||
`round` smallint(5) signed NOT NULL DEFAULT 0,
|
||||
`score` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`time_left` int(10) unsigned,
|
||||
`is_owner` tinyint(1) NOT NULL DEFAULT 0,
|
||||
|
@ -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');
|
||||
|
@ -16,7 +16,7 @@ class UserInChallenge extends Model
|
||||
|
||||
private ?int $challengeId = null;
|
||||
|
||||
private int $round = -1;
|
||||
private int $round = 0;
|
||||
|
||||
private int $score = 0;
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use Generator;
|
||||
use MapGuesser\Database\Query\Select;
|
||||
use MapGuesser\PersistentData\Model\Challenge;
|
||||
use MapGuesser\PersistentData\Model\Map;
|
||||
use MapGuesser\PersistentData\Model\Place;
|
||||
use MapGuesser\PersistentData\PersistentDataManager;
|
||||
@ -176,5 +177,15 @@ class PlaceRepository
|
||||
|
||||
return $places;
|
||||
}
|
||||
|
||||
public function getCurrentInChallenge(Challenge $challenge, int $round): ?Place
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->innerJoin('place_in_challenge', ['places', 'id'], '=', ['place_in_challenge', 'place_id']);
|
||||
$select->orderBy('order');
|
||||
$select->limit(1, $round);
|
||||
|
||||
return $this->pdm->selectFromDb($select, Place::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,6 +32,15 @@ class UserInChallengeRepository
|
||||
yield from $this->pdm->selectMultipleFromDb($select, UserInChallenge::class);
|
||||
}
|
||||
|
||||
public function getByUserIdAndChallenge(int $userId, Challenge $challenge): ?UserInChallenge
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('user_id', '=', $userId);
|
||||
$select->where('challenge_id', '=', $challenge->getId());
|
||||
|
||||
return $this->pdm->selectFromDb($select, UserInChallenge::class);
|
||||
}
|
||||
|
||||
public function isUserParticipatingInChallenge(int $userId, Challenge $challenge): bool
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection, 'user_in_challenge');
|
||||
|
Loading…
Reference in New Issue
Block a user