mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Issue #414: part1: add opacity to Layer model
This commit is contained in:
parent
6a9c9467a5
commit
7660119b50
@ -7,6 +7,7 @@
|
|||||||
} else {
|
} else {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.frames = [];
|
this.frames = [];
|
||||||
|
this.opacity = 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -31,6 +32,17 @@
|
|||||||
this.name = name;
|
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 () {
|
ns.Layer.prototype.getFrames = function () {
|
||||||
return this.frames;
|
return this.frames;
|
||||||
};
|
};
|
||||||
|
39
test/js/model/LayerTest.js
Normal file
39
test/js/model/LayerTest.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user