mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Merge branch 'develop' into updateMonitorsAction
This commit is contained in:
commit
adc60001ee
3 changed files with 21 additions and 4 deletions
|
@ -672,7 +672,6 @@ class Runtime extends EventEmitter {
|
||||||
* inactive threads after each iteration.
|
* inactive threads after each iteration.
|
||||||
*/
|
*/
|
||||||
_step () {
|
_step () {
|
||||||
this._refreshTargets = false;
|
|
||||||
// Find all edge-activated hats, and add them to threads to be evaluated.
|
// Find all edge-activated hats, and add them to threads to be evaluated.
|
||||||
for (const hatType in this._hats) {
|
for (const hatType in this._hats) {
|
||||||
if (!this._hats.hasOwnProperty(hatType)) continue;
|
if (!this._hats.hasOwnProperty(hatType)) continue;
|
||||||
|
@ -694,7 +693,11 @@ class Runtime extends EventEmitter {
|
||||||
// @todo: Only render when this.redrawRequested or clones rendered.
|
// @todo: Only render when this.redrawRequested or clones rendered.
|
||||||
this.renderer.draw();
|
this.renderer.draw();
|
||||||
}
|
}
|
||||||
if (this._refreshTargets) this.emit(Runtime.TARGETS_UPDATE);
|
|
||||||
|
if (this._refreshTargets) {
|
||||||
|
this.emit(Runtime.TARGETS_UPDATE);
|
||||||
|
this._refreshTargets = false;
|
||||||
|
}
|
||||||
|
|
||||||
// @todo(vm#570) only emit if monitors has changed since last time.
|
// @todo(vm#570) only emit if monitors has changed since last time.
|
||||||
this.emit(Runtime.MONITORS_UPDATE,
|
this.emit(Runtime.MONITORS_UPDATE,
|
||||||
|
|
|
@ -332,9 +332,8 @@ class VirtualMachine extends EventEmitter {
|
||||||
}
|
}
|
||||||
if (newName && RESERVED_NAMES.indexOf(newName) === -1) {
|
if (newName && RESERVED_NAMES.indexOf(newName) === -1) {
|
||||||
const names = this.runtime.targets
|
const names = this.runtime.targets
|
||||||
.filter(runtimeTarget => runtimeTarget.isSprite())
|
.filter(runtimeTarget => runtimeTarget.isSprite() && runtimeTarget.id !== target.id)
|
||||||
.map(runtimeTarget => runtimeTarget.sprite.name);
|
.map(runtimeTarget => runtimeTarget.sprite.name);
|
||||||
|
|
||||||
sprite.name = StringUtil.unusedName(newName, names);
|
sprite.name = StringUtil.unusedName(newName, names);
|
||||||
}
|
}
|
||||||
this.emitTargetsUpdate();
|
this.emitTargetsUpdate();
|
||||||
|
|
|
@ -94,3 +94,18 @@ test('renameSprite increments from existing sprite names', t => {
|
||||||
t.equal(vm.runtime.targets[0].sprite.name, 'that name2');
|
t.equal(vm.runtime.targets[0].sprite.name, 'that name2');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('renameSprite does not increment when renaming to the same name', t => {
|
||||||
|
const vm = new VirtualMachine();
|
||||||
|
vm.emitTargetsUpdate = () => {};
|
||||||
|
vm.runtime.targets = [{
|
||||||
|
id: 'id1',
|
||||||
|
isSprite: () => true,
|
||||||
|
sprite: {
|
||||||
|
name: 'this name'
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
vm.renameSprite('id1', 'this name');
|
||||||
|
t.equal(vm.runtime.targets[0].sprite.name, 'this name');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue