mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-03-14 01:09:51 -04:00
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:
parent
fbee37e915
commit
59a865ef47
7 changed files with 21 additions and 24 deletions
src
test
|
@ -165,8 +165,7 @@ class Scratch3ControlBlocks {
|
||||||
// Create clone
|
// Create clone
|
||||||
const newClone = cloneTarget.makeClone();
|
const newClone = cloneTarget.makeClone();
|
||||||
if (newClone) {
|
if (newClone) {
|
||||||
this.runtime.targets.push(newClone);
|
this.runtime.addTarget(newClone);
|
||||||
this.runtime.addExecutable(newClone);
|
|
||||||
|
|
||||||
// Place behind the original target.
|
// Place behind the original target.
|
||||||
newClone.goBehindOther(cloneTarget);
|
newClone.goBehindOther(cloneTarget);
|
||||||
|
|
|
@ -1560,11 +1560,14 @@ class Runtime extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a target to the execution order.
|
* Add a target to the runtime. This tracks the sprite pane
|
||||||
* @param {Target} executableTarget target to add
|
* 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) {
|
addTarget (target) {
|
||||||
this.executableTargets.push(executableTarget);
|
this.targets.push(target);
|
||||||
|
this.executableTargets.push(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -495,17 +495,15 @@ class VirtualMachine extends EventEmitter {
|
||||||
|
|
||||||
return Promise.all(extensionPromises).then(() => {
|
return Promise.all(extensionPromises).then(() => {
|
||||||
targets.forEach(target => {
|
targets.forEach(target => {
|
||||||
this.runtime.targets.push(target);
|
this.runtime.addTarget(target);
|
||||||
(/** @type RenderedTarget */ target).updateAllDrawableProperties();
|
(/** @type RenderedTarget */ target).updateAllDrawableProperties();
|
||||||
// Ensure unique sprite name
|
// Ensure unique sprite name
|
||||||
if (target.isSprite()) this.renameSprite(target.id, target.getName());
|
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.
|
// Remove layerOrder property after use.
|
||||||
const executableTargets = targets.slice()
|
this.runtime.executableTargets.sort((a, b) => a.layerOrder - b.layerOrder);
|
||||||
.sort((a, b) => a.layerOrder - b.layerOrder);
|
targets.forEach(target => {
|
||||||
executableTargets.forEach(target => {
|
|
||||||
this.runtime.addExecutable(target);
|
|
||||||
delete target.layerOrder;
|
delete target.layerOrder;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1025,8 +1023,7 @@ class VirtualMachine extends EventEmitter {
|
||||||
throw new Error('No sprite associated with this target.');
|
throw new Error('No sprite associated with this target.');
|
||||||
}
|
}
|
||||||
return target.duplicate().then(newTarget => {
|
return target.duplicate().then(newTarget => {
|
||||||
this.runtime.targets.push(newTarget);
|
this.runtime.addTarget(newTarget);
|
||||||
this.runtime.addExecutable(newTarget);
|
|
||||||
newTarget.goBehindOther(target);
|
newTarget.goBehindOther(target);
|
||||||
this.setEditingTarget(newTarget.id);
|
this.setEditingTarget(newTarget.id);
|
||||||
});
|
});
|
||||||
|
|
|
@ -193,8 +193,7 @@ test('edge activated hat should trigger for both sprites when sprite is cloned',
|
||||||
t.equal(numTargetEdgeHats, 1);
|
t.equal(numTargetEdgeHats, 1);
|
||||||
|
|
||||||
const cloneTarget = vm.runtime.targets[1].makeClone();
|
const cloneTarget = vm.runtime.targets[1].makeClone();
|
||||||
vm.runtime.targets.push(cloneTarget);
|
vm.runtime.addTarget(cloneTarget);
|
||||||
vm.runtime.addExecutable(cloneTarget);
|
|
||||||
|
|
||||||
vm.runtime._step();
|
vm.runtime._step();
|
||||||
// Check that the runtime's _edgeActivatedHatValues object has two separate keys
|
// Check that the runtime's _edgeActivatedHatValues object has two separate keys
|
||||||
|
|
|
@ -54,9 +54,8 @@ test('#760 - broadcastAndWait', t => {
|
||||||
const tgt = new Target(rt, b);
|
const tgt = new Target(rt, b);
|
||||||
tgt.isStage = true;
|
tgt.isStage = true;
|
||||||
tgt.createVariable('testBroadcastID', 'message', Variable.BROADCAST_MESSAGE_TYPE);
|
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.addTarget(tgt);
|
||||||
rt.executableTargets.push(tgt);
|
|
||||||
|
|
||||||
let th = rt._pushThread('broadcastAndWaitBlock', t);
|
let th = rt._pushThread('broadcastAndWaitBlock', t);
|
||||||
const util = new BlockUtility();
|
const util = new BlockUtility();
|
||||||
|
|
|
@ -48,7 +48,7 @@ const testCostume = (costumes, arg, currentCostume = 1, isStage = false) => {
|
||||||
|
|
||||||
if (isStage) {
|
if (isStage) {
|
||||||
target.isStage = true;
|
target.isStage = true;
|
||||||
rt.targets.push(target);
|
rt.addTarget(target);
|
||||||
looks.switchBackdrop({BACKDROP: arg}, {target});
|
looks.switchBackdrop({BACKDROP: arg}, {target});
|
||||||
} else {
|
} else {
|
||||||
looks.switchCostume({COSTUME: arg}, {target});
|
looks.switchCostume({COSTUME: arg}, {target});
|
||||||
|
|
|
@ -188,7 +188,7 @@ test('renameVariable calls cloud io device\'s requestRenameVariable function', t
|
||||||
target.isStage = true;
|
target.isStage = true;
|
||||||
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
|
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
|
||||||
target.variables[mockCloudVar.id] = mockCloudVar;
|
target.variables[mockCloudVar.id] = mockCloudVar;
|
||||||
runtime.targets.push(target);
|
runtime.addTarget(target);
|
||||||
|
|
||||||
target.renameVariable('foo', 'bar2');
|
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 target = new Target(runtime);
|
||||||
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
|
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
|
||||||
target.variables[mockCloudVar.id] = mockCloudVar;
|
target.variables[mockCloudVar.id] = mockCloudVar;
|
||||||
runtime.targets.push(target);
|
runtime.addTarget(target);
|
||||||
|
|
||||||
target.renameVariable('foo', 'bar2');
|
target.renameVariable('foo', 'bar2');
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ test('deleteVariable calls cloud io device\'s requestRenameVariable function', t
|
||||||
target.isStage = true;
|
target.isStage = true;
|
||||||
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
|
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
|
||||||
target.variables[mockCloudVar.id] = mockCloudVar;
|
target.variables[mockCloudVar.id] = mockCloudVar;
|
||||||
runtime.targets.push(target);
|
runtime.addTarget(target);
|
||||||
|
|
||||||
target.deleteVariable('foo');
|
target.deleteVariable('foo');
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ test('deleteVariable calls cloud io device\'s requestRenameVariable function', t
|
||||||
const target = new Target(runtime);
|
const target = new Target(runtime);
|
||||||
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
|
const mockCloudVar = new Variable('foo', 'bar', Variable.SCALAR_TYPE, true);
|
||||||
target.variables[mockCloudVar.id] = mockCloudVar;
|
target.variables[mockCloudVar.id] = mockCloudVar;
|
||||||
runtime.targets.push(target);
|
runtime.addTarget(target);
|
||||||
|
|
||||||
target.deleteVariable('foo');
|
target.deleteVariable('foo');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue