mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Moving block updating code into blocks instead of runtime.
This commit is contained in:
parent
784341909b
commit
0b2eaa9e19
2 changed files with 29 additions and 29 deletions
|
@ -321,7 +321,11 @@ class Blocks {
|
||||||
stage.renameVariable(e.varId, e.newName);
|
stage.renameVariable(e.varId, e.newName);
|
||||||
// Update all the blocks that use the renamed variable.
|
// Update all the blocks that use the renamed variable.
|
||||||
if (optRuntime) {
|
if (optRuntime) {
|
||||||
optRuntime.updateBlocksAfterVarRename(e.varId, e.newName);
|
const targets = optRuntime.targets;
|
||||||
|
for (let i = 0; i < targets.length; i++) {
|
||||||
|
const currTarget = targets[i];
|
||||||
|
currTarget.blocks.updateBlocksAfterVarRename(e.varId, e.newName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'var_delete':
|
case 'var_delete':
|
||||||
|
@ -550,6 +554,29 @@ class Blocks {
|
||||||
this.resetCache();
|
this.resetCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep blocks up to date after a variable gets renamed.
|
||||||
|
* @param {string} varId The id of the variable that was renamed
|
||||||
|
* @param {string} newName The new name of the variable that was renamed
|
||||||
|
*/
|
||||||
|
updateBlocksAfterVarRename (varId, newName) {
|
||||||
|
const blocks = this._blocks;
|
||||||
|
for (const blockId in blocks) {
|
||||||
|
let varOrListField = null;
|
||||||
|
if (blocks[blockId].fields.VARIABLE) {
|
||||||
|
varOrListField = blocks[blockId].fields.VARIABLE;
|
||||||
|
} else if (blocks[blockId].fields.LIST) {
|
||||||
|
varOrListField = blocks[blockId].fields.LIST;
|
||||||
|
}
|
||||||
|
if (varOrListField) {
|
||||||
|
const currFieldId = varOrListField.id;
|
||||||
|
if (varId === currFieldId) {
|
||||||
|
varOrListField.value = newName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1581,33 +1581,6 @@ class Runtime extends EventEmitter {
|
||||||
disableProfiling () {
|
disableProfiling () {
|
||||||
this.profiler = null;
|
this.profiler = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Keep blocks up to date after a variable gets renamed.
|
|
||||||
* @param {string} varId The id of the variable that was renamed
|
|
||||||
* @param {string} newName The new name of the variable that was renamed
|
|
||||||
*/
|
|
||||||
updateBlocksAfterVarRename (varId, newName) {
|
|
||||||
const allTargets = this.targets;
|
|
||||||
for (let i = 0; i < allTargets.length; i++) {
|
|
||||||
const currTarget = allTargets[i];
|
|
||||||
const currBlocks = currTarget.blocks._blocks;
|
|
||||||
for (const blockId in currBlocks) {
|
|
||||||
let varOrListField = null;
|
|
||||||
if (currBlocks[blockId].fields.VARIABLE) {
|
|
||||||
varOrListField = currBlocks[blockId].fields.VARIABLE;
|
|
||||||
} else if (currBlocks[blockId].fields.LIST) {
|
|
||||||
varOrListField = currBlocks[blockId].fields.LIST;
|
|
||||||
}
|
|
||||||
if (varOrListField) {
|
|
||||||
const currFieldId = varOrListField.id;
|
|
||||||
if (varId === currFieldId) {
|
|
||||||
varOrListField.value = newName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue