mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #353 from rschamp/feature/sprite-info
Report costume data in sprite info reports and targetsUpdate
This commit is contained in:
commit
a55a422a3e
4 changed files with 45 additions and 15 deletions
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue