diff --git a/src/engine/runtime.js b/src/engine/runtime.js index e94667015..532a35388 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1770,7 +1770,7 @@ class Runtime extends EventEmitter { } if (this._refreshTargets) { - this.emit(Runtime.TARGETS_UPDATE); + this.emit(Runtime.TARGETS_UPDATE, false /* Don't emit project changed */); this._refreshTargets = false; } diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 38eb79e9f..0db45536b 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -94,8 +94,8 @@ class VirtualMachine extends EventEmitter { this.runtime.on(Runtime.VISUAL_REPORT, visualReport => { this.emit(Runtime.VISUAL_REPORT, visualReport); }); - this.runtime.on(Runtime.TARGETS_UPDATE, () => { - this.emitTargetsUpdate(); + this.runtime.on(Runtime.TARGETS_UPDATE, emitProjectChanged => { + this.emitTargetsUpdate(emitProjectChanged); }); this.runtime.on(Runtime.MONITORS_UPDATE, monitorList => { this.emit(Runtime.MONITORS_UPDATE, monitorList); @@ -201,7 +201,7 @@ class VirtualMachine extends EventEmitter { clear () { this.runtime.dispose(); this.editingTarget = null; - this.emitTargetsUpdate(); + this.emitTargetsUpdate(false /* Don't emit project change */); } /** @@ -562,10 +562,12 @@ class VirtualMachine extends EventEmitter { .then(validatedInput => { const projectVersion = validatedInput[0].projectVersion; if (projectVersion === 2) { - return this._addSprite2(validatedInput[0], validatedInput[1]); + return this._addSprite2(validatedInput[0], validatedInput[1]) + .then(() => this.runtime.emitProjectChanged()); } if (projectVersion === 3) { - return this._addSprite3(validatedInput[0], validatedInput[1]); + return this._addSprite3(validatedInput[0], validatedInput[1]) + .then(() => this.runtime.emitProjectChanged()); } return Promise.reject(`${errorPrefix} Unable to verify sprite version.`); }) @@ -627,6 +629,7 @@ class VirtualMachine extends EventEmitter { target.setCostume( target.getCostumes().length - 1 ); + this.runtime.emitProjectChanged(); }); } // If the target cannot be found by id, return a rejected promise @@ -698,6 +701,7 @@ class VirtualMachine extends EventEmitter { const deletedCostume = this.editingTarget.deleteCostume(costumeIndex); if (deletedCostume) { const target = this.editingTarget; + this.runtime.emitProjectChanged(); return () => { target.addCostume(deletedCostume); this.emitTargetsUpdate(); @@ -797,6 +801,7 @@ class VirtualMachine extends EventEmitter { const target = this.editingTarget; const deletedSound = this.editingTarget.deleteSound(soundIndex); if (deletedSound) { + this.runtime.emitProjectChanged(); const restoreFun = () => { target.addSound(deletedSound); this.emitTargetsUpdate(); @@ -928,6 +933,7 @@ class VirtualMachine extends EventEmitter { const stage = this.runtime.getTargetForStage(); stage.addCostume(backdropObject); stage.setCostume(stage.getCostumes().length - 1); + this.runtime.emitProjectChanged(); }); } @@ -958,8 +964,9 @@ class VirtualMachine extends EventEmitter { const currTarget = allTargets[i]; currTarget.blocks.updateAssetName(oldName, newName, 'sprite'); } + + if (newUnusedName !== oldName) this.emitTargetsUpdate(); } - this.emitTargetsUpdate(); } else { throw new Error('No target with the provided id.'); } @@ -1281,7 +1288,9 @@ class VirtualMachine extends EventEmitter { // Currently editing target id. editingTarget: this.editingTarget ? this.editingTarget.id : null }); - if (triggerProjectChange) this.runtime.emitProjectChanged(); + if (triggerProjectChange) { + this.runtime.emitProjectChanged(); + } } /** @@ -1383,7 +1392,11 @@ class VirtualMachine extends EventEmitter { reorderCostume (targetId, costumeIndex, newIndex) { const target = this.runtime.getTargetById(targetId); if (target) { - return target.reorderCostume(costumeIndex, newIndex); + const reorderSuccessful = target.reorderCostume(costumeIndex, newIndex); + if (reorderSuccessful) { + this.runtime.emitProjectChanged(); + } + return reorderSuccessful; } return false; } @@ -1398,7 +1411,11 @@ class VirtualMachine extends EventEmitter { reorderSound (targetId, soundIndex, newIndex) { const target = this.runtime.getTargetById(targetId); if (target) { - return target.reorderSound(soundIndex, newIndex); + const reorderSuccessful = target.reorderSound(soundIndex, newIndex); + if (reorderSuccessful) { + this.runtime.emitProjectChanged(); + } + return reorderSuccessful; } return false; } @@ -1440,6 +1457,11 @@ class VirtualMachine extends EventEmitter { } else { this.editingTarget.postSpriteInfo(data); } + // Post sprite info means the gui has changed something about a sprite, + // either through the sprite info pane fields (e.g. direction, size) or + // through dragging a sprite on the stage + // Emit a project changed event. + this.runtime.emitProjectChanged(); } /**