Entrar
PT
games/doom-jumphp / src / Scene / OptionsScene.php · commit 8e1cb9f
<?phpnamespace App\Scene;use JumPHP\Kernel\Platform;use JumPHP\Ui\MenuScene;/** Settings, saved in var/options.json (IndexedDB in the browser). */final class OptionsScene extends MenuScene{    protected string $title = 'OPTIONS';    protected float $titleScale = 2.0;    public function isOverlay(): bool    {        return true;    }    protected function items(): array    {        $options = $this->engine->options;        $sound = $this->sound();        $items = [            ['SOUND', fn () => round($sound->getSfxVolume() * 100) . '%', null, function (int $dir) use ($sound, $options): void {                $sound->setSfxVolume(round($sound->getSfxVolume() * 10 + $dir) / 10);                $options->set('sfx_volume', $sound->getSfxVolume());                $sound->playSfx('menu_move');            }],            ['DETAIL', fn () => strtoupper((string)$options->get('detail', Platform::isMobile() ? 'low' : 'high')), null, function (int $dir) use ($options): void {                $now = $options->get('detail', Platform::isMobile() ? 'low' : 'high');                $options->set('detail', $now === 'high' ? 'low' : 'high');                $this->refresh();            }],            ['LANGUAGE', fn () => strtoupper($this->engine->lang->getLang()), null, function (int $dir) use ($options): void {                $langs = $this->engine->lang->available();                $i = array_search($this->engine->lang->getLang(), $langs, true);                $lang = $langs[((int)$i + $dir + count($langs)) % count($langs)];                $this->engine->lang->setLang($lang);                $options->set('lang', $lang);            }],        ];        if (Platform::isDesktop()) {            $items[] = ['FULLSCREEN', fn () => $options->get('fullscreen') ? 'ON' : 'OFF', null, fn () => $this->engine->toggleFullscreen()];        }        array_push($items, ...$this->engine->pwa()->menuItems());        $items[] = ['BACK', null, fn () => $this->back()];        return $items;    }    protected function renderBackground(\JumPHP\Renderer\Renderer $r): void    {        $r->fillRect(0, 0, $this->width(), $this->height(), [0, 0, 0, 225]);    }    protected function back(): void    {        $this->scenes()->pop();    }}