PL
games/alis / src / Scene / TitleScene.php · commit 9c722cf
<?phpnamespace App\Scene;use App\Alis\GameLibrary;use JumPHP\Kernel\Platform;use JumPHP\Renderer\Renderer;use JumPHP\Ui\MenuScene;/** * First screen: the ALIS games found in data/ (one folder per game, holding the original data files). */final class TitleScene extends MenuScene{    protected string $title = 'ALIS';    private array $games = [];    public function enter(array $params = []): void    {        $this->games = GameLibrary::scan($this->engine->config->path('data'), $this->engine->config->path('catalog'));        parent::enter($params);    }    protected function items(): array    {        $items = [];        $editors = [];        // the HD edition first: the one selected when the list opens        $games = $this->games;        usort($games, static fn (array $a, array $b) => ($a['edition'] !== 'hd') <=> ($b['edition'] !== 'hd'));        foreach ($games as $game) {            $items[] = [strtoupper($game['label']), null, fn () => $this->scenes()->switchTo(PlayScene::class, ['game' => $game['id'], 'edition' => $game['edition'], 'crt' => (bool) $this->engine->options->get('crt', false), 'fps' => (bool) $this->engine->options->get('fps', false), 'nodownscale' => (bool) $this->engine->options->get('nodownscale', false)])];            if ($game['edition'] === 'source') {                $editors[$game['id']] = $game;            }        }        // the ALIS editor of each game that has the sources of its scripts (docs/editor.md)        foreach ($editors as $game) {            $label = substr($game['label'], 0, -strlen(GameLibrary::EDITIONS['source']));            $items[] = [strtoupper($label) . ' - ALIS EDITOR', null, fn () => $this->scenes()->switchTo(EditorScene::class, ['game' => $game['id']])];        }        // an original survival prototype in the same spirit (not one of the ALIS games): App\Scene\RevisitedScene        $items[] = ['EXPERIENCE - ROB REVISITED - TEST', null, fn () => $this->scenes()->switchTo(RevisitedScene::class)];        // the "CRT 1995" option: ticked here, for the game chosen (App\Hd\CrtRenderer, kept in the options)        $toggle = function (): void {            $this->engine->options->set('crt', !(bool) $this->engine->options->get('crt', false));            $this->refresh();        };        $items[] = ['CRT 1995 SCREEN', fn () => $this->engine->options->get('crt', false) ? '[X]' : '[ ]', $toggle, fn (int $dir) => $toggle()];        $fps = function (): void {            $this->engine->options->set('fps', !(bool) $this->engine->options->get('fps', false));            $this->refresh();        };        $items[] = ['FPS', fn () => $this->engine->options->get('fps', false) ? '[X]' : '[ ]', $fps, fn (int $dir) => $fps()];        $full = function (): void {            $this->engine->options->set('nodownscale', !(bool) $this->engine->options->get('nodownscale', false));            $this->refresh();        };        $items[] = ['NO DOWNSCALE', fn () => $this->engine->options->get('nodownscale', false) ? '[X]' : '[ ]', $full, fn (int $dir) => $full()];        if (Platform::isDesktop()) {            $items[] = ['QUIT', null, fn () => $this->engine->quit()];        }        return $items;    }    protected function renderBackground(Renderer $r): void    {        $r->clear([12, 10, 24]);        $font = $this->font();        $font->draw($r, 'SILMARILS VIRTUAL MACHINE IN PHP', $this->width() / 2, 82, 1, [150, 140, 200], 'center');        if ($this->games === []) {            $font->draw($r, "PUT THE ORIGINAL DATA FILES OF A\nSILMARILS GAME IN DATA/<NAME>/", $this->width() / 2, 120, 1, [230, 200, 120], 'center');        }    }}