Name box in the New world panel (t10)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
<button class="btn" id="btn-worlds" hidden>Worlds <small>load · rename · delete</small></button>
|
||||
<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>
|
||||
<label>Size
|
||||
<select id="nw-size">
|
||||
|
||||
@@ -293,6 +293,7 @@ input.text { background: var(--soot-0); border: 1px solid var(--soot-4); border-
|
||||
.newworld { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; padding: 10px; }
|
||||
.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; }
|
||||
.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); }
|
||||
|
||||
+9
-2
@@ -97,11 +97,18 @@ function boot(hotData) {
|
||||
buildTitleCells(); drawTitle();
|
||||
$('nw-seed').value = String(Math.floor(Math.random() * 900000) + 100000);
|
||||
$('wallet').onclick = () => { playSfx('ui'); openNotebook('Market'); };
|
||||
$('btn-new').onclick = () => { auInit(); playSfx('ui'); $('newworld').hidden = !$('newworld').hidden; if (!$('newworld').hidden) $('btn-generate').focus(); };
|
||||
$('btn-new').onclick = async () => {
|
||||
auInit(); playSfx('ui'); $('newworld').hidden = !$('newworld').hidden;
|
||||
if ($('newworld').hidden) return;
|
||||
try { $('nw-name').value = `World ${(await listWorlds()).length + 1}`; }
|
||||
catch (e) { $('nw-name').value = 'World 1'; }
|
||||
$('nw-name').focus(); $('nw-name').select();
|
||||
};
|
||||
for (const id of ['nw-name', 'nw-seed']) $(id).onkeydown = e => { if (e.key === 'Enter') $('btn-generate').click(); };
|
||||
$('btn-generate').onclick = () => {
|
||||
const seed = parseInt(String($('nw-seed').value).replace(/\D/g, ''), 10) || Math.floor(Math.random() * 1e6);
|
||||
const [w, h] = $('nw-size').value.split('x').map(Number);
|
||||
startNewWorld(seed, w, h);
|
||||
startNewWorld(seed, w, h, $('nw-name').value);
|
||||
};
|
||||
$('btn-continue').onclick = async () => { auInit(); playSfx('ui'); const sv = await newestSave(); if (sv) startFromSave(sv); else toast('No saved world found.'); };
|
||||
$('btn-title-settings').onclick = () => { auInit(); playSfx('ui'); openSettings('Display'); };
|
||||
|
||||
+2
-1
@@ -54,11 +54,12 @@ function deleteWorld(id) {
|
||||
if (GAME.worldId === id) { GAME.worldId = ''; GAME.worldName = ''; }
|
||||
});
|
||||
}
|
||||
function cleanWorldName(name, fallback) { return String(name).trim().slice(0, 40) || fallback; }
|
||||
function renameWorld(id, name) {
|
||||
return worldWrite(async () => {
|
||||
const list = await listWorlds(), entry = list.find(w => w.id === id);
|
||||
if (!entry) return;
|
||||
entry.name = String(name).trim().slice(0, 40) || entry.name;
|
||||
entry.name = cleanWorldName(name, entry.name);
|
||||
await DB.put('worlds', list);
|
||||
if (GAME.worldId === id) GAME.worldName = entry.name;
|
||||
});
|
||||
|
||||
+2
-2
@@ -15,13 +15,13 @@ function enterGame() {
|
||||
GAME.drag = null; GAME.lmb = GAME.rmb = false; lastBagKey = '';
|
||||
hudDirty = true; renderHotbar();
|
||||
}
|
||||
function startNewWorld(seed, w, h) {
|
||||
function startNewWorld(seed, w, h, name = '') {
|
||||
auInit();
|
||||
showLoading(true, 0);
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
const worlds = await listWorlds();
|
||||
GAME.worldId = newWorldId(); GAME.worldName = `World ${worlds.length + 1}`;
|
||||
GAME.worldId = newWorldId(); GAME.worldName = cleanWorldName(name, `World ${worlds.length + 1}`);
|
||||
await putWorldEntry({ id: GAME.worldId, name: GAME.worldName, seed, w, h, createdAt: Date.now(), savedAt: 0, playTime: 0 });
|
||||
generateWorld(seed, w, h, null);
|
||||
GAME.playTime = 0; GAME.clip = null; GAME.paste = false; GAME.selDrag = null; GAME.tool = 0; GAME.dropMat = 0; GAME.matChosen = false; GAME.wallMat = RSTONE; GAME.filterCfg = { m: [], inv: 0 }; GAME.pieceIdx = 0;
|
||||
|
||||
Reference in New Issue
Block a user