mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
ChangeBlock uses id's of variable instead of name.
This commit is contained in:
parent
b0fb4f0b55
commit
22f87e32f8
3 changed files with 34 additions and 6 deletions
|
@ -296,7 +296,16 @@ class Blocks {
|
||||||
case 'field':
|
case 'field':
|
||||||
// Update block value
|
// Update block value
|
||||||
if (!block.fields[args.name]) return;
|
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;
|
break;
|
||||||
case 'mutation':
|
case 'mutation':
|
||||||
block.mutation = mutationAdapter(args.value);
|
block.mutation = mutationAdapter(args.value);
|
||||||
|
|
|
@ -981,6 +981,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.
|
* Tell the runtime to request a redraw.
|
||||||
* Use after a clone/sprite has completed some visible operation on the stage.
|
* Use after a clone/sprite has completed some visible operation on the stage.
|
||||||
|
|
|
@ -71,12 +71,27 @@ class Target extends EventEmitter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up a variable object, and create it if one doesn't exist.
|
* 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} id Id of the variable.
|
||||||
* @param {string} name Name of the variable.
|
* @param {string} name Name of the variable.
|
||||||
* @return {!Variable} Variable object.
|
* @return {!Variable} Variable object.
|
||||||
*/
|
*/
|
||||||
lookupOrCreateVariable (id, name) {
|
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 we have a local copy, return it.
|
||||||
if (this.variables.hasOwnProperty(id)) {
|
if (this.variables.hasOwnProperty(id)) {
|
||||||
return this.variables[id];
|
return this.variables[id];
|
||||||
|
@ -88,10 +103,6 @@ class Target extends EventEmitter {
|
||||||
return stage.variables[id];
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue