2016-09-21 16:38:33 -04:00
|
|
|
/**
|
|
|
|
* @fileoverview
|
|
|
|
* Object representing a Scratch variable.
|
|
|
|
*/
|
|
|
|
|
2017-06-15 17:29:15 -04:00
|
|
|
const uid = require('../util/uid');
|
|
|
|
|
2017-04-17 19:42:48 -04:00
|
|
|
class Variable {
|
|
|
|
/**
|
2017-06-15 17:29:15 -04:00
|
|
|
* @param {string} id Id of the variable.
|
|
|
|
* @param {string} name Name of the variable.
|
2017-04-17 19:42:48 -04:00
|
|
|
* @param {(string|number)} value Value of the variable.
|
|
|
|
* @param {boolean} isCloud Whether the variable is stored in the cloud.
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-06-15 17:29:15 -04:00
|
|
|
constructor (id, name, value, isCloud) {
|
|
|
|
this.id = id || uid();
|
2017-04-17 19:42:48 -04:00
|
|
|
this.name = name;
|
|
|
|
this.value = value;
|
|
|
|
this.isCloud = isCloud;
|
|
|
|
}
|
2017-05-25 11:44:49 -04:00
|
|
|
|
|
|
|
toXML () {
|
2017-06-15 17:29:15 -04:00
|
|
|
return `<variable type="" id="${this.id}">${this.name}</variable>`;
|
2017-05-25 11:44:49 -04:00
|
|
|
}
|
2017-04-17 19:42:48 -04:00
|
|
|
}
|
2016-10-24 11:49:34 -04:00
|
|
|
|
|
|
|
module.exports = Variable;
|