Add 'islocal' flag to XML serialization for variables.

This commit is contained in:
Karishma Chadha 2018-07-06 13:02:23 -04:00
parent ed608ffe6f
commit a0a11f2f19
2 changed files with 11 additions and 8 deletions

View file

@ -33,8 +33,9 @@ class Variable {
} }
} }
toXML () { toXML (isLocal) {
return `<variable type="${this.type}" id="${this.id}">${this.name}</variable>`; isLocal = (isLocal === true);
return `<variable type="${this.type}" id="${this.id}" islocal="${isLocal}">${this.name}</variable>`;
} }
/** /**

View file

@ -1074,19 +1074,21 @@ class VirtualMachine extends EventEmitter {
const id = messageIds[i]; const id = messageIds[i];
delete this.runtime.getTargetForStage().variables[id]; delete this.runtime.getTargetForStage().variables[id];
} }
const variableMap = Object.assign({}, const globalVarMap = Object.assign({}, this.runtime.getTargetForStage().variables);
this.runtime.getTargetForStage().variables, const localVarMap = this.editingTarget.isStage ?
this.editingTarget.variables Object.create(null) :
); Object.assign({}, this.editingTarget.variables);
const variables = Object.keys(variableMap).map(k => variableMap[k]); const globalVariables = Object.keys(globalVarMap).map(k => globalVarMap[k]);
const localVariables = Object.keys(localVarMap).map(k => localVarMap[k]);
const workspaceComments = Object.keys(this.editingTarget.comments) const workspaceComments = Object.keys(this.editingTarget.comments)
.map(k => this.editingTarget.comments[k]) .map(k => this.editingTarget.comments[k])
.filter(c => c.blockId === null); .filter(c => c.blockId === null);
const xmlString = `<xml xmlns="http://www.w3.org/1999/xhtml"> const xmlString = `<xml xmlns="http://www.w3.org/1999/xhtml">
<variables> <variables>
${variables.map(v => v.toXML()).join()} ${globalVariables.map(v => v.toXML()).join()}
${localVariables.map(v => v.toXML(true)).join()}
</variables> </variables>
${workspaceComments.map(c => c.toXML()).join()} ${workspaceComments.map(c => c.toXML()).join()}
${this.editingTarget.blocks.toXML(this.editingTarget.comments)} ${this.editingTarget.blocks.toXML(this.editingTarget.comments)}