Add draggable property to sprites

This property should be managed by the VM so that it can be displayed in the sprite info panel in the GUI.
This commit is contained in:
Ray Schamp 2017-03-01 18:49:17 -05:00
parent 7042bdb45c
commit 8dadc42857
3 changed files with 26 additions and 0 deletions

View file

@ -104,6 +104,9 @@ var parseScratchObject = function (object, runtime, topLevel) {
if (object.hasOwnProperty('direction')) {
target.direction = object.direction;
}
if (object.hasOwnProperty('isDraggable')) {
target.draggable = object.isDraggable;
}
if (object.hasOwnProperty('scale')) {
// SB2 stores as 1.0 = 100%; we use % in the VM.
target.size = object.scale * 100;

View file

@ -106,6 +106,12 @@ RenderedTarget.prototype.y = 0;
*/
RenderedTarget.prototype.direction = 90;
/**
* Whether the rendered target is draggable on the stage
* @type {boolean}
*/
RenderedTarget.prototype.draggable = false;
/**
* Whether the rendered target is currently visible.
* @type {boolean}
@ -229,6 +235,16 @@ RenderedTarget.prototype.setDirection = function (direction) {
this.runtime.spriteInfoReport(this);
};
/**
* Set draggability; i.e., whether it's able to be dragged in the player
* @param {!boolean} draggable True if should be draggable.
*/
RenderedTarget.prototype.setDraggable = function (draggable) {
if (this.isStage) return;
this.draggable = !!draggable;
this.runtime.spriteInfoReport(this);
};
/**
* Set a say bubble.
* @param {?string} type Type of say bubble: "say", "think", or null.
@ -431,6 +447,7 @@ RenderedTarget.prototype.updateAllDrawableProperties = function () {
var props = {
position: [this.x, this.y],
direction: renderedDirectionScale.direction,
draggable: this.draggable,
scale: renderedDirectionScale.scale,
visible: this.visible,
skin: costume.skin,
@ -656,6 +673,7 @@ RenderedTarget.prototype.makeClone = function () {
newClone.x = this.x;
newClone.y = this.y;
newClone.direction = this.direction;
newClone.draggable = this.draggable;
newClone.visible = this.visible;
newClone.size = this.size;
newClone.currentCostume = this.currentCostume;
@ -703,6 +721,9 @@ RenderedTarget.prototype.postSpriteInfo = function (data) {
if (data.hasOwnProperty('direction')) {
this.setDirection(data.direction);
}
if (data.hasOwnProperty('draggable')) {
this.setDraggable(data.draggable);
}
if (data.hasOwnProperty('rotationStyle')) {
this.setRotationStyle(data.rotationStyle);
}
@ -723,6 +744,7 @@ RenderedTarget.prototype.toJSON = function () {
x: this.x,
y: this.y,
direction: this.direction,
draggable: this.draggable,
costume: this.getCurrentCostume(),
costumeCount: this.getCostumes().length,
visible: this.visible,

View file

@ -34,6 +34,7 @@ test('complex', function (t) {
x: 0,
y: 10,
direction: 90,
draggable: true,
rotationStyle: 'all around',
visible: true
});