From 19c99d1aa7e93464bf0b2fea936fab7fedaa0073 Mon Sep 17 00:00:00 2001 From: jdescottes Date: Mon, 14 Jul 2014 14:14:28 +0200 Subject: [PATCH] Fixed canvas ordering, fixed FPS during local import --- src/css/style.css | 6 ++-- src/js/app.js | 1 + src/js/rendering/layer/LayersRenderer.js | 2 ++ src/js/service/LocalStorageService.js | 10 ++++-- src/js/snippets.js | 43 ++++++++++++++++++++++++ src/piskel-script-list.js | 4 ++- 6 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 src/js/snippets.js diff --git a/src/css/style.css b/src/css/style.css index 16f7aa1..c4f2312 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -158,9 +158,9 @@ body { */ .canvas.layers-below-canvas {z-index: 7;} .canvas.drawing-canvas {z-index: 8;} -.canvas.layers-above-canvas {z-index: 9;} -.canvas.onion-skin-canvas {z-index: 10;} -.canvas.canvas-overlay {z-index: 11;} +.canvas.canvas-overlay {z-index: 9;} +.canvas.onion-skin-canvas {z-index: 10;} +.canvas.layers-above-canvas {z-index: 11;} diff --git a/src/js/app.js b/src/js/app.js index 295de41..8c94036 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -172,3 +172,4 @@ } }; })(); + diff --git a/src/js/rendering/layer/LayersRenderer.js b/src/js/rendering/layer/LayersRenderer.js index 3b46b98..9e5a42b 100644 --- a/src/js/rendering/layer/LayersRenderer.js +++ b/src/js/rendering/layer/LayersRenderer.js @@ -14,6 +14,8 @@ this.add(this.aboveRenderer); this.serializedRendering = ''; + + $.subscribe(Events.PISKEL_RESET, this.flush.bind(this)); }; pskl.utils.inherit(pskl.rendering.layer.LayersRenderer, pskl.rendering.CompositeRenderer); diff --git a/src/js/service/LocalStorageService.js b/src/js/service/LocalStorageService.js index a0861b7..52b9164 100644 --- a/src/js/service/LocalStorageService.js +++ b/src/js/service/LocalStorageService.js @@ -20,10 +20,16 @@ ns.LocalStorageService.prototype.load = function(name) { var piskelString = this.getPiskel(name); var key = this.getKey_(name); + var serializedPiskel = JSON.parse(piskelString); + // FIXME : should be moved to deserializer + // Deserializer should call callback with descriptor + fps information + var fps = serializedPiskel.piskel.fps; + var description = serializedPiskel.piskel.description; - pskl.utils.serialization.Deserializer.deserialize(JSON.parse(piskelString), function (piskel) { - piskel.setDescriptor(new pskl.model.piskel.Descriptor(name, key.description, true)); + pskl.utils.serialization.Deserializer.deserialize(serializedPiskel, function (piskel) { + piskel.setDescriptor(new pskl.model.piskel.Descriptor(name, description, true)); pskl.app.piskelController.setPiskel(piskel); + pskl.app.animationController.setFPS(fps); }); }; diff --git a/src/js/snippets.js b/src/js/snippets.js new file mode 100644 index 0000000..a506cc4 --- /dev/null +++ b/src/js/snippets.js @@ -0,0 +1,43 @@ +(function () { + var flipFrame = function (frame, horizontal, vertical) { + var clone = frame.clone(); + var w = frame.getWidth(); + var h = frame.getHeight(); + clone.forEachPixel(function (color, x, y) { + if (horizontal) { + x = w-x-1; + } + if (vertical) { + y = h-y-1; + } + frame.pixels[x][y] = color; + }); + frame.version++; + }; + + window.flip = function (horizontal, vertical) { + var currentFrameIndex = pskl.app.piskelController.getCurrentFrameIndex(); + var layers = pskl.app.piskelController.getLayers(); + layers.forEach(function (layer) { + flipFrame(layer.getFrameAt(currentFrameIndex), horizontal, vertical); + }); + $.publish(Events.PISKEL_RESET); + $.publish(Events.PISKEL_SAVE_STATE, { + type : pskl.service.HistoryService.SNAPSHOT + }); + }; + + window.copyToAll = function () { + var ref = pskl.app.piskelController.getCurrentFrame(); + var layer = pskl.app.piskelController.getCurrentLayer(); + layer.getFrames().forEach(function (frame) { + if (frame !== ref) { + frame.setPixels(ref.getPixels()); + } + }); + $.publish(Events.PISKEL_RESET); + $.publish(Events.PISKEL_SAVE_STATE, { + type : pskl.service.HistoryService.SNAPSHOT + }); + }; +})(); \ No newline at end of file diff --git a/src/piskel-script-list.js b/src/piskel-script-list.js index b91b889..09e4041 100644 --- a/src/piskel-script-list.js +++ b/src/piskel-script-list.js @@ -138,5 +138,7 @@ "js/drawingtools/ColorPicker.js", "js/drawingtools/ColorSwap.js", // Application controller and initialization - "js/app.js" + "js/app.js", + // Bonus features !! + "js/snippets.js" ]; \ No newline at end of file