Reject blueprint codes with unknown pieces, machines or molds (t78)

This commit is contained in:
2026-10-29 17:50:07 -04:00
parent f7c989db6c
commit 5e26e4634d
3 changed files with 82 additions and 1 deletions
+10 -1
View File
@@ -211,7 +211,16 @@ async function importWorldFile(file) {
function libLoad() { try { return JSON.parse(localStorage.getItem('deepgrain.blueprints') || '[]'); } catch (e) { return []; } }
function libSave(list) { try { localStorage.setItem('deepgrain.blueprints', JSON.stringify(list)); return true; } catch (e) { toast('Blueprints cannot be stored in this view. Copy the blueprint code instead.'); return false; } }
function bpEncode(bp) { return 'DGBP2:' + btoa(unescape(encodeURIComponent(JSON.stringify(bp)))); }
function bpValid(bp) { return !!(bp && bp.v === 2 && Array.isArray(bp.blocks) && bp.bw > 0 && bp.bh > 0); }
function bpValid(bp) {
return !!(bp && bp.v === 2 && Array.isArray(bp.blocks) && bp.bw > 0 && bp.bh > 0
&& bp.blocks.every(b => Array.isArray(b) && Number.isInteger(b[2]) && Object.hasOwn(PIECE_BY_CODE, b[2]))
&& Array.isArray(bp.machines || []) && (bp.machines || []).every(m => {
if (!Array.isArray(m) || !Object.hasOwn(PIECE_BY_ID, m[0])) return false;
const p = PIECE_BY_ID[m[0]];
return p.kind === 'machine' && !p.fixed;
})
&& Array.isArray(bp.molds || []) && (bp.molds || []).every(m => Array.isArray(m) && Object.hasOwn(MOLDS, m[0])));
}
function bpDecode(code) {
const s = code.trim();
if (s.startsWith('DGBP1:')) throw new Error('That blueprint is from an older version of the game, before the block grid. It cannot be used.');