Make index optional

This commit is contained in:
DD 2018-02-23 16:24:18 -05:00
parent 10789cd779
commit 9a65df4c12
2 changed files with 16 additions and 28 deletions

View file

@ -401,22 +401,16 @@ class RenderedTarget extends Target {
/**
* Add a costume, taking care to avoid duplicate names.
* @param {!object} costumeObject Object representing the costume.
* @param {?int} index Index at which to add costume
*/
addCostume (costumeObject) {
addCostume (costumeObject, index) {
const usedNames = this.sprite.costumes.map(costume => costume.name);
costumeObject.name = StringUtil.unusedName(costumeObject.name, usedNames);
this.sprite.costumes.push(costumeObject);
}
/**
* Add a costume at the given index, taking care to avoid duplicate names.
* @param {!object} costumeObject Object representing the costume.
* @param {!int} index Index at which to add costume
*/
addCostumeAt (costumeObject, index) {
const usedNames = this.sprite.costumes.map(costume => costume.name);
costumeObject.name = StringUtil.unusedName(costumeObject.name, usedNames);
this.sprite.costumes.splice(index, 0, costumeObject);
if (index) {
this.sprite.costumes.splice(index, 0, costumeObject);
} else {
this.sprite.costumes.push(costumeObject);
}
}
/**
@ -472,22 +466,16 @@ class RenderedTarget extends Target {
/**
* Add a sound, taking care to avoid duplicate names.
* @param {!object} soundObject Object representing the sound.
* @param {!int} index Index at which to add costume
* @param {?int} index Index at which to add costume
*/
addSoundAt (soundObject, index) {
addSound (soundObject, index) {
const usedNames = this.sprite.sounds.map(sound => sound.name);
soundObject.name = StringUtil.unusedName(soundObject.name, usedNames);
this.sprite.sounds.splice(index, 0, soundObject);
}
/**
* Add a sound, taking care to avoid duplicate names.
* @param {!object} soundObject Object representing the sound.
*/
addSound (soundObject) {
const usedNames = this.sprite.sounds.map(sound => sound.name);
soundObject.name = StringUtil.unusedName(soundObject.name, usedNames);
this.sprite.sounds.push(soundObject);
if (index) {
this.sprite.sounds.splice(index, 0, soundObject);
} else {
this.sprite.sounds.push(soundObject);
}
}
/**

View file

@ -337,7 +337,7 @@ class VirtualMachine extends EventEmitter {
const clone = Object.assign({}, originalCostume);
const md5ext = `${clone.assetId}.${clone.dataFormat}`;
return loadCostume(md5ext, clone, this.runtime).then(() => {
this.editingTarget.addCostumeAt(clone, costumeIndex + 1);
this.editingTarget.addCostume(clone, costumeIndex + 1);
this.editingTarget.setCostume(costumeIndex + 1);
this.emitTargetsUpdate();
});
@ -352,7 +352,7 @@ class VirtualMachine extends EventEmitter {
const originalSound = this.editingTarget.getSounds()[soundIndex];
const clone = Object.assign({}, originalSound);
return loadSound(clone, this.runtime).then(() => {
this.editingTarget.addSoundAt(clone, soundIndex + 1);
this.editingTarget.addSound(clone, soundIndex + 1);
this.emitTargetsUpdate();
});
}