Issue #414: part1: add opacity to Layer model

This commit is contained in:
Julian Descottes 2016-03-05 15:23:57 +01:00 committed by juliandescottes
parent 6a9c9467a5
commit 7660119b50
2 changed files with 51 additions and 0 deletions

View File

@ -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;
};

View File

@ -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);
});
});