This commit is contained in:
Azgaar 2022-04-20 12:14:16 +05:00
parent 73434f5bb7
commit 424e1f4d85

40
main.js
View file

@ -241,26 +241,27 @@ async function checkLoadParameters() {
} }
// open latest map if option is active and map is stored // open latest map if option is active and map is stored
const loadLastMap = () => new Promise((resolve, reject) => { const loadLastMap = () =>
ldb.get("lastMap", blob => { new Promise((resolve, reject) => {
if (blob) { ldb.get("lastMap", blob => {
WARN && console.warn("Load last saved map"); if (blob) {
try { WARN && console.warn("Load last saved map");
uploadMap(blob); try {
resolve(); uploadMap(blob);
} catch (error) { resolve();
reject(error); } catch (error) {
reject(error);
}
} else {
reject("No map stored");
} }
} else { });
reject("No map stored"); });
}
})
})
if (onloadMap.value === "saved") { if (onloadMap.value === "saved") {
try { try {
await loadLastMap(); await loadLastMap();
} catch(error) { } catch (error) {
ERROR && console.error(error); ERROR && console.error(error);
WARN && console.warn("Cannot load stored map, random map to be generated"); WARN && console.warn("Cannot load stored map, random map to be generated");
await generateMapOnLoad(); await generateMapOnLoad();
@ -1625,10 +1626,11 @@ function addZones(number = 1) {
const neib = ra(state.neighbors.filter(n => n && !states[n].removed)); const neib = ra(state.neighbors.filter(n => n && !states[n].removed));
if (!neib) return; if (!neib) return;
const cell = cells.i.find(i => cells.state[i] === state.i && !state.removed && cells.c[i].some(c => cells.state[c] === neib)); const cell = cells.i.find(i => cells.state[i] === state.i && !state.removed && cells.c[i].some(c => cells.state[c] === neib));
const cellsArray = [], const cellsArray = [];
queue = [], const queue = [];
power = rand(10, 30); if (cell) queue.push(cell);
if (cell) queue.push.cell;
const power = rand(10, 30);
while (queue.length) { while (queue.length) {
const q = queue.shift(); const q = queue.shift();