mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Comment save and load.
This commit is contained in:
parent
8c748cebb4
commit
e2eadbf603
2 changed files with 45 additions and 0 deletions
|
@ -8,6 +8,7 @@ const vmPackage = require('../../package.json');
|
|||
const Blocks = require('../engine/blocks');
|
||||
const Sprite = require('../sprites/sprite');
|
||||
const Variable = require('../engine/variable');
|
||||
const Comment = require('../engine/comment');
|
||||
const StageLayering = require('../engine/stage-layering');
|
||||
const log = require('../util/log');
|
||||
const uid = require('../util/uid');
|
||||
|
@ -207,6 +208,9 @@ const serializeBlock = function (block) {
|
|||
if (block.mutation) {
|
||||
obj.mutation = block.mutation;
|
||||
}
|
||||
if (block.comment) {
|
||||
obj.comment = block.comment;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
@ -384,6 +388,27 @@ const serializeVariables = function (variables) {
|
|||
return obj;
|
||||
};
|
||||
|
||||
const serializeComments = function (comments) {
|
||||
const obj = Object.create(null);
|
||||
for (const commentId in comments) {
|
||||
if (!comments.hasOwnProperty(commentId)) continue;
|
||||
const comment = comments[commentId];
|
||||
|
||||
const serializedComment = Object.create(null);
|
||||
serializedComment.id = comment.id;
|
||||
serializedComment.blockId = comment.blockId;
|
||||
serializedComment.x = comment.x;
|
||||
serializedComment.y = comment.y;
|
||||
serializedComment.width = comment.width;
|
||||
serializedComment.height = comment.height;
|
||||
serializedComment.minimized = comment.minimized;
|
||||
serializedComment.text = comment.text;
|
||||
|
||||
obj[commentId] = serializedComment;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize the given target. Only serialize properties that are necessary
|
||||
* for saving and loading this target.
|
||||
|
@ -399,6 +424,7 @@ const serializeTarget = function (target) {
|
|||
obj.lists = vars.lists;
|
||||
obj.broadcasts = vars.broadcasts;
|
||||
obj.blocks = serializeBlocks(target.blocks);
|
||||
obj.comments = serializeComments(target.comments);
|
||||
obj.currentCostume = target.currentCostume;
|
||||
obj.costumes = target.costumes.map(serializeCostume);
|
||||
obj.sounds = target.sounds.map(serializeSound);
|
||||
|
@ -834,6 +860,24 @@ const parseScratchObject = function (object, runtime, extensions, zip) {
|
|||
target.variables[newBroadcast.id] = newBroadcast;
|
||||
}
|
||||
}
|
||||
if (object.hasOwnProperty('comments')) {
|
||||
for (const commentId in object.comments) {
|
||||
const comment = object.comments[commentId];
|
||||
const newComment = new Comment(
|
||||
comment.id,
|
||||
comment.text,
|
||||
comment.x,
|
||||
comment.y,
|
||||
comment.width,
|
||||
comment.height,
|
||||
comment.minimized
|
||||
);
|
||||
if (comment.blockId) {
|
||||
newComment.blockId = comment.blockId;
|
||||
}
|
||||
target.comments[newComment.id] = newComment;
|
||||
}
|
||||
}
|
||||
if (object.hasOwnProperty('x')) {
|
||||
target.x = object.x;
|
||||
}
|
||||
|
|
|
@ -1103,6 +1103,7 @@ class RenderedTarget extends Target {
|
|||
costumeCount: costumes.length,
|
||||
visible: this.visible,
|
||||
rotationStyle: this.rotationStyle,
|
||||
comments: this.comments,
|
||||
blocks: this.blocks._blocks,
|
||||
variables: this.variables,
|
||||
costumes: costumes,
|
||||
|
|
Loading…
Reference in a new issue