diff --git a/src/js/model/Layer.js b/src/js/model/Layer.js index 1daa1fd3..fdf94727 100644 --- a/src/js/model/Layer.js +++ b/src/js/model/Layer.js @@ -7,6 +7,7 @@ } else { this.name = name; this.frames = []; + this.opacity = 1; } }; @@ -31,6 +32,17 @@ this.name = name; }; + ns.Layer.prototype.getOpacity = function () { + return this.opacity; + }; + + ns.Layer.prototype.setOpacity = function (opacity) { + if (opacity === null || isNaN(opacity) || opacity < 0 || opacity > 1) { + return; + } + this.opacity = opacity; + }; + ns.Layer.prototype.getFrames = function () { return this.frames; }; diff --git a/test/js/model/LayerTest.js b/test/js/model/LayerTest.js new file mode 100644 index 00000000..2fedfc37 --- /dev/null +++ b/test/js/model/LayerTest.js @@ -0,0 +1,39 @@ +describe("Layer model test", function() { + + beforeEach(function() {}); + afterEach(function() {}); + + it("has proper defaults", function() { + var layer = new pskl.model.Layer('layerName'); + + expect(layer.getOpacity()).toBe(1); + expect(layer.getFrames().length).toBe(0); + expect(layer.getName()).toBe('layerName'); + }); + + it("can set opacity", function() { + var layer = new pskl.model.Layer('layerName'); + + layer.setOpacity(0.5); + expect(layer.getOpacity()).toBe(0.5); + }); + + it("ignores bad opacity", function() { + var layer = new pskl.model.Layer('layerName'); + + layer.setOpacity(0.3); + expect(layer.getOpacity()).toBe(0.3); + + layer.setOpacity('Yep I\'m an opacity, let me in !'); + expect(layer.getOpacity()).toBe(0.3); + + layer.setOpacity(9000); + expect(layer.getOpacity()).toBe(0.3); + + layer.setOpacity(-1); + expect(layer.getOpacity()).toBe(0.3); + + layer.setOpacity(null); + expect(layer.getOpacity()).toBe(0.3); + }); +}); \ No newline at end of file