Trying to add waiting pages
This commit is contained in:
@@ -4,9 +4,14 @@ declare(strict_types=1);
|
||||
namespace App\Game\Controller;
|
||||
|
||||
use App\Game\Entity\Session;
|
||||
use App\Game\Entity\SessionSetting;
|
||||
use App\Game\Enum\SessionSettingType;
|
||||
use App\Game\Enum\SessionStatus;
|
||||
use App\Game\Repository\GameRepository;
|
||||
use App\Game\Repository\PlayerRepository;
|
||||
use App\Game\Repository\SessionRepository;
|
||||
use App\Game\Service\GameDashboardService;
|
||||
use App\Tech\Entity\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -14,9 +19,16 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
|
||||
final class GameController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
#[Autowire('%env(MERCURE_PUBLIC_URL)%')]
|
||||
private string $mercurePublicUrl
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(path: '', name: 'game_dashboard', methods: ['GET', 'POST'])]
|
||||
#[IsGranted(new Expression("is_granted('ROLE_PLAYER') or is_granted('ROLE_ADMIN')"))]
|
||||
public function dashboard(
|
||||
@@ -92,17 +104,48 @@ final class GameController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/{session}', name: 'game')]
|
||||
#[Route(path: '/{session}', name: 'game', methods: ['GET', 'POST'])]
|
||||
#[IsGranted(new Expression("is_granted('ROLE_PLAYER') or is_granted('ROLE_ADMIN')"))]
|
||||
#[IsGranted('SESSION_VIEW', subject: 'session')]
|
||||
public function index(
|
||||
Session $session,
|
||||
Request $request,
|
||||
Security $security,
|
||||
\App\Game\Repository\PlayerRepository $playerRepository
|
||||
PlayerRepository $playerRepository,
|
||||
GameDashboardService $dashboardService
|
||||
): Response
|
||||
{
|
||||
$user = $security->getUser();
|
||||
if (!$user instanceof User) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
$player = $playerRepository->findOneBy(['session' => $session, 'user' => $user]);
|
||||
|
||||
if ($request->isMethod('POST') && $request->request->has('toggle_ready')) {
|
||||
$dashboardService->toggleReady($session, $user);
|
||||
return $this->redirectToRoute('game', ['session' => $session->getId()]);
|
||||
}
|
||||
|
||||
// Periodically check readiness timeout
|
||||
$dashboardService->checkAllPlayersReady($session);
|
||||
|
||||
if ($session->getStatus() === SessionStatus::READY) {
|
||||
$isReady = false;
|
||||
if ($player) {
|
||||
$settingName = SessionSettingType::tryFrom('ReadyAtForPlayer' . $player->getScreen());
|
||||
if ($settingName) {
|
||||
$isReady = $session->getSettings()->exists(fn($i, SessionSetting $s) => $s->getName() === $settingName && $s->getPlayer() === $player);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('game/waiting.html.twig', [
|
||||
'session' => $session,
|
||||
'isReady' => $isReady,
|
||||
'mercure_public_url' => $this->mercurePublicUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
$screen = $player ? $player->getScreen() : 0;
|
||||
|
||||
return $this->render('game/index.html.twig', [
|
||||
|
||||
Reference in New Issue
Block a user