Add delete costume and sound functions to the vm public api

This commit is contained in:
Paul Kaplan 2017-05-15 08:30:02 -04:00
parent e9c48d250b
commit 73cb823199

View file

@ -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. * Add a sound to the current editing target.
* @param {!object} soundObject Object representing the costume. * @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. * Add a backdrop to the stage.
* @param {string} md5ext - the MD5 and extension of the backdrop to be loaded. * @param {string} md5ext - the MD5 and extension of the backdrop to be loaded.