mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Refactor error throwing
This commit is contained in:
parent
4a7ba534c1
commit
a885e7d619
1 changed files with 9 additions and 15 deletions
|
@ -445,23 +445,17 @@ class VirtualMachine extends EventEmitter {
|
||||||
*/
|
*/
|
||||||
duplicateSprite (targetId) {
|
duplicateSprite (targetId) {
|
||||||
const target = this.runtime.getTargetById(targetId);
|
const target = this.runtime.getTargetById(targetId);
|
||||||
|
if (!target) {
|
||||||
if (target) {
|
|
||||||
if (!target.isSprite()) {
|
|
||||||
throw new Error('Cannot duplicate non-sprite targets.');
|
|
||||||
}
|
|
||||||
const sprite = target.sprite;
|
|
||||||
if (!sprite) {
|
|
||||||
throw new Error('No sprite associated with this target.');
|
|
||||||
}
|
|
||||||
|
|
||||||
target.duplicate().then(newTarget => {
|
|
||||||
this.runtime.targets.push(newTarget);
|
|
||||||
this.setEditingTarget(newTarget.id);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
throw new Error('No target with the provided id.');
|
throw new Error('No target with the provided id.');
|
||||||
|
} else if (!target.isSprite()) {
|
||||||
|
throw new Error('Cannot duplicate non-sprite targets.');
|
||||||
|
} else if (!target.sprite) {
|
||||||
|
throw new Error('No sprite associated with this target.');
|
||||||
}
|
}
|
||||||
|
target.duplicate().then(newTarget => {
|
||||||
|
this.runtime.targets.push(newTarget);
|
||||||
|
this.setEditingTarget(newTarget.id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue