Don't serialize x and y for sb2 comments so that they can be auto positioned.

This commit is contained in:
Karishma Chadha 2018-05-28 21:24:47 -04:00
parent b0aa288916
commit f079eb4bbd
2 changed files with 8 additions and 5 deletions

View file

@ -17,8 +17,8 @@ class Comment {
constructor (id, text, x, y, width, height, minimized) {
this.id = id || uid();
this.text = text;
this.x = cast.toNumber(x);
this.y = cast.toNumber(y);
this.x = x;
this.y = y;
this.width = Math.max(cast.toNumber(width), Comment.MIN_WIDTH);
this.height = Math.max(cast.toNumber(height), Comment.MIN_HEIGHT);
this.minimized = minimized || false;

View file

@ -449,16 +449,19 @@ const parseScratchObject = function (object, runtime, extensions, topLevel, zip)
const blockComments = {};
if (object.hasOwnProperty('scriptComments')) {
const comments = object.scriptComments.map(commentDesc => {
const isBlockComment = commentDesc[5] >= 0;
const newComment = new Comment(
null, // generate a new id for this comment
commentDesc[6], // text content of sb2 comment
commentDesc[0] * 1.5, // x position of comment
commentDesc[1] * 2.2, // y position of comment
// Only serialize x & y position of comment if it's a workspace comment
// If it's a block comment, we'll let scratch-blocks handle positioning
isBlockComment ? null : commentDesc[0] * 1.5, // x position of comment
isBlockComment ? null : commentDesc[1] * 2.2, // y position of comment
commentDesc[2] * 1.5, // width of comment
commentDesc[3] * 2.2, // height of comment
!commentDesc[4] // commentDesc[4] -- false means minimized, true means full screen
);
if (commentDesc[5] >= 0) {
if (isBlockComment) {
// commentDesc[5] refers to the index of the block that this
// comment is attached to -- in a flattened version of the
// scripts array.