From 1ac63ff55138f9effbb0860c4857e87c9f3a4d14 Mon Sep 17 00:00:00 2001 From: Muffin Date: Sun, 21 Jul 2024 20:23:40 -0500 Subject: [PATCH] Tolerate sb3 targets without comments and blocks without inputs Fixes 1032296687 --- src/packager/minify/sb3.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/packager/minify/sb3.js b/src/packager/minify/sb3.js index 611d40d4..667bc173 100644 --- a/src/packager/minify/sb3.js +++ b/src/packager/minify/sb3.js @@ -76,11 +76,13 @@ const optimizeSb3Json = (projectData) => { blockPool.addReference(block.next); } - for (const input of Object.values(block.inputs)) { - for (let i = 1; i < input.length; i++) { - const inputValue = input[i]; - if (typeof inputValue === 'string') { - blockPool.addReference(inputValue); + if (block.inputs) { + for (const input of Object.values(block.inputs)) { + for (let i = 1; i < input.length; i++) { + const inputValue = input[i]; + if (typeof inputValue === 'string') { + blockPool.addReference(inputValue); + } } } } @@ -114,11 +116,13 @@ const optimizeSb3Json = (projectData) => { block.next = blockPool.getNewId(block.next); } - for (const input of Object.values(block.inputs)) { - for (let i = 1; i < input.length; i++) { - const inputValue = input[i]; - if (typeof inputValue === 'string') { - input[i] = blockPool.getNewId(inputValue); + if (block.inputs) { + for (const input of Object.values(block.inputs)) { + for (let i = 1; i < input.length; i++) { + const inputValue = input[i]; + if (typeof inputValue === 'string') { + input[i] = blockPool.getNewId(inputValue); + } } } } @@ -132,11 +136,13 @@ const optimizeSb3Json = (projectData) => { delete block.y; delete block.comment; } - for (const [commentId, comment] of Object.entries(target.comments)) { - const text = comment.text; - const isSpecial = text.includes(' // _twconfig_') || text.includes(' // _gamepad_'); - if (isSpecial) { - newComments[commentId] = comment; + if (target.comments) { + for (const [commentId, comment] of Object.entries(target.comments)) { + const text = comment.text; + const isSpecial = text.includes(' // _twconfig_') || text.includes(' // _gamepad_'); + if (isSpecial) { + newComments[commentId] = comment; + } } }