Merge pull request #487 from rschamp/draggability

Add draggable property to sprites
This commit is contained in:
Ray Schamp 2017-03-02 15:56:12 -05:00 committed by GitHub
commit 319f27a060
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.
@ -432,6 +448,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,
@ -657,6 +674,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;
@ -704,6 +722,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);
}
@ -724,6 +745,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
});