Add command-line tutorial (PreGameController) and link it from the lobby
Adds a black-terminal tutorial page at /game/pregame/{session} that walks
players through help, pwd, cd, ls, cat, rm and sudo before the real game
starts. Links to it are shown on both the lobby (waiting for players) and
ready-up screens so players can practice, repeatedly, before starting.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Game\Controller;
|
||||
|
||||
use App\Game\Entity\Session;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Twig\Environment;
|
||||
|
||||
final class PreGameController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Environment $twig,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(path: '/pregame/{session}', name: 'game_pregame', methods: ['GET'])]
|
||||
#[IsGranted(new Expression("is_granted('ROLE_PLAYER') or is_granted('ROLE_ADMIN')"))]
|
||||
#[IsGranted('SESSION_VIEW', subject: 'session')]
|
||||
public function index(Session $session): Response
|
||||
{
|
||||
$gameId = $session->getGame()?->getId();
|
||||
$template = sprintf('pregame/game%d.html.twig', $gameId ?? 0);
|
||||
|
||||
if (!$this->twig->getLoader()->exists($template)) {
|
||||
$template = 'pregame/default.html.twig';
|
||||
}
|
||||
|
||||
return $this->render($template, [
|
||||
'session' => $session,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user