Dev console refuses buildable piece materials; loose piece grains cleared on load (t97)
This commit is contained in:
@@ -24,7 +24,7 @@ const DEV_COMMANDS = {
|
||||
};
|
||||
function devError(text) { return Object.assign([text], { error: true }); }
|
||||
function devName(text) { return text.toLowerCase().replace(/\s+/g, ''); }
|
||||
function devGiveable(id) { return id !== EMPTY && PH[id] !== PH_GAS && (PH[id] !== PH_SOLID || !!YLD[id]); }
|
||||
function devGiveable(id) { return id !== EMPTY && !PARTMAT[id] && PH[id] !== PH_GAS && (PH[id] !== PH_SOLID || !!YLD[id]); }
|
||||
function devMaterialList(text = '') {
|
||||
const keys = new Map(Object.entries(DEV_MATERIALS).map(([key, id]) => [id, key]));
|
||||
const list = [], name = devName(text);
|
||||
@@ -91,6 +91,7 @@ function devMaterial(name) {
|
||||
name = devName(name);
|
||||
const internal = Object.entries(DEV_MATERIALS).find(([key]) => devName(key) === name);
|
||||
if (internal) return internal[1];
|
||||
for (let id = 1; id < NMAT; id++) if (PARTMAT[id] && devName(MD[id].name) === name) return id;
|
||||
const ids = devMaterialList();
|
||||
const exact = ids.filter(([, id]) => devName(MD[id].name) === name);
|
||||
const matches = [...new Set((exact.length ? exact : ids.filter(([key, id]) => devName(key).startsWith(name) || devName(MD[id].name).startsWith(name))).map(([, id]) => id))];
|
||||
@@ -134,6 +135,7 @@ function devCommand(text, cursor) {
|
||||
if (!args.length || !Number.isInteger(n) || n <= 0) return usage();
|
||||
const m = devMaterial(args.join(' '));
|
||||
if (typeof m === 'string') return devError(m);
|
||||
if (PARTMAT[m]) return devError(`${MD[m].name} is built from the build menu, not given.`);
|
||||
if (!devGiveable(m)) return devError(`${MD[m].name} cannot go in the bag.`);
|
||||
if (n > 2147483647 - bag[m]) return devError('Too many: a material count cannot exceed 2147483647.');
|
||||
const into = PH[m] === PH_SOLID && YLD[m] ? YLD[m] : m;
|
||||
|
||||
+2
-1
@@ -279,6 +279,7 @@ function entsInCircle(cx, cy, r) {
|
||||
|
||||
// ---------- Bag ----------
|
||||
function bagAdd(m, n, force) {
|
||||
if (PARTMAT[m]) return 0;
|
||||
if (PH[m] === PH_SOLID && YLD[m]) m = YLD[m]; // rock and metal go in as what drilling them gives
|
||||
const room = force ? n : Math.max(0, bagCap() - bagTotal);
|
||||
const k = Math.min(n, room);
|
||||
@@ -291,7 +292,7 @@ function bagTake(m, n) { const k = Math.min(n, bag[m]); bag[m] -= k; bagTotal -=
|
||||
// grains as loose material, bars as bar objects. Counts what dropped.
|
||||
let droppedLast = 0;
|
||||
function giveOrDrop(m, n, x, y) {
|
||||
if (n <= 0) return;
|
||||
if (n <= 0 || PARTMAT[m]) return;
|
||||
if (m === CASH) { money += n; return; }
|
||||
const k = bagAdd(m, n, false);
|
||||
let rest = n - k;
|
||||
|
||||
+9
-2
@@ -139,8 +139,8 @@ function deserializeWorld(meta, buffers) {
|
||||
weather.shower = mw.shower || null; weather.next = mw.next || weather.next; weather.wind = mw.wind || weather.wind; weather.seen = !!mw.seen; weather.base = mw.base || 0;
|
||||
}
|
||||
bot.x = meta.bot.x; bot.y = meta.bot.y; bot.lamp = meta.bot.lamp !== false; bot.vx = bot.vy = 0;
|
||||
bag = new Int32Array(NMAT); meta.bag.forEach((v, k) => { if (k < NMAT) bag[k] = v; });
|
||||
for (const m of meta.flyers || []) if (m < NMAT) bag[m]++; // grains that were mid-air when saved
|
||||
bag = new Int32Array(NMAT); meta.bag.forEach((v, k) => { if (k < NMAT && !PARTMAT[k]) bag[k] = v; });
|
||||
for (const m of meta.flyers || []) if (m < NMAT && !PARTMAT[m]) bag[m]++; // grains that were mid-air when saved
|
||||
// solids saved in the bag (older saves) come back as what drilling them gives
|
||||
for (let k = 0; k < NMAT; k++) if (bag[k] && PH[k] === PH_SOLID && YLD[k]) { bag[YLD[k]] += bag[k]; bag[k] = 0; }
|
||||
bagTotal = 0; for (let k = 0; k < NMAT; k++) bagTotal += bag[k];
|
||||
@@ -148,6 +148,13 @@ function deserializeWorld(meta, buffers) {
|
||||
seen = new Uint8Array(NMAT); meta.seen.forEach((v, k) => { if (k < NMAT) seen[k] = v; });
|
||||
ledger = meta.ledger || {};
|
||||
Object.assign(stats, meta.stats || {});
|
||||
// Dedicated piece materials can only survive as owned construction, never nozzle grains.
|
||||
for (let i = 0; i < N; i++) if (PARTMAT[mat[i]] && !mach[i]) {
|
||||
const b = (((i / W) | 0) >> 2) * BW + ((i % W) >> 2);
|
||||
if (!blockOwnsCell(b, i, false) && slopeSealOwner(i) < 0) {
|
||||
setCell(i, EMPTY, temp[i], 0); markPow(i, false);
|
||||
}
|
||||
}
|
||||
clearStraySeals();
|
||||
powerDirty = true; rebuildPower(); slopeCleatsTick(false); updateRoof();
|
||||
if (!weather.base) weather.base = worldWater(); // older saves: take the water it has now as its starting amount
|
||||
|
||||
+2
-1
@@ -65,12 +65,13 @@ let blowRR = 0;
|
||||
function toolBlow(cx, cy, r, m, mix) {
|
||||
let pickM = null;
|
||||
if (mix && mix.length) {
|
||||
const avail = mix.filter(k => bag[k] > 0 && PH[k] !== PH_ITEM && (PH[k] !== PH_LIQUID || player.flask));
|
||||
const avail = mix.filter(k => !PARTMAT[k] && bag[k] > 0 && PH[k] !== PH_ITEM && (PH[k] !== PH_LIQUID || player.flask));
|
||||
if (!avail.length) return { placed: 0, status: 'None of the selected materials are in the bag.' };
|
||||
pickM = () => { for (let k = 0; k < avail.length; k++) { const c = avail[(blowRR++) % avail.length]; if (bag[c] > 0) return c; } return 0; };
|
||||
m = avail[0];
|
||||
}
|
||||
if (!m) return { placed: 0, status: 'Nothing selected: click or Q/E in the bag.' };
|
||||
if (PARTMAT[m]) return { placed: 0, status: MD[m].name + ' is built from the build menu.' };
|
||||
if (bag[m] <= 0) return { placed: 0, status: 'None of the selected materials are in the bag.' };
|
||||
const ph = PH[m];
|
||||
if (ph === PH_LIQUID && !player.flask) return { placed: 0, status: 'You need the Flask to carry liquids.' };
|
||||
|
||||
Reference in New Issue
Block a user