mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Add 'islocal' flag to XML serialization for variables.
This commit is contained in:
parent
ed608ffe6f
commit
a0a11f2f19
2 changed files with 11 additions and 8 deletions
|
@ -33,8 +33,9 @@ class Variable {
|
|||
}
|
||||
}
|
||||
|
||||
toXML () {
|
||||
return `<variable type="${this.type}" id="${this.id}">${this.name}</variable>`;
|
||||
toXML (isLocal) {
|
||||
isLocal = (isLocal === true);
|
||||
return `<variable type="${this.type}" id="${this.id}" islocal="${isLocal}">${this.name}</variable>`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1074,19 +1074,21 @@ class VirtualMachine extends EventEmitter {
|
|||
const id = messageIds[i];
|
||||
delete this.runtime.getTargetForStage().variables[id];
|
||||
}
|
||||
const variableMap = Object.assign({},
|
||||
this.runtime.getTargetForStage().variables,
|
||||
this.editingTarget.variables
|
||||
);
|
||||
const globalVarMap = Object.assign({}, this.runtime.getTargetForStage().variables);
|
||||
const localVarMap = this.editingTarget.isStage ?
|
||||
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)
|
||||
.map(k => this.editingTarget.comments[k])
|
||||
.filter(c => c.blockId === null);
|
||||
|
||||
const xmlString = `<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||
<variables>
|
||||
${variables.map(v => v.toXML()).join()}
|
||||
${globalVariables.map(v => v.toXML()).join()}
|
||||
${localVariables.map(v => v.toXML(true)).join()}
|
||||
</variables>
|
||||
${workspaceComments.map(c => c.toXML()).join()}
|
||||
${this.editingTarget.blocks.toXML(this.editingTarget.comments)}
|
||||
|
|
Loading…
Reference in a new issue