prnd with world seed

This commit is contained in:
azykov@mail.ru
2026-09-09 19:52:27 +03:00
parent 7e6b50d1bc
commit e0a50aac18
9 changed files with 161 additions and 24 deletions
+30 -3
View File
@@ -23,8 +23,14 @@ function createToggle(label: string, initial: boolean, onChange: (value: boolean
}
/** Builds the settings screen — rendering-diagnostics toggles that take effect the next time a
* game is (re)started (GameCanvas reads them once, on mount), reachable from the main menu. */
export function createSettingsScreen(onBack: () => void): HTMLElement {
* game is (re)started (GameCanvas reads them once, on mount), plus a seed field, reachable from
* the main menu.
* @param currentSeed The running game's current PRNG seed (see GameStore.seed) — 0 if no game has
* started yet this page load. Shown as the seed field's starting value.
* @param onStartWithSeed Called with a new seed the instant the seed field's value is committed
* (blur or Enter) — starts (or restarts) a game seeded from it, discarding any existing save, the
* same way "Новая игра" does. */
export function createSettingsScreen(currentSeed: number, onBack: () => void, onStartWithSeed: (seed: number) => void): HTMLElement {
const root = document.createElement('div');
root.className = 'main-menu';
@@ -45,13 +51,34 @@ export function createSettingsScreen(onBack: () => void): HTMLElement {
setRenderSettings({ noScale: value });
});
const seedLabel = document.createElement('label');
seedLabel.className = 'settings-seed-label';
seedLabel.textContent = 'Сид игры (новая игра при изменении)';
const seedInput = document.createElement('input');
seedInput.type = 'number';
seedInput.className = 'settings-seed-input';
seedInput.min = '0';
seedInput.max = '4294967295';
seedInput.step = '1';
seedInput.value = String(currentSeed);
seedInput.addEventListener('change', () => {
const parsed = Math.floor(Number(seedInput.value));
if (!Number.isFinite(parsed) || parsed < 0) {
seedInput.value = String(currentSeed);
return;
}
onStartWithSeed(parsed >>> 0);
});
seedLabel.appendChild(seedInput);
const backBtn = document.createElement('button');
backBtn.type = 'button';
backBtn.className = 'menu-btn';
backBtn.textContent = 'Назад';
backBtn.addEventListener('click', onBack);
buttons.append(antialiasingBtn, noScaleBtn, backBtn);
buttons.append(antialiasingBtn, noScaleBtn, seedLabel, backBtn);
root.append(title, buttons);
return root;
}