Report full sprite info in targetsUpdate

We need more than just the name for the initial render, so send everything consistent with sprite info reports.
This commit is contained in:
Ray Schamp 2016-12-05 18:02:51 -05:00
parent adaf2df743
commit e9da046969
4 changed files with 32 additions and 13 deletions

View file

@ -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);
}

View file

@ -729,15 +729,7 @@ Runtime.prototype.visualReport = function (blockId, value) {
Runtime.prototype.spriteInfoReport = function (target) {
if (!target.isOriginal) return;
this.emit(Runtime.SPRITE_INFO_REPORT, {
id: target.id,
x: target.x,
y: target.y,
direction: target.direction,
costume: target.getCurrentCostume(),
visible: target.visible,
rotationStyle: target.rotationStyle
});
this.emit(Runtime.SPRITE_INFO_REPORT, target.toJSON());
};
/**

View file

@ -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

View file

@ -379,6 +379,14 @@ 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.
@ -654,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.
*/