Dice button picks a random seed in the new-world dialog (t100)
This commit is contained in:
+8
-1
@@ -56,7 +56,14 @@
|
||||
<button class="btn" id="btn-new">New world <small>generate</small></button>
|
||||
<div class="plate newworld" id="newworld" hidden>
|
||||
<label>Name <input id="nw-name" type="text" maxlength="40" autocomplete="off" spellcheck="false"></label>
|
||||
<label>Seed <input id="nw-seed" type="text" inputmode="numeric" autocomplete="off"></label>
|
||||
<div class="seed-field">
|
||||
<label for="nw-seed">Seed</label>
|
||||
<div class="seed-row">
|
||||
<input id="nw-seed" type="text" inputmode="numeric" maxlength="10" autocomplete="off" aria-describedby="nw-seed-hint">
|
||||
<button class="btn" id="btn-random-seed" type="button" aria-label="Random seed" title="Random seed">⚄</button>
|
||||
</div>
|
||||
<small id="nw-seed-hint" role="status" hidden>Maximum seed: 4294967295.</small>
|
||||
</div>
|
||||
<label>Size
|
||||
<select id="nw-size">
|
||||
<option value="2048x1024">Small · 2048 × 1024</option>
|
||||
|
||||
@@ -301,6 +301,11 @@ input.text { background: var(--soot-0); border: 1px solid var(--soot-4); border-
|
||||
.newworld label { display: flex; flex-direction: column; gap: 4px; font-size: 0.86em; color: var(--ash); }
|
||||
.newworld select, .newworld input { background: var(--soot-0); border: 1px solid var(--soot-4); border-radius: 4px; padding: 6px 8px; color: var(--bone); }
|
||||
.newworld label:first-child { grid-column: 1 / -1; }
|
||||
.seed-field { display: flex; flex-direction: column; gap: 4px; color: var(--ash); font-size: 0.86em; }
|
||||
.seed-field label { font-size: inherit; }
|
||||
.seed-row { display: flex; gap: 4px; }
|
||||
.seed-row input { min-width: 0; width: 100%; }
|
||||
.seed-row .btn { padding: 2px 8px; font-size: 1.4em; }
|
||||
.newworld .full { grid-column: 1 / -1; }
|
||||
.tfoot { text-align: center; color: var(--ash-dim); font-size: 0.82em; font-family: var(--font-mono); }
|
||||
#loading { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(11, 9, 8, 0.86); }
|
||||
|
||||
+24
-4
@@ -113,10 +113,21 @@ function boot(hotData) {
|
||||
initRender(canvas);
|
||||
setupBuildBar();
|
||||
buildTitleCells(); drawTitle();
|
||||
$('nw-seed').value = String(Math.floor(Math.random() * 900000) + 100000);
|
||||
$('wallet').onclick = () => { playSfx('ui'); openNotebook('Market'); };
|
||||
let autoName = '', worldNames = [];
|
||||
const newWorldSeed = () => parseInt(String($('nw-seed').value).replace(/\D/g, ''), 10) || Math.floor(Math.random() * 1e6);
|
||||
const seedBox = $('nw-seed');
|
||||
const newWorldSeed = (value = seedBox.value) => {
|
||||
const digits = value.replace(/\D/g, '');
|
||||
const clamped = Number(digits) > 4294967295;
|
||||
$('nw-seed-hint').hidden = !clamped;
|
||||
if (value === seedBox.value) {
|
||||
const caret = seedBox.value.slice(0, seedBox.selectionStart).replace(/\D/g, '').length;
|
||||
const clean = clamped ? '4294967295' : digits;
|
||||
if (seedBox.value !== clean) { seedBox.value = clean; seedBox.setSelectionRange(caret, caret); }
|
||||
}
|
||||
return digits === '' ? Math.floor(Math.random() * 900000) + 100000 : Math.min(Number(digits), 4294967295);
|
||||
};
|
||||
seedBox.value = String(newWorldSeed(''));
|
||||
$('btn-new').onclick = async () => {
|
||||
auInit(); playSfx('ui'); $('newworld').hidden = !$('newworld').hidden;
|
||||
if ($('newworld').hidden) return;
|
||||
@@ -125,8 +136,17 @@ function boot(hotData) {
|
||||
$('nw-name').value = autoName = claimName(newWorldSeed(), worldNames);
|
||||
$('nw-name').focus(); $('nw-name').select();
|
||||
};
|
||||
$('nw-seed').oninput = () => {
|
||||
if ($('nw-name').value === autoName) $('nw-name').value = autoName = claimName(newWorldSeed(), worldNames);
|
||||
seedBox.oninput = () => {
|
||||
const seed = newWorldSeed();
|
||||
if ($('nw-name').value === autoName) $('nw-name').value = autoName = claimName(seed, worldNames);
|
||||
};
|
||||
$('btn-random-seed').onclick = () => { seedBox.value = String(newWorldSeed('')); seedBox.oninput(); };
|
||||
// Read the whole transfer before maxlength can truncate its digits.
|
||||
seedBox.onpaste = seedBox.ondrop = e => {
|
||||
e.preventDefault();
|
||||
const text = (e.clipboardData || e.dataTransfer).getData('text/plain');
|
||||
seedBox.setRangeText(text, seedBox.selectionStart, seedBox.selectionEnd, 'end');
|
||||
seedBox.oninput();
|
||||
};
|
||||
for (const id of ['nw-name', 'nw-seed']) $(id).onkeydown = e => { if (e.key === 'Enter') $('btn-generate').click(); };
|
||||
$('btn-generate').onclick = () => {
|
||||
|
||||
Reference in New Issue
Block a user