Refactor furnace input, fuel, and output handling: stringify on save and parse on load
This commit is contained in:
@@ -158,9 +158,9 @@ const saveFurnacesBatch = db.transaction((furnaces, now) => {
|
||||
name,
|
||||
type: f.type || 'minecraft:furnace',
|
||||
active: f.active ? 1 : 0,
|
||||
input: f.input || null,
|
||||
fuel: f.fuel || null,
|
||||
output: f.output || null,
|
||||
input: f.input ? JSON.stringify(f.input) : null,
|
||||
fuel: f.fuel ? JSON.stringify(f.fuel) : null,
|
||||
output: f.output ? JSON.stringify(f.output) : null,
|
||||
updatedAt: now,
|
||||
});
|
||||
}
|
||||
@@ -260,12 +260,16 @@ export function loadFurnaces() {
|
||||
const rows = getAllFurnaces.all();
|
||||
const result = {};
|
||||
for (const row of rows) {
|
||||
let input = null, fuel = null, output = null;
|
||||
try { input = row.input ? JSON.parse(row.input) : null; } catch { input = row.input; }
|
||||
try { fuel = row.fuel ? JSON.parse(row.fuel) : null; } catch { fuel = row.fuel; }
|
||||
try { output = row.output ? JSON.parse(row.output) : null; } catch { output = row.output; }
|
||||
result[row.name] = {
|
||||
active: !!row.active,
|
||||
type: row.type,
|
||||
input: row.input,
|
||||
fuel: row.fuel,
|
||||
output: row.output,
|
||||
input,
|
||||
fuel,
|
||||
output,
|
||||
};
|
||||
}
|
||||
return result;
|
||||
@@ -362,9 +366,9 @@ const _saveFullStateTransaction = db.transaction((state, now) => {
|
||||
name,
|
||||
type: f.type || 'minecraft:furnace',
|
||||
active: f.active ? 1 : 0,
|
||||
input: f.input || null,
|
||||
fuel: f.fuel || null,
|
||||
output: f.output || null,
|
||||
input: f.input ? JSON.stringify(f.input) : null,
|
||||
fuel: f.fuel ? JSON.stringify(f.fuel) : null,
|
||||
output: f.output ? JSON.stringify(f.output) : null,
|
||||
updatedAt: now,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user