mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Export the sprite and return an add function when deleting the sprite.
This commit is contained in:
parent
6e6e9b49cb
commit
5ef246a2b0
1 changed files with 8 additions and 2 deletions
|
@ -836,6 +836,7 @@ class VirtualMachine extends EventEmitter {
|
|||
/**
|
||||
* Delete a sprite and all its clones.
|
||||
* @param {string} targetId ID of a target whose sprite to delete.
|
||||
* @return {Function} Returns a function to restore the sprite that was deleted
|
||||
*/
|
||||
deleteSprite (targetId) {
|
||||
const target = this.runtime.getTargetById(targetId);
|
||||
|
@ -849,6 +850,10 @@ class VirtualMachine extends EventEmitter {
|
|||
if (!sprite) {
|
||||
throw new Error('No sprite associated with this target.');
|
||||
}
|
||||
const spritePromise = this.exportSprite(targetId, 'uint8array');
|
||||
const restoreSprite = () => {
|
||||
spritePromise.then(spriteBuffer => this.addSprite(spriteBuffer));
|
||||
};
|
||||
this.runtime.requestRemoveMonitorByTargetId(targetId);
|
||||
const currentEditingTarget = this.editingTarget;
|
||||
for (let i = 0; i < sprite.clones.length; i++) {
|
||||
|
@ -867,9 +872,10 @@ class VirtualMachine extends EventEmitter {
|
|||
}
|
||||
// Sprite object should be deleted by GC.
|
||||
this.emitTargetsUpdate();
|
||||
} else {
|
||||
throw new Error('No target with the provided id.');
|
||||
return restoreSprite;
|
||||
}
|
||||
|
||||
throw new Error('No target with the provided id.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue