From 73cb82319907b568febc5b74c5c91346e0506329 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Mon, 15 May 2017 08:30:02 -0400 Subject: [PATCH] Add delete costume and sound functions to the vm public api --- src/virtual-machine.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index cf4d0e636..a0da9b22f 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -286,6 +286,20 @@ class VirtualMachine extends EventEmitter { }); } + /** + * Delete a costume from the current editing target. + * @param {int} costumeIndex - the index of the costume to be removed. + */ + deleteCostume (costumeIndex) { + this.editingTarget.sprite.costumes = this.editingTarget.sprite.costumes + .slice(0, costumeIndex) + .concat(this.editingTarget.sprite.costumes.slice(costumeIndex + 1)); + if (costumeIndex === this.editingTarget.currentCostume) { + this.editingTarget.setCostume(costumeIndex - 1); + } + this.emitTargetsUpdate(); + } + /** * Add a sound to the current editing target. * @param {!object} soundObject Object representing the costume. @@ -298,6 +312,17 @@ class VirtualMachine extends EventEmitter { }); } + /** + * Delete a sound from the current editing target. + * @param {int} soundIndex - the index of the sound to be removed. + */ + deleteSound (soundIndex) { + this.editingTarget.sprite.sounds = this.editingTarget.sprite.sounds + .slice(0, soundIndex) + .concat(this.editingTarget.sprite.sounds.slice(soundIndex + 1)); + this.emitTargetsUpdate(); + } + /** * Add a backdrop to the stage. * @param {string} md5ext - the MD5 and extension of the backdrop to be loaded.