diff --git a/playground/playground.js b/playground/playground.js index cd9f8dff0..81efb53b4 100644 --- a/playground/playground.js +++ b/playground/playground.js @@ -121,13 +121,13 @@ window.onload = function() { // Generate new select box. for (var i = 0; i < data.targetList.length; i++) { var targetOption = document.createElement('option'); - targetOption.setAttribute('value', data.targetList[i][0]); + targetOption.setAttribute('value', data.targetList[i].id); // If target id matches editingTarget id, select it. - if (data.targetList[i][0] == data.editingTarget) { + if (data.targetList[i].id == data.editingTarget) { targetOption.setAttribute('selected', 'selected'); } targetOption.appendChild( - document.createTextNode(data.targetList[i][1]) + document.createTextNode(data.targetList[i].name) ); selectedTarget.appendChild(targetOption); } @@ -154,6 +154,7 @@ window.onload = function() { }); vm.on('SPRITE_INFO_REPORT', function(data) { + if (data.id !== selectedTarget.value) return; // Not the editingTarget document.getElementById('sinfo-x').value = data.x; document.getElementById('sinfo-y').value = data.y; document.getElementById('sinfo-direction').value = data.direction; diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 5c7b788c4..a404ce421 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -723,20 +723,13 @@ Runtime.prototype.visualReport = function (blockId, value) { }; /** - * Emit a sprite info report if the provided target is the editing target. + * Emit a sprite info report if the provided target is the original sprite * @param {!Target} target Target to report sprite info for. */ Runtime.prototype.spriteInfoReport = function (target) { - if (target !== this._editingTarget) { - return; - } - this.emit(Runtime.SPRITE_INFO_REPORT, { - x: target.x, - y: target.y, - direction: target.direction, - visible: target.visible, - rotationStyle: target.rotationStyle - }); + if (!target.isOriginal) return; + + this.emit(Runtime.SPRITE_INFO_REPORT, target.toJSON()); }; /** diff --git a/src/index.js b/src/index.js index 4ed724f39..24e1d67b7 100644 --- a/src/index.js +++ b/src/index.js @@ -304,7 +304,7 @@ VirtualMachine.prototype.emitTargetsUpdate = function () { // Don't report clones. return !target.hasOwnProperty('isOriginal') || target.isOriginal; }).map(function (target) { - return [target.id, target.getName()]; + return target.toJSON(); }), // Currently editing target id. editingTarget: this.editingTarget ? this.editingTarget.id : null diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 50ad7e8f5..08ee727f8 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -329,6 +329,7 @@ RenderedTarget.prototype.setCostume = function (index) { this.runtime.requestRedraw(); } } + this.runtime.spriteInfoReport(this); }; /** @@ -370,6 +371,22 @@ RenderedTarget.prototype.getCostumeIndexByName = function (costumeName) { return -1; }; +/** + * Get a costume of this rendered target by id. + * @return {object} current costume + */ +RenderedTarget.prototype.getCurrentCostume = function () { + return this.sprite.costumes[this.currentCostume]; +}; + +/** + * Get full costume list + * @return {object[]} list of costumes + */ +RenderedTarget.prototype.getCostumes = function () { + return this.sprite.costumes; +}; + /** * Update all drawable properties for this rendered target. * Use when a batch has changed, e.g., when the drawable is first created. @@ -645,6 +662,25 @@ RenderedTarget.prototype.postSpriteInfo = function (data) { } }; +/** + * Serialize sprite info, used when emitting events about the sprite + * @returns {object} sprite data as a simple object + */ +RenderedTarget.prototype.toJSON = function () { + return { + id: this.id, + name: this.getName(), + isStage: this.isStage, + x: this.x, + y: this.y, + direction: this.direction, + costume: this.getCurrentCostume(), + costumeCount: this.getCostumes().length, + visible: this.visible, + rotationStyle: this.rotationStyle + }; +}; + /** * Dispose, destroying any run-time properties. */