New claims: open another claim once one is paid off, travel between them (t3)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 18:06:01 -04:00
co-authored by Claude Opus 5.5
parent 282e9ce9ab
commit 28893c93bc
12 changed files with 300 additions and 36 deletions
+18 -7
View File
@@ -49,8 +49,19 @@ async function worldNewest(id) {
}
function deleteWorld(id) {
return worldWrite(async () => {
const list = (await listWorlds()).filter(w => w.id !== id);
await DB.op('readwrite', st => { st.delete(`${id}:main`); st.delete(`${id}:auto`); st.put(list, 'worlds'); });
const worlds = await listWorlds(), entry = worlds.find(w => w.id === id), list = worlds.filter(w => w.id !== id);
const stored = entry && entry.career ? await DB.get('career:' + entry.career) : null;
const c = stored && typeof stored === 'object' && !Array.isArray(stored) ? stored : null;
const claims = entry && entry.career ? list.filter(w => w.career === entry.career).map(w => w.id) : [];
if (c) c.claims = claims;
await DB.op('readwrite', st => {
st.delete(`${id}:main`); st.delete(`${id}:auto`); st.put(list, 'worlds');
if (entry && entry.career) {
if (!claims.length) st.delete('career:' + entry.career);
else if (c) st.put(c, 'career:' + entry.career);
}
});
if (career && c && career.id === c.id) career.claims = c.claims;
if (GAME.worldId === id) { GAME.worldId = ''; GAME.worldName = ''; }
});
}
@@ -91,14 +102,14 @@ async function saveWorld(slot, quiet) {
try {
const s = serializeWorld(), savedAt = Date.now(), playTime = GAME.playTime;
if (!GAME.worldId) { GAME.worldId = newWorldId(); GAME.worldName = `World ${(await listWorlds()).length + 1}`; }
const id = GAME.worldId, name = GAME.worldName;
const buffers = await packBuffers(s.buffers);
const id = GAME.worldId, name = GAME.worldName, claimNo = GAME.claimNo, c = GAME.careerId && career ? { ...career, ...careerState() } : null;
await worldWrite(async () => {
const buffers = await packBuffers(s.buffers);
const list = await listWorlds();
let entry = list.find(w => w.id === id);
if (!entry) { entry = { id, name, createdAt: savedAt }; list.push(entry); }
Object.assign(entry, { savedAt, playTime, seed: s.meta.seed, w: s.meta.W, h: s.meta.H });
await DB.op('readwrite', st => { st.put({ meta: s.meta, buffers, savedAt, playTime }, `${id}:${slot}`); st.put(list, 'worlds'); });
Object.assign(entry, { savedAt, playTime, seed: s.meta.seed, w: s.meta.W, h: s.meta.H, debt: s.meta.economy.debt, ...(c ? { career: c.id, claimNo } : {}) });
await DB.op('readwrite', st => { st.put({ meta: s.meta, buffers, savedAt, playTime }, `${id}:${slot}`); st.put(list, 'worlds'); if (c) st.put(c, 'career:' + c.id); });
});
if (!quiet) toast(slot === 'auto' ? 'Autosaved.' : 'World saved.');
return true;
@@ -178,7 +189,7 @@ async function importWorldFile(file) {
bufs[k] = new C(bytes.buffer, bytes.byteOffset, bytes.byteLength / C.BYTES_PER_ELEMENT);
}
const id = newWorldId(), name = `Imported ${obj.meta.seed}`.slice(0, 40);
if (!startFromSave({ meta: obj.meta, buffers: bufs, worldId: id, worldName: name })) return;
if (!await startFromSave({ meta: obj.meta, buffers: bufs, worldId: id, worldName: name })) return;
if (!await saveWorld('auto')) return;
toast('World imported.');
} catch (e) { toast('That file could not be loaded: ' + (e.message || 'unknown error')); }