From d9573df8ca4c2c53b8fd25c9d104aedabe0541d6 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 20 Feb 2025 13:20:15 -0800 Subject: [PATCH] fix: use derived IDs for block comments --- src/engine/adapter.js | 2 +- src/serialization/sb3.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/engine/adapter.js b/src/engine/adapter.js index d10c6874ac9..ce840fde149 100644 --- a/src/engine/adapter.js +++ b/src/engine/adapter.js @@ -88,7 +88,7 @@ const domToBlock = function (blockDOM, blocks, isTopBlock, parent) { } case 'comment': { - block.comment = xmlChild.attribs.id; + block.comment = `${block.id}_comment`; break; } case 'value': diff --git a/src/serialization/sb3.js b/src/serialization/sb3.js index c7db58d0b37..18636d17535 100644 --- a/src/serialization/sb3.js +++ b/src/serialization/sb3.js @@ -842,6 +842,14 @@ const deserializeBlocks = function (blocks) { block.id = blockId; // add id back to block since it wasn't serialized block.inputs = deserializeInputs(block.inputs, blockId, blocks); block.fields = deserializeFields(block.fields); + + if (block.comment) { + // Pre-Blockly v12 Scratch used arbitrary IDs for block comments. + // Newer versions use an ID based on the parent block's ID instead, + // so disregard the actual saved value and replace it with the + // synthesized one. + block.comment = `${block.id}_comment`; + } } return blocks; }; @@ -1047,7 +1055,7 @@ const parseScratchObject = function (object, runtime, extensions, zip, assets) { for (const commentId in object.comments) { const comment = object.comments[commentId]; const newComment = new Comment( - commentId, + comment.blockId ? `${comment.blockId}_comment` : commentId, comment.text, comment.x, comment.y,