Merge pull request #629 from marisaleung/develop

ChangeBlock uses id's of variable instead of name.
This commit is contained in:
Paul Kaplan 2017-06-30 08:10:55 -04:00 committed by GitHub
commit 6fa49b1e7a
3 changed files with 34 additions and 6 deletions

View file

@ -296,7 +296,16 @@ class Blocks {
case 'field':
// Update block value
if (!block.fields[args.name]) return;
block.fields[args.name].value = args.value;
if (args.name === 'VARIABLE') {
// Get variable name using the id in args.value.
const variable = optRuntime.getEditingTarget().lookupVariableById(args.value);
if (variable) {
block.fields[args.name].value = variable.name;
block.fields[args.name].id = args.value;
}
} else {
block.fields[args.name].value = args.value;
}
break;
case 'mutation':
block.mutation = mutationAdapter(args.value);

View file

@ -991,6 +991,14 @@ class Runtime extends EventEmitter {
}
}
/**
* Get the editing target.
* @return {?Target} The editing target.
*/
getEditingTarget () {
return this._editingTarget;
}
/**
* Tell the runtime to request a redraw.
* Use after a clone/sprite has completed some visible operation on the stage.

View file

@ -79,12 +79,27 @@ class Target extends EventEmitter {
/**
* Look up a variable object, and create it if one doesn't exist.
* Search begins for local variables; then look for globals.
* @param {string} id Id of the variable.
* @param {string} name Name of the variable.
* @return {!Variable} Variable object.
*/
lookupOrCreateVariable (id, name) {
const variable = this.lookupVariableById(id);
if (variable) return variable;
// No variable with this name exists - create it locally.
const newVariable = new Variable(id, name, 0, false);
this.variables[id] = newVariable;
return newVariable;
}
/**
* Look up a variable object.
* Search begins for local variables; then look for globals.
* @param {string} id Id of the variable.
* @param {string} name Name of the variable.
* @return {!Variable} Variable object.
*/
lookupVariableById (id) {
// If we have a local copy, return it.
if (this.variables.hasOwnProperty(id)) {
return this.variables[id];
@ -96,10 +111,6 @@ class Target extends EventEmitter {
return stage.variables[id];
}
}
// No variable with this name exists - create it locally.
const newVariable = new Variable(id, name, 0, false);
this.variables[id] = newVariable;
return newVariable;
}
/**