Merge pull request #952 from kchadha/duplicate-sprite-names

Duplicating sprite should give new sprite a fresh name.
This commit is contained in:
kchadha 2018-02-28 17:13:19 -05:00 committed by GitHub
commit 8bebc1f5a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View file

@ -84,7 +84,7 @@ class Sprite {
newSprite.blocks = this.blocks.duplicate(); newSprite.blocks = this.blocks.duplicate();
const allNames = this.runtime.targets.map(t => t.name); const allNames = this.runtime.targets.map(t => t.sprite.name);
newSprite.name = StringUtil.unusedName(this.name, allNames); newSprite.name = StringUtil.unusedName(this.name, allNames);
const assetPromises = []; const assetPromises = [];

View file

@ -276,6 +276,26 @@ test('duplicateSprite duplicates a sprite when given id is associated with known
}); });
test('duplicateSprite assigns duplicated sprite a fresh name', t => {
const vm = new VirtualMachine();
const spr = new Sprite(null, vm.runtime);
spr.name = 'sprite1';
const currTarget = spr.createClone();
vm.editingTarget = currTarget;
vm.emitWorkspaceUpdate = () => null;
vm.runtime.targets = [currTarget];
t.equal(vm.runtime.targets.length, 1);
vm.duplicateSprite(currTarget.id).then(() => {
t.equal(vm.runtime.targets.length, 2);
t.equal(vm.runtime.targets[0].sprite.name, 'sprite1');
t.equal(vm.runtime.targets[1].sprite.name, 'sprite2');
t.end();
});
});
test('emitWorkspaceUpdate', t => { test('emitWorkspaceUpdate', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();
vm.runtime.targets = [ vm.runtime.targets = [