Create a new addTarget function on the runtime which populates the targets list as well as the executable targets list.

This commit is contained in:
Karishma Chadha 2019-01-14 11:48:11 -05:00
parent fbee37e915
commit 59a865ef47
7 changed files with 21 additions and 24 deletions

View file

@ -165,8 +165,7 @@ class Scratch3ControlBlocks {
// Create clone
const newClone = cloneTarget.makeClone();
if (newClone) {
this.runtime.targets.push(newClone);
this.runtime.addExecutable(newClone);
this.runtime.addTarget(newClone);
// Place behind the original target.
newClone.goBehindOther(cloneTarget);

View file

@ -1560,11 +1560,14 @@ class Runtime extends EventEmitter {
}
/**
* Add a target to the execution order.
* @param {Target} executableTarget target to add
* Add a target to the runtime. This tracks the sprite pane
* ordering of the target. The target still needs to be put
* into the correct execution order after calling this function.
* @param {Target} target target to add
*/
addExecutable (executableTarget) {
this.executableTargets.push(executableTarget);
addTarget (target) {
this.targets.push(target);
this.executableTargets.push(target);
}
/**

View file

@ -495,17 +495,15 @@ class VirtualMachine extends EventEmitter {
return Promise.all(extensionPromises).then(() => {
targets.forEach(target => {
this.runtime.targets.push(target);
this.runtime.addTarget(target);
(/** @type RenderedTarget */ target).updateAllDrawableProperties();
// Ensure unique sprite name
if (target.isSprite()) this.renameSprite(target.id, target.getName());
});
// Initialize executable targets sorted by the layerOrder.
// Sort the executable targets by layerOrder.
// Remove layerOrder property after use.
const executableTargets = targets.slice()
.sort((a, b) => a.layerOrder - b.layerOrder);
executableTargets.forEach(target => {
this.runtime.addExecutable(target);
this.runtime.executableTargets.sort((a, b) => a.layerOrder - b.layerOrder);
targets.forEach(target => {
delete target.layerOrder;
});
@ -1025,8 +1023,7 @@ class VirtualMachine extends EventEmitter {
throw new Error('No sprite associated with this target.');
}
return target.duplicate().then(newTarget => {
this.runtime.targets.push(newTarget);
this.runtime.addExecutable(newTarget);
this.runtime.addTarget(newTarget);
newTarget.goBehindOther(target);
this.setEditingTarget(newTarget.id);
});

View file

@ -193,8 +193,7 @@ test('edge activated hat should trigger for both sprites when sprite is cloned',
t.equal(numTargetEdgeHats, 1);
const cloneTarget = vm.runtime.targets[1].makeClone();
vm.runtime.targets.push(cloneTarget);
vm.runtime.addExecutable(cloneTarget);
vm.runtime.addTarget(cloneTarget);
vm.runtime._step();
// Check that the runtime's _edgeActivatedHatValues object has two separate keys

View file

@ -54,9 +54,8 @@ test('#760 - broadcastAndWait', t => {
const tgt = new Target(rt, b);
tgt.isStage = true;
tgt.createVariable('testBroadcastID', 'message', Variable.BROADCAST_MESSAGE_TYPE);
// Need to add to both runtime.targets as well as runtime.executableTargets here
rt.targets.push(tgt);
rt.executableTargets.push(tgt);
rt.addTarget(tgt);
let th = rt._pushThread('broadcastAndWaitBlock', t);
const util = new BlockUtility();

View file

@ -48,7 +48,7 @@ const testCostume = (costumes, arg, currentCostume = 1, isStage = false) => {
if (isStage) {
target.isStage = true;
rt.targets.push(target);
rt.addTarget(target);
looks.switchBackdrop({BACKDROP: arg}, {target});
} else {
looks.switchCostume({COSTUME: arg}, {target});

View file

@ -188,7 +188,7 @@ test('renameVariable calls cloud io device\'s requestRenameVariable function', t
target.isStage = true;
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
target.variables[mockCloudVar.id] = mockCloudVar;
runtime.targets.push(target);
runtime.addTarget(target);
target.renameVariable('foo', 'bar2');
@ -215,7 +215,7 @@ test('renameVariable does not call cloud io device\'s requestRenameVariable func
const target = new Target(runtime);
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
target.variables[mockCloudVar.id] = mockCloudVar;
runtime.targets.push(target);
runtime.addTarget(target);
target.renameVariable('foo', 'bar2');
@ -266,7 +266,7 @@ test('deleteVariable calls cloud io device\'s requestRenameVariable function', t
target.isStage = true;
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
target.variables[mockCloudVar.id] = mockCloudVar;
runtime.targets.push(target);
runtime.addTarget(target);
target.deleteVariable('foo');
@ -288,7 +288,7 @@ test('deleteVariable calls cloud io device\'s requestRenameVariable function', t
const target = new Target(runtime);
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
target.variables[mockCloudVar.id] = mockCloudVar;
runtime.targets.push(target);
runtime.addTarget(target);
target.deleteVariable('foo');