diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 8a3436f52..294bf84bf 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -419,11 +419,7 @@ class Blocks { * @return {string} String of XML representing this object's blocks. */ toXML () { - let xmlString = ''; - for (let i = 0; i < this._scripts.length; i++) { - xmlString += this.blockToXML(this._scripts[i]); - } - return `${xmlString}`; + return this._scripts.map(script => this.blockToXML(script)).join(); } /** diff --git a/src/engine/variable.js b/src/engine/variable.js index 2be2c0f89..69cb915c8 100644 --- a/src/engine/variable.js +++ b/src/engine/variable.js @@ -15,6 +15,10 @@ class Variable { this.value = value; this.isCloud = isCloud; } + + toXML () { + return `${this.name}`; + } } module.exports = Variable; diff --git a/src/virtual-machine.js b/src/virtual-machine.js index fef841a6a..19a4a8dd4 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -491,9 +491,18 @@ class VirtualMachine extends EventEmitter { * of the current editing target's blocks. */ emitWorkspaceUpdate () { - this.emit('workspaceUpdate', { - xml: this.editingTarget.blocks.toXML() - }); + // @todo Include variables scoped to editing target also. + const variableMap = this.runtime.getTargetForStage().variables; + const variables = Object.keys(variableMap).map(k => variableMap[k]); + + const xmlString = ` + + ${variables.map(v => v.toXML()).join()} + + ${this.editingTarget.blocks.toXML()} + `; + + this.emit('workspaceUpdate', {xml: xmlString}); } /** @@ -538,6 +547,15 @@ class VirtualMachine extends EventEmitter { postSpriteInfo (data) { this.editingTarget.postSpriteInfo(data); } + + /** + * Create a variable by name. + * @todo this only creates global variables by putting them on the stage + * @param {string} name The name of the variable + */ + createVariable (name) { + this.runtime.getTargetForStage().lookupOrCreateVariable(name); + } } module.exports = VirtualMachine;