2016-03-05 22:42:21 +03:00
|
|
|
describe("Serialization/Deserialization test", function() {
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
pskl.app.piskelController = {
|
|
|
|
getFPS: function () {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2016-12-21 19:17:59 +03:00
|
|
|
|
2016-03-05 22:42:21 +03:00
|
|
|
afterEach(function() {
|
|
|
|
delete pskl.app.piskelController;
|
|
|
|
});
|
|
|
|
|
2016-12-21 19:17:59 +03:00
|
|
|
if("serializes frames correctly", function () {
|
|
|
|
// Create piskel.
|
|
|
|
var descriptor = new pskl.model.piskel.Descriptor('piskelName', 'piskelDesc');
|
|
|
|
var piskel = new pskl.model.Piskel(1, 1, 1, descriptor);
|
|
|
|
// Add layer.
|
|
|
|
piskel.addLayer(new pskl.model.Layer('layer1'));
|
|
|
|
// Add frame.
|
|
|
|
piskel.getLayerAt(0).addFrame(pskl.model.Frame.fromPixelGrid([
|
|
|
|
["red", "black"],
|
|
|
|
["blue", "green"]
|
|
|
|
]));
|
|
|
|
|
|
|
|
// Verify the frame is successfully added in the layer.
|
|
|
|
expect(piskel.getLayerAt(0).getFrames().length).toBe(1);
|
|
|
|
|
|
|
|
var serializedPiskel = pskl.utils.serialization.Serializer.serialize(piskel);
|
|
|
|
|
|
|
|
var deserializer = pskl.utils.serialization.Deserializer;
|
|
|
|
deserializer.deserialize(JSON.parse(serializedPiskel), function (p) {
|
|
|
|
// Check the frame has been properly deserialized
|
|
|
|
expect(p.getLayerAt(0).getFrames().length).toBe(1);
|
|
|
|
var frame = p.getLayerAt(0).getFrameAt(0);
|
|
|
|
test.testutils.frameEqualsGrid(flattened, [
|
|
|
|
["red", "black"],
|
|
|
|
["blue", "green"]
|
|
|
|
]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
2016-03-05 22:42:21 +03:00
|
|
|
it("serializes layer opacity", function(done) {
|
|
|
|
var descriptor = new pskl.model.piskel.Descriptor('piskelName', 'piskelDesc');
|
2016-12-13 11:17:34 +03:00
|
|
|
var piskel = new pskl.model.Piskel(1, 1, 1, descriptor);
|
2016-03-05 22:42:21 +03:00
|
|
|
|
|
|
|
piskel.addLayer(new pskl.model.Layer('layer1'));
|
|
|
|
piskel.addLayer(new pskl.model.Layer('layer2'));
|
|
|
|
piskel.addLayer(new pskl.model.Layer('layer3'));
|
|
|
|
|
|
|
|
piskel.getLayerAt(0).setOpacity(0);
|
|
|
|
piskel.getLayerAt(1).setOpacity(0.3);
|
|
|
|
piskel.getLayerAt(2).setOpacity(0.9);
|
|
|
|
|
|
|
|
var frame = new pskl.model.Frame(1, 1);
|
|
|
|
piskel.getLayers().forEach(function (layer) {
|
|
|
|
layer.addFrame(frame);
|
|
|
|
});
|
|
|
|
|
2016-10-16 19:28:12 +03:00
|
|
|
var serializedPiskel = pskl.utils.serialization.Serializer.serialize(piskel);
|
2016-03-05 22:42:21 +03:00
|
|
|
|
|
|
|
var deserializer = pskl.utils.serialization.Deserializer;
|
2016-10-16 19:28:12 +03:00
|
|
|
deserializer.deserialize(JSON.parse(serializedPiskel), function (p) {
|
2016-03-05 22:42:21 +03:00
|
|
|
expect(p.getLayerAt(0).getOpacity()).toBe(0);
|
|
|
|
expect(p.getLayerAt(1).getOpacity()).toBe(0.3);
|
|
|
|
expect(p.getLayerAt(2).getOpacity()).toBe(0.9);
|
2016-12-21 19:17:59 +03:00
|
|
|
|
|
|
|
// Check the serialization was successful
|
|
|
|
expect(p.getLayerAt(0).getFrames().length).toBe(1);
|
2016-03-05 22:42:21 +03:00
|
|
|
done();
|
2016-12-21 19:17:59 +03:00
|
|
|
});
|
2016-03-05 22:42:21 +03:00
|
|
|
});
|
2016-12-21 19:17:59 +03:00
|
|
|
});
|