mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Rename Clone -> RenderedTarget (#317)
This commit is contained in:
parent
6e9b3f262c
commit
2f0ce7137c
5 changed files with 120 additions and 120 deletions
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Blocks = require('../engine/blocks');
|
var Blocks = require('../engine/blocks');
|
||||||
var Clone = require('../sprites/clone');
|
var RenderedTarget = require('../sprites/rendered-target');
|
||||||
var Sprite = require('../sprites/sprite');
|
var Sprite = require('../sprites/sprite');
|
||||||
var Color = require('../util/color.js');
|
var Color = require('../util/color.js');
|
||||||
var log = require('../util/log');
|
var log = require('../util/log');
|
||||||
|
@ -101,11 +101,11 @@ var parseScratchObject = function (object, runtime, topLevel) {
|
||||||
}
|
}
|
||||||
if (object.hasOwnProperty('rotationStyle')) {
|
if (object.hasOwnProperty('rotationStyle')) {
|
||||||
if (object.rotationStyle === 'none') {
|
if (object.rotationStyle === 'none') {
|
||||||
target.rotationStyle = Clone.ROTATION_STYLE_NONE;
|
target.rotationStyle = RenderedTarget.ROTATION_STYLE_NONE;
|
||||||
} else if (object.rotationStyle === 'leftRight') {
|
} else if (object.rotationStyle === 'leftRight') {
|
||||||
target.rotationStyle = Clone.ROTATION_STYLE_LEFT_RIGHT;
|
target.rotationStyle = RenderedTarget.ROTATION_STYLE_LEFT_RIGHT;
|
||||||
} else if (object.rotationStyle === 'normal') {
|
} else if (object.rotationStyle === 'normal') {
|
||||||
target.rotationStyle = Clone.ROTATION_STYLE_ALL_AROUND;
|
target.rotationStyle = RenderedTarget.ROTATION_STYLE_ALL_AROUND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
target.isStage = topLevel;
|
target.isStage = topLevel;
|
||||||
|
|
|
@ -5,16 +5,16 @@ var MathUtil = require('../util/math-util');
|
||||||
var Target = require('../engine/target');
|
var Target = require('../engine/target');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone (instance) of a sprite.
|
* Rendered target: instance of a sprite (clone), or the stage.
|
||||||
* @param {!Sprite} sprite Reference to the sprite.
|
* @param {!Sprite} sprite Reference to the parent sprite.
|
||||||
* @param {Runtime} runtime Reference to the runtime.
|
* @param {Runtime} runtime Reference to the runtime.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
var Clone = function (sprite, runtime) {
|
var RenderedTarget = function (sprite, runtime) {
|
||||||
Target.call(this, sprite.blocks);
|
Target.call(this, sprite.blocks);
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
/**
|
/**
|
||||||
* Reference to the sprite that this is a clone of.
|
* Reference to the sprite that this is a render of.
|
||||||
* @type {!Sprite}
|
* @type {!Sprite}
|
||||||
*/
|
*/
|
||||||
this.sprite = sprite;
|
this.sprite = sprite;
|
||||||
|
@ -27,7 +27,8 @@ var Clone = function (sprite, runtime) {
|
||||||
this.renderer = this.runtime.renderer;
|
this.renderer = this.runtime.renderer;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* ID of the drawable for this clone returned by the renderer, if rendered.
|
* ID of the drawable for this rendered target,
|
||||||
|
* returned by the renderer, if rendered.
|
||||||
* @type {?Number}
|
* @type {?Number}
|
||||||
*/
|
*/
|
||||||
this.drawableID = null;
|
this.drawableID = null;
|
||||||
|
@ -46,12 +47,12 @@ var Clone = function (sprite, runtime) {
|
||||||
ghost: 0
|
ghost: 0
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
util.inherits(Clone, Target);
|
util.inherits(RenderedTarget, Target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a clone's drawable with the this.renderer.
|
* Create a drawable with the this.renderer.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.initDrawable = function () {
|
RenderedTarget.prototype.initDrawable = function () {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
this.drawableID = this.renderer.createDrawable();
|
this.drawableID = this.renderer.createDrawable();
|
||||||
}
|
}
|
||||||
|
@ -63,88 +64,87 @@ Clone.prototype.initDrawable = function () {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clone-level properties.
|
|
||||||
/**
|
/**
|
||||||
* Whether this represents an "original" clone, i.e., created by the editor
|
* Whether this represents an "original" non-clone rendered-target for a sprite,
|
||||||
* and not clone blocks. In interface terms, this true for a "sprite."
|
* i.e., created by the editor and not clone blocks.
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
Clone.prototype.isOriginal = true;
|
RenderedTarget.prototype.isOriginal = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this clone represents the Scratch stage.
|
* Whether this rendered target represents the Scratch stage.
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
Clone.prototype.isStage = false;
|
RenderedTarget.prototype.isStage = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scratch X coordinate. Currently should range from -240 to 240.
|
* Scratch X coordinate. Currently should range from -240 to 240.
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
Clone.prototype.x = 0;
|
RenderedTarget.prototype.x = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scratch Y coordinate. Currently should range from -180 to 180.
|
* Scratch Y coordinate. Currently should range from -180 to 180.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
Clone.prototype.y = 0;
|
RenderedTarget.prototype.y = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scratch direction. Currently should range from -179 to 180.
|
* Scratch direction. Currently should range from -179 to 180.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
Clone.prototype.direction = 90;
|
RenderedTarget.prototype.direction = 90;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the clone is currently visible.
|
* Whether the rendered target is currently visible.
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
Clone.prototype.visible = true;
|
RenderedTarget.prototype.visible = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of clone as a percent of costume size. Ranges from 5% to 535%.
|
* Size of rendered target as a percent of costume size.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
Clone.prototype.size = 100;
|
RenderedTarget.prototype.size = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently selected costume index.
|
* Currently selected costume index.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
Clone.prototype.currentCostume = 0;
|
RenderedTarget.prototype.currentCostume = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotation style for "all around"/spinning.
|
* Rotation style for "all around"/spinning.
|
||||||
* @enum
|
* @enum
|
||||||
*/
|
*/
|
||||||
Clone.ROTATION_STYLE_ALL_AROUND = 'all around';
|
RenderedTarget.ROTATION_STYLE_ALL_AROUND = 'all around';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotation style for "left-right"/flipping.
|
* Rotation style for "left-right"/flipping.
|
||||||
* @enum
|
* @enum
|
||||||
*/
|
*/
|
||||||
Clone.ROTATION_STYLE_LEFT_RIGHT = 'left-right';
|
RenderedTarget.ROTATION_STYLE_LEFT_RIGHT = 'left-right';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotation style for "no rotation."
|
* Rotation style for "no rotation."
|
||||||
* @enum
|
* @enum
|
||||||
*/
|
*/
|
||||||
Clone.ROTATION_STYLE_NONE = 'don\'t rotate';
|
RenderedTarget.ROTATION_STYLE_NONE = 'don\'t rotate';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current rotation style.
|
* Current rotation style.
|
||||||
* @type {!string}
|
* @type {!string}
|
||||||
*/
|
*/
|
||||||
Clone.prototype.rotationStyle = Clone.ROTATION_STYLE_ALL_AROUND;
|
RenderedTarget.prototype.rotationStyle = (
|
||||||
|
RenderedTarget.ROTATION_STYLE_ALL_AROUND
|
||||||
// End clone-level properties.
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the X and Y coordinates of a clone.
|
* Set the X and Y coordinates.
|
||||||
* @param {!number} x New X coordinate of clone, in Scratch coordinates.
|
* @param {!number} x New X coordinate, in Scratch coordinates.
|
||||||
* @param {!number} y New Y coordinate of clone, in Scratch coordinates.
|
* @param {!number} y New Y coordinate, in Scratch coordinates.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.setXY = function (x, y) {
|
RenderedTarget.prototype.setXY = function (x, y) {
|
||||||
if (this.isStage) {
|
if (this.isStage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -164,14 +164,14 @@ Clone.prototype.setXY = function (x, y) {
|
||||||
* Get the rendered direction and scale, after applying rotation style.
|
* Get the rendered direction and scale, after applying rotation style.
|
||||||
* @return {Object<string, number>} Direction and scale to render.
|
* @return {Object<string, number>} Direction and scale to render.
|
||||||
*/
|
*/
|
||||||
Clone.prototype._getRenderedDirectionAndScale = function () {
|
RenderedTarget.prototype._getRenderedDirectionAndScale = function () {
|
||||||
// Default: no changes to `this.direction` or `this.scale`.
|
// Default: no changes to `this.direction` or `this.scale`.
|
||||||
var finalDirection = this.direction;
|
var finalDirection = this.direction;
|
||||||
var finalScale = [this.size, this.size];
|
var finalScale = [this.size, this.size];
|
||||||
if (this.rotationStyle === Clone.ROTATION_STYLE_NONE) {
|
if (this.rotationStyle === RenderedTarget.ROTATION_STYLE_NONE) {
|
||||||
// Force rendered direction to be 90.
|
// Force rendered direction to be 90.
|
||||||
finalDirection = 90;
|
finalDirection = 90;
|
||||||
} else if (this.rotationStyle === Clone.ROTATION_STYLE_LEFT_RIGHT) {
|
} else if (this.rotationStyle === RenderedTarget.ROTATION_STYLE_LEFT_RIGHT) {
|
||||||
// Force rendered direction to be 90, and flip drawable if needed.
|
// Force rendered direction to be 90, and flip drawable if needed.
|
||||||
finalDirection = 90;
|
finalDirection = 90;
|
||||||
var scaleFlip = (this.direction < 0) ? -1 : 1;
|
var scaleFlip = (this.direction < 0) ? -1 : 1;
|
||||||
|
@ -181,10 +181,10 @@ Clone.prototype._getRenderedDirectionAndScale = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the direction of a clone.
|
* Set the direction.
|
||||||
* @param {!number} direction New direction of clone.
|
* @param {!number} direction New direction.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.setDirection = function (direction) {
|
RenderedTarget.prototype.setDirection = function (direction) {
|
||||||
if (this.isStage) {
|
if (this.isStage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -203,11 +203,11 @@ Clone.prototype.setDirection = function (direction) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a say bubble on this clone.
|
* Set a say bubble.
|
||||||
* @param {?string} type Type of say bubble: "say", "think", or null.
|
* @param {?string} type Type of say bubble: "say", "think", or null.
|
||||||
* @param {?string} message Message to put in say bubble.
|
* @param {?string} message Message to put in say bubble.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.setSay = function (type, message) {
|
RenderedTarget.prototype.setSay = function (type, message) {
|
||||||
if (this.isStage) {
|
if (this.isStage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -220,10 +220,10 @@ Clone.prototype.setSay = function (type, message) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set visibility of the clone; i.e., whether it's shown or hidden.
|
* Set visibility; i.e., whether it's shown or hidden.
|
||||||
* @param {!boolean} visible True if the sprite should be shown.
|
* @param {!boolean} visible True if should be shown.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.setVisible = function (visible) {
|
RenderedTarget.prototype.setVisible = function (visible) {
|
||||||
if (this.isStage) {
|
if (this.isStage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -239,10 +239,10 @@ Clone.prototype.setVisible = function (visible) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set size of the clone, as a percentage of the costume size.
|
* Set size, as a percentage of the costume size.
|
||||||
* @param {!number} size Size of clone, from 5 to 535.
|
* @param {!number} size Size of rendered target, as % of costume size.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.setSize = function (size) {
|
RenderedTarget.prototype.setSize = function (size) {
|
||||||
if (this.isStage) {
|
if (this.isStage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -261,11 +261,11 @@ Clone.prototype.setSize = function (size) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a particular graphic effect on this clone.
|
* Set a particular graphic effect value.
|
||||||
* @param {!string} effectName Name of effect (see `Clone.prototype.effects`).
|
* @param {!string} effectName Name of effect (see `RenderedTarget.prototype.effects`).
|
||||||
* @param {!number} value Numerical magnitude of effect.
|
* @param {!number} value Numerical magnitude of effect.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.setEffect = function (effectName, value) {
|
RenderedTarget.prototype.setEffect = function (effectName, value) {
|
||||||
if (!this.effects.hasOwnProperty(effectName)) return;
|
if (!this.effects.hasOwnProperty(effectName)) return;
|
||||||
this.effects[effectName] = value;
|
this.effects[effectName] = value;
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
|
@ -279,9 +279,9 @@ Clone.prototype.setEffect = function (effectName, value) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all graphic effects on this clone.
|
* Clear all graphic effects on this rendered target.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.clearEffects = function () {
|
RenderedTarget.prototype.clearEffects = function () {
|
||||||
for (var effectName in this.effects) {
|
for (var effectName in this.effects) {
|
||||||
this.effects[effectName] = 0;
|
this.effects[effectName] = 0;
|
||||||
}
|
}
|
||||||
|
@ -294,10 +294,10 @@ Clone.prototype.clearEffects = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current costume of this clone.
|
* Set the current costume.
|
||||||
* @param {number} index New index of costume.
|
* @param {number} index New index of costume.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.setCostume = function (index) {
|
RenderedTarget.prototype.setCostume = function (index) {
|
||||||
// Keep the costume index within possible values.
|
// Keep the costume index within possible values.
|
||||||
index = Math.round(index);
|
index = Math.round(index);
|
||||||
this.currentCostume = MathUtil.wrapClamp(
|
this.currentCostume = MathUtil.wrapClamp(
|
||||||
|
@ -320,16 +320,16 @@ Clone.prototype.setCostume = function (index) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the rotation style for this clone.
|
* Update the rotation style.
|
||||||
* @param {!string} rotationStyle New rotation style.
|
* @param {!string} rotationStyle New rotation style.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.setRotationStyle = function (rotationStyle) {
|
RenderedTarget.prototype.setRotationStyle = function (rotationStyle) {
|
||||||
if (rotationStyle === Clone.ROTATION_STYLE_NONE) {
|
if (rotationStyle === RenderedTarget.ROTATION_STYLE_NONE) {
|
||||||
this.rotationStyle = Clone.ROTATION_STYLE_NONE;
|
this.rotationStyle = RenderedTarget.ROTATION_STYLE_NONE;
|
||||||
} else if (rotationStyle === Clone.ROTATION_STYLE_ALL_AROUND) {
|
} else if (rotationStyle === RenderedTarget.ROTATION_STYLE_ALL_AROUND) {
|
||||||
this.rotationStyle = Clone.ROTATION_STYLE_ALL_AROUND;
|
this.rotationStyle = RenderedTarget.ROTATION_STYLE_ALL_AROUND;
|
||||||
} else if (rotationStyle === Clone.ROTATION_STYLE_LEFT_RIGHT) {
|
} else if (rotationStyle === RenderedTarget.ROTATION_STYLE_LEFT_RIGHT) {
|
||||||
this.rotationStyle = Clone.ROTATION_STYLE_LEFT_RIGHT;
|
this.rotationStyle = RenderedTarget.ROTATION_STYLE_LEFT_RIGHT;
|
||||||
}
|
}
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
var renderedDirectionScale = this._getRenderedDirectionAndScale();
|
var renderedDirectionScale = this._getRenderedDirectionAndScale();
|
||||||
|
@ -344,11 +344,11 @@ Clone.prototype.setRotationStyle = function (rotationStyle) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a costume index of this clone, by name of the costume.
|
* Get a costume index of this rendered target, by name of the costume.
|
||||||
* @param {?string} costumeName Name of a costume.
|
* @param {?string} costumeName Name of a costume.
|
||||||
* @return {number} Index of the named costume, or -1 if not present.
|
* @return {number} Index of the named costume, or -1 if not present.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.getCostumeIndexByName = function (costumeName) {
|
RenderedTarget.prototype.getCostumeIndexByName = function (costumeName) {
|
||||||
for (var i = 0; i < this.sprite.costumes.length; i++) {
|
for (var i = 0; i < this.sprite.costumes.length; i++) {
|
||||||
if (this.sprite.costumes[i].name === costumeName) {
|
if (this.sprite.costumes[i].name === costumeName) {
|
||||||
return i;
|
return i;
|
||||||
|
@ -358,10 +358,10 @@ Clone.prototype.getCostumeIndexByName = function (costumeName) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update all drawable properties for this clone.
|
* Update all drawable properties for this rendered target.
|
||||||
* Use when a batch has changed, e.g., when the drawable is first created.
|
* Use when a batch has changed, e.g., when the drawable is first created.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.updateAllDrawableProperties = function () {
|
RenderedTarget.prototype.updateAllDrawableProperties = function () {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
var renderedDirectionScale = this._getRenderedDirectionAndScale();
|
var renderedDirectionScale = this._getRenderedDirectionAndScale();
|
||||||
var costume = this.sprite.costumes[this.currentCostume];
|
var costume = this.sprite.costumes[this.currentCostume];
|
||||||
|
@ -384,20 +384,20 @@ Clone.prototype.updateAllDrawableProperties = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the human-readable name for this clone, i.e., the sprite's name.
|
* Return the human-readable name for this rendered target, e.g., the sprite's name.
|
||||||
* @override
|
* @override
|
||||||
* @returns {string} Human-readable name for the clone.
|
* @returns {string} Human-readable name.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.getName = function () {
|
RenderedTarget.prototype.getName = function () {
|
||||||
return this.sprite.name;
|
return this.sprite.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the clone's tight bounding box.
|
* Return the rendered target's tight bounding box.
|
||||||
* Includes top, left, bottom, right attributes in Scratch coordinates.
|
* Includes top, left, bottom, right attributes in Scratch coordinates.
|
||||||
* @return {?Object} Tight bounding box of clone, or null.
|
* @return {?Object} Tight bounding box, or null.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.getBounds = function () {
|
RenderedTarget.prototype.getBounds = function () {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
return this.runtime.renderer.getBounds(this.drawableID);
|
return this.runtime.renderer.getBounds(this.drawableID);
|
||||||
}
|
}
|
||||||
|
@ -405,12 +405,12 @@ Clone.prototype.getBounds = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether the clone is touching a point.
|
* Return whether touching a point.
|
||||||
* @param {number} x X coordinate of test point.
|
* @param {number} x X coordinate of test point.
|
||||||
* @param {number} y Y coordinate of test point.
|
* @param {number} y Y coordinate of test point.
|
||||||
* @return {Boolean} True iff the clone is touching the point.
|
* @return {Boolean} True iff the rendered target is touching the point.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.isTouchingPoint = function (x, y) {
|
RenderedTarget.prototype.isTouchingPoint = function (x, y) {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
// @todo: Update once pick is in Scratch coordinates.
|
// @todo: Update once pick is in Scratch coordinates.
|
||||||
// Limits test to this Drawable, so this will return true
|
// Limits test to this Drawable, so this will return true
|
||||||
|
@ -427,10 +427,10 @@ Clone.prototype.isTouchingPoint = function (x, y) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether the clone is touching a stage edge.
|
* Return whether touching a stage edge.
|
||||||
* @return {Boolean} True iff the clone is touching the stage edge.
|
* @return {Boolean} True iff the rendered target is touching the stage edge.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.isTouchingEdge = function () {
|
RenderedTarget.prototype.isTouchingEdge = function () {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
var stageWidth = this.runtime.constructor.STAGE_WIDTH;
|
var stageWidth = this.runtime.constructor.STAGE_WIDTH;
|
||||||
var stageHeight = this.runtime.constructor.STAGE_HEIGHT;
|
var stageHeight = this.runtime.constructor.STAGE_HEIGHT;
|
||||||
|
@ -446,11 +446,11 @@ Clone.prototype.isTouchingEdge = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether the clone is touching a named sprite.
|
* Return whether touching any of a named sprite's clones.
|
||||||
* @param {string} spriteName Name fo the sprite.
|
* @param {string} spriteName Name of the sprite.
|
||||||
* @return {Boolean} True iff the clone is touching a clone of the sprite.
|
* @return {Boolean} True iff touching a clone of the sprite.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.isTouchingSprite = function (spriteName) {
|
RenderedTarget.prototype.isTouchingSprite = function (spriteName) {
|
||||||
var firstClone = this.runtime.getSpriteTargetByName(spriteName);
|
var firstClone = this.runtime.getSpriteTargetByName(spriteName);
|
||||||
if (!firstClone || !this.renderer) {
|
if (!firstClone || !this.renderer) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -463,11 +463,11 @@ Clone.prototype.isTouchingSprite = function (spriteName) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether the clone is touching a color.
|
* Return whether touching a color.
|
||||||
* @param {Array.<number>} rgb [r,g,b], values between 0-255.
|
* @param {Array.<number>} rgb [r,g,b], values between 0-255.
|
||||||
* @return {Promise.<Boolean>} True iff the clone is touching the color.
|
* @return {Promise.<Boolean>} True iff the rendered target is touching the color.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.isTouchingColor = function (rgb) {
|
RenderedTarget.prototype.isTouchingColor = function (rgb) {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
return this.renderer.isTouchingColor(this.drawableID, rgb);
|
return this.renderer.isTouchingColor(this.drawableID, rgb);
|
||||||
}
|
}
|
||||||
|
@ -475,12 +475,12 @@ Clone.prototype.isTouchingColor = function (rgb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether the clone's color is touching a color.
|
* Return whether rendered target's color is touching a color.
|
||||||
* @param {Object} targetRgb {Array.<number>} [r,g,b], values between 0-255.
|
* @param {Object} targetRgb {Array.<number>} [r,g,b], values between 0-255.
|
||||||
* @param {Object} maskRgb {Array.<number>} [r,g,b], values between 0-255.
|
* @param {Object} maskRgb {Array.<number>} [r,g,b], values between 0-255.
|
||||||
* @return {Promise.<Boolean>} True iff the clone's color is touching the color.
|
* @return {Promise.<Boolean>} True iff the color is touching the color.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.colorIsTouchingColor = function (targetRgb, maskRgb) {
|
RenderedTarget.prototype.colorIsTouchingColor = function (targetRgb, maskRgb) {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
return this.renderer.isTouchingColor(
|
return this.renderer.isTouchingColor(
|
||||||
this.drawableID,
|
this.drawableID,
|
||||||
|
@ -492,32 +492,32 @@ Clone.prototype.colorIsTouchingColor = function (targetRgb, maskRgb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move clone to the front layer.
|
* Move to the front layer.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.goToFront = function () {
|
RenderedTarget.prototype.goToFront = function () {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
this.renderer.setDrawableOrder(this.drawableID, Infinity);
|
this.renderer.setDrawableOrder(this.drawableID, Infinity);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move clone back a number of layers.
|
* Move back a number of layers.
|
||||||
* @param {number} nLayers How many layers to go back.
|
* @param {number} nLayers How many layers to go back.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.goBackLayers = function (nLayers) {
|
RenderedTarget.prototype.goBackLayers = function (nLayers) {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
this.renderer.setDrawableOrder(this.drawableID, -nLayers, true, 1);
|
this.renderer.setDrawableOrder(this.drawableID, -nLayers, true, 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move behind some other clone.
|
* Move behind some other rendered target.
|
||||||
* @param {!Clone} otherClone Other clone to move behind.
|
* @param {!Clone} other Other rendered target to move behind.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.goBehindOtherClone = function (otherClone) {
|
RenderedTarget.prototype.goBehindOther = function (other) {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
var otherLayer = this.renderer.setDrawableOrder(
|
var otherLayer = this.renderer.setDrawableOrder(
|
||||||
otherClone.drawableID, 0, true);
|
other.drawableID, 0, true);
|
||||||
this.renderer.setDrawableOrder(this.drawableID, otherLayer);
|
this.renderer.setDrawableOrder(this.drawableID, otherLayer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -529,7 +529,7 @@ Clone.prototype.goBehindOtherClone = function (otherClone) {
|
||||||
* @param {Object=} optFence Optional fence with left, right, top bottom.
|
* @param {Object=} optFence Optional fence with left, right, top bottom.
|
||||||
* @return {Array.<number>} Fenced X and Y coordinates.
|
* @return {Array.<number>} Fenced X and Y coordinates.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.keepInFence = function (newX, newY, optFence) {
|
RenderedTarget.prototype.keepInFence = function (newX, newY, optFence) {
|
||||||
var fence = optFence;
|
var fence = optFence;
|
||||||
if (!fence) {
|
if (!fence) {
|
||||||
fence = {
|
fence = {
|
||||||
|
@ -565,11 +565,11 @@ Clone.prototype.keepInFence = function (newX, newY, optFence) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a clone of this clone, copying any run-time properties.
|
* Make a clone, copying any run-time properties.
|
||||||
* If we've hit the global clone limit, returns null.
|
* If we've hit the global clone limit, returns null.
|
||||||
* @return {!Clone} New clone object.
|
* @return {!RenderedTarget} New clone.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.makeClone = function () {
|
RenderedTarget.prototype.makeClone = function () {
|
||||||
if (!this.runtime.clonesAvailable() || this.isStage) {
|
if (!this.runtime.clonesAvailable() || this.isStage) {
|
||||||
return; // Hit max clone limit, or this is the stage.
|
return; // Hit max clone limit, or this is the stage.
|
||||||
}
|
}
|
||||||
|
@ -588,23 +588,23 @@ Clone.prototype.makeClone = function () {
|
||||||
newClone.lists = JSON.parse(JSON.stringify(this.lists));
|
newClone.lists = JSON.parse(JSON.stringify(this.lists));
|
||||||
newClone.initDrawable();
|
newClone.initDrawable();
|
||||||
newClone.updateAllDrawableProperties();
|
newClone.updateAllDrawableProperties();
|
||||||
// Place clone behind the current target.
|
// Place behind the current target.
|
||||||
newClone.goBehindOtherClone(this);
|
newClone.goBehindOther(this);
|
||||||
return newClone;
|
return newClone;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the project receives a "green flag."
|
* Called when the project receives a "green flag."
|
||||||
* For a clone, this clears graphic effects.
|
* For a rendered target, this clears graphic effects.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.onGreenFlag = function () {
|
RenderedTarget.prototype.onGreenFlag = function () {
|
||||||
this.clearEffects();
|
this.clearEffects();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispose of this clone, destroying any run-time properties.
|
* Dispose, destroying any run-time properties.
|
||||||
*/
|
*/
|
||||||
Clone.prototype.dispose = function () {
|
RenderedTarget.prototype.dispose = function () {
|
||||||
this.runtime.changeCloneCounter(-1);
|
this.runtime.changeCloneCounter(-1);
|
||||||
if (this.renderer && this.drawableID !== null) {
|
if (this.renderer && this.drawableID !== null) {
|
||||||
this.renderer.destroyDrawable(this.drawableID);
|
this.renderer.destroyDrawable(this.drawableID);
|
||||||
|
@ -614,4 +614,4 @@ Clone.prototype.dispose = function () {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Clone;
|
module.exports = RenderedTarget;
|
|
@ -1,4 +1,4 @@
|
||||||
var Clone = require('./clone');
|
var RenderedTarget = require('./rendered-target');
|
||||||
var Blocks = require('../engine/blocks');
|
var Blocks = require('../engine/blocks');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,7 +45,7 @@ var Sprite = function (blocks, runtime) {
|
||||||
* @returns {!Clone} Newly created clone.
|
* @returns {!Clone} Newly created clone.
|
||||||
*/
|
*/
|
||||||
Sprite.prototype.createClone = function () {
|
Sprite.prototype.createClone = function () {
|
||||||
var newClone = new Clone(this, this.runtime);
|
var newClone = new RenderedTarget(this, this.runtime);
|
||||||
newClone.isOriginal = this.clones.length === 0;
|
newClone.isOriginal = this.clones.length === 0;
|
||||||
this.clones.push(newClone);
|
this.clones.push(newClone);
|
||||||
if (newClone.isOriginal) {
|
if (newClone.isOriginal) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var test = require('tap').test;
|
var test = require('tap').test;
|
||||||
|
|
||||||
var clone = require('../../src/sprites/clone');
|
var renderedTarget = require('../../src/sprites/rendered-target');
|
||||||
var runtime = require('../../src/engine/runtime');
|
var runtime = require('../../src/engine/runtime');
|
||||||
var sb2 = require('../../src/import/sb2import');
|
var sb2 = require('../../src/import/sb2import');
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ test('default', function (t) {
|
||||||
t.type(rt, 'object');
|
t.type(rt, 'object');
|
||||||
t.type(rt.targets, 'object');
|
t.type(rt.targets, 'object');
|
||||||
|
|
||||||
t.ok(rt.targets[0] instanceof clone);
|
t.ok(rt.targets[0] instanceof renderedTarget);
|
||||||
t.type(rt.targets[0].id, 'string');
|
t.type(rt.targets[0].id, 'string');
|
||||||
t.type(rt.targets[0].blocks, 'object');
|
t.type(rt.targets[0].blocks, 'object');
|
||||||
t.type(rt.targets[0].variables, 'object');
|
t.type(rt.targets[0].variables, 'object');
|
||||||
|
@ -36,7 +36,7 @@ test('default', function (t) {
|
||||||
t.equal(rt.targets[0].isOriginal, true);
|
t.equal(rt.targets[0].isOriginal, true);
|
||||||
t.equal(rt.targets[0].isStage, true);
|
t.equal(rt.targets[0].isStage, true);
|
||||||
|
|
||||||
t.ok(rt.targets[1] instanceof clone);
|
t.ok(rt.targets[1] instanceof renderedTarget);
|
||||||
t.type(rt.targets[1].id, 'string');
|
t.type(rt.targets[1].id, 'string');
|
||||||
t.type(rt.targets[1].blocks, 'object');
|
t.type(rt.targets[1].blocks, 'object');
|
||||||
t.type(rt.targets[1].variables, 'object');
|
t.type(rt.targets[1].variables, 'object');
|
||||||
|
@ -63,7 +63,7 @@ test('demo', function (t) {
|
||||||
t.type(rt, 'object');
|
t.type(rt, 'object');
|
||||||
t.type(rt.targets, 'object');
|
t.type(rt.targets, 'object');
|
||||||
|
|
||||||
t.ok(rt.targets[0] instanceof clone);
|
t.ok(rt.targets[0] instanceof renderedTarget);
|
||||||
t.type(rt.targets[0].id, 'string');
|
t.type(rt.targets[0].id, 'string');
|
||||||
t.type(rt.targets[0].blocks, 'object');
|
t.type(rt.targets[0].blocks, 'object');
|
||||||
t.type(rt.targets[0].variables, 'object');
|
t.type(rt.targets[0].variables, 'object');
|
||||||
|
@ -74,7 +74,7 @@ test('demo', function (t) {
|
||||||
t.equal(rt.targets[0].isOriginal, true);
|
t.equal(rt.targets[0].isOriginal, true);
|
||||||
t.equal(rt.targets[0].isStage, true);
|
t.equal(rt.targets[0].isStage, true);
|
||||||
|
|
||||||
t.ok(rt.targets[1] instanceof clone);
|
t.ok(rt.targets[1] instanceof renderedTarget);
|
||||||
t.type(rt.targets[1].id, 'string');
|
t.type(rt.targets[1].id, 'string');
|
||||||
t.type(rt.targets[1].blocks, 'object');
|
t.type(rt.targets[1].blocks, 'object');
|
||||||
t.type(rt.targets[1].variables, 'object');
|
t.type(rt.targets[1].variables, 'object');
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
var test = require('tap').test;
|
var test = require('tap').test;
|
||||||
var Clone = require('../../src/sprites/clone');
|
var RenderedTarget = require('../../src/sprites/rendered-target');
|
||||||
var Sprite = require('../../src/sprites/sprite');
|
var Sprite = require('../../src/sprites/sprite');
|
||||||
|
|
||||||
test('clone effects', function (t) {
|
test('clone effects', function (t) {
|
||||||
// Create two clones and ensure they have different graphic effect objects.
|
// Create two clones and ensure they have different graphic effect objects.
|
||||||
// Regression test for Github issue #224
|
// Regression test for Github issue #224
|
||||||
var spr = new Sprite();
|
var spr = new Sprite();
|
||||||
var a = new Clone(spr, null);
|
var a = new RenderedTarget(spr, null);
|
||||||
var b = new Clone(spr, null);
|
var b = new RenderedTarget(spr, null);
|
||||||
t.ok(a.effects !== b.effects);
|
t.ok(a.effects !== b.effects);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
Loading…
Reference in a new issue