From 5728d648b1b320bb4c37f03b28ceab5da802cd82 Mon Sep 17 00:00:00 2001 From: Tim Mickel Date: Mon, 3 Oct 2016 10:16:43 -0400 Subject: [PATCH] Ensure clone.effects is defined on each instance (#225) * Ensure clone.effects is defined on each instance * Add regression test for GH-224 --- src/sprites/clone.js | 27 ++++++++++++++------------- test/unit/clone.js | 13 +++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 test/unit/clone.js diff --git a/src/sprites/clone.js b/src/sprites/clone.js index 14d7b366c..4d7c3672c 100644 --- a/src/sprites/clone.js +++ b/src/sprites/clone.js @@ -29,6 +29,20 @@ function Clone(sprite, runtime) { * @type {?Number} */ this.drawableID = null; + + /** + * Map of current graphic effect values. + * @type {!Object.} + */ + this.effects = { + 'color': 0, + 'fisheye': 0, + 'whirl': 0, + 'pixelate': 0, + 'mosaic': 0, + 'brightness': 0, + 'ghost': 0 + }; } util.inherits(Clone, Target); @@ -121,19 +135,6 @@ Clone.ROTATION_STYLE_NONE = 'don\'t rotate'; */ Clone.prototype.rotationStyle = Clone.ROTATION_STYLE_ALL_AROUND; -/** - * Map of current graphic effect values. - * @type {!Object.} - */ -Clone.prototype.effects = { - 'color': 0, - 'fisheye': 0, - 'whirl': 0, - 'pixelate': 0, - 'mosaic': 0, - 'brightness': 0, - 'ghost': 0 -}; // End clone-level properties. /** diff --git a/test/unit/clone.js b/test/unit/clone.js new file mode 100644 index 000000000..246e1b955 --- /dev/null +++ b/test/unit/clone.js @@ -0,0 +1,13 @@ +var test = require('tap').test; +var Clone = require('../../src/sprites/clone'); +var Sprite = require('../../src/sprites/sprite'); + +test('clone effects', function (t) { + // Create two clones and ensure they have different graphic effect objects. + // Regression test for Github issue #224 + var spr = new Sprite(); + var a = new Clone(spr, null); + var b = new Clone(spr, null); + t.ok(a.effects !== b.effects); + t.end(); +});