request = $request; $this->mapRepository = new MapRepository(); } public function getGame(): IContent { $mapId = (int) $this->request->query('mapId'); return new HtmlContent('game', $this->prepareGame($mapId)); } public function getGameJson(): IContent { $mapId = (int) $this->request->query('mapId'); return new JsonContent($this->prepareGame($mapId)); } private function prepareGame(int $mapId): array { $map = $this->mapRepository->getById($mapId); $session = $this->request->session(); if (!($state = $session->get('state')) || $state['mapId'] !== $mapId) { $session->set('state', [ 'mapId' => $mapId, 'area' => $map->getArea(), 'rounds' => [], 'currentRound' => -1 ]); } return ['mapId' => $mapId, 'mapName' => $map->getName(), 'bounds' => $map->getBounds()->toArray()]; } }