Sign in
EN
games/open-lemmings / src / Scene / OptionsScene.php · commit 04e2e2a
<?phpnamespace App\Scene;use JumPHP\Kernel\Platform;/** Settings (saved by the engine's Options): sound, music, language, full screen, install. */final class OptionsScene extends MenuBase{    protected string $title = 'OPTIONS';    public function isOverlay(): bool    {        return true;    }    protected function renderBackground(\JumPHP\Renderer\Renderer $r): void    {        $r->fillRect(0, 0, 480, 270, [8, 4, 20, 235]);    }    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(max(0, min(1, round($sound->getSfxVolume() * 10 + $dir) / 10)));                $options->set('sfx_volume', $sound->getSfxVolume());            }],            ['MUSIC', fn () => round($sound->getMusicVolume() * 100) . '%', null, function (int $dir) use ($sound, $options): void {                $sound->setMusicVolume(max(0, min(1, round($sound->getMusicVolume() * 10 + $dir) / 10)));                $options->set('music_volume', $sound->getMusicVolume());            }],            ['LANGUAGE', fn () => 'LANGNAME', 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);            }],        ];        $items[] = ['GRAPHICS', fn () => $this->art->hdOn($this->engine) ? 'HD' : 'RETRO', null, function (int $dir): void {            $this->art->toggleHd($this->engine);            $this->scenes()->switchTo(TitleScene::class, [], false);   // every scene draws its pictures again        }];        if ($this->art->effects->available($this->engine)) {            $items[] = ['EFFECTS', fn () => $this->art->effects->isOn($this->engine) ? 'ON' : 'OFF', null, fn (int $dir) => $this->art->effects->toggle($this->engine)];        }        if (Platform::isDesktop()) {            $items[] = ['FULLSCREEN', fn () => $options->get('fullscreen') ? 'ON' : 'OFF', null, fn (int $dir) => $this->engine->toggleFullscreen()];        }        $pwa = $this->engine->pwa();        if ($pwa->canInstall()) {            $items[] = ['INSTALL', null, fn () => $pwa->install()->then(fn () => null)];        } elseif ($pwa->hasPortal()) {            $items[] = ['INSTALL', null, fn () => $pwa->showInstallMenu()];        }        $items[] = ['BACK', null, fn () => $this->back()];        return $items;    }    protected function back(): void    {        $this->scenes()->pop();    }}