2018-05-21 11:30:22 -04:00
|
|
|
/**
|
|
|
|
* @fileoverview
|
|
|
|
* Object representing a Scratch Comment (block or workspace).
|
|
|
|
*/
|
|
|
|
|
|
|
|
const uid = require('../util/uid');
|
|
|
|
const cast = require('../util/cast');
|
|
|
|
|
|
|
|
class Comment {
|
|
|
|
/**
|
|
|
|
* @param {string} id Id of the variable.
|
|
|
|
* @param {string} name Name of the variable.
|
|
|
|
* @param {string} type Type of the variable, one of '' or 'list'
|
|
|
|
* @param {boolean} isCloud Whether the variable is stored in the cloud.
|
|
|
|
* @constructor
|
|
|
|
*/ /* TODO should the comment constructor take in an id? will we need this for sb3? */
|
|
|
|
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.width = Math.max(cast.toNumber(width), Comment.MIN_WIDTH);
|
|
|
|
this.height = Math.max(cast.toNumber(height), Comment.MIN_HEIGHT);
|
|
|
|
this.minimized = minimized || false;
|
|
|
|
this.blockId = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
toXML () {
|
2018-05-24 16:23:08 -04:00
|
|
|
return `<comment type="scratch" id="${this.id}" x="${this.x}" y="${
|
|
|
|
this.y}" w="${this.width}" h="${this.height}" pinned="${
|
|
|
|
this.blockId !== null}" minimized="${this.minimized}">${this.text}</comment>`;
|
2018-05-21 11:30:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO choose min and defaults for width and height
|
|
|
|
static get MIN_WIDTH () {
|
|
|
|
return 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get MIN_HEIGHT () {
|
|
|
|
return 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get DEFAULT_WIDTH () {
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get DEFAULT_HEIGHT () {
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Comment;
|