Merged changes

This commit is contained in:
jdescottes
2014-07-03 23:40:30 +02:00
13 changed files with 206 additions and 43 deletions

View File

@ -10,7 +10,6 @@
// I apologize to my future self for this one.
var NO_SCROLL_MAX_COLORS = 20;
var MAX_COLORS = 100;
ns.PalettesListController = function (paletteController, usedColorService) {
this.usedColorService = usedColorService;
@ -80,8 +79,8 @@
}
}
if (colors.length > MAX_COLORS) {
colors = colors.slice(0, MAX_COLORS);
if (colors.length > Constants.MAX_CURRENT_COLORS_DISPLAYED) {
colors = colors.slice(0, Constants.MAX_CURRENT_COLORS_DISPLAYED);
}
return colors;

View File

@ -15,6 +15,10 @@
this.refreshZoom_();
this.redrawFlag = true;
this.cachedFrameProcessor = new pskl.model.frame.CachedFrameProcessor();
this.cachedFrameProcessor.setFrameProcessor(this.frameToPreviewCanvas_.bind(this));
this.cachedFrameProcessor.setOutputCloner(this.clonePreviewCanvas_.bind(this));
};
ns.PreviewFilmController.prototype.init = function() {
@ -39,7 +43,6 @@
ns.PreviewFilmController.prototype.render = function () {
if (this.redrawFlag) {
// TODO(vincz): Full redraw on any drawing modification, optimize.
this.createPreviews_();
this.redrawFlag = false;
}
@ -175,11 +178,8 @@
cloneFrameButton.className = "tile-overlay duplicate-frame-action";
previewTileRoot.appendChild(cloneFrameButton);
var canvasRenderer = new pskl.rendering.CanvasRenderer(currentFrame, this.zoom);
canvasRenderer.drawTransparentAs(Constants.TRANSPARENT_COLOR);
var canvas = canvasRenderer.render();
canvas.classList.add('tile-view', 'canvas');
canvasContainer.appendChild(canvas);
canvasContainer.appendChild(this.getCanvasForFrame(currentFrame));
previewTileRoot.appendChild(canvasContainer);
if(tileNumber > 0 || this.piskelController.getFrameCount() > 1) {
@ -206,6 +206,25 @@
return previewTileRoot;
};
ns.PreviewFilmController.prototype.getCanvasForFrame = function (frame) {
var canvas = this.cachedFrameProcessor.get(frame, this.zoom);
return canvas;
};
ns.PreviewFilmController.prototype.frameToPreviewCanvas_ = function (frame) {
var canvasRenderer = new pskl.rendering.CanvasRenderer(frame, this.zoom);
canvasRenderer.drawTransparentAs(Constants.TRANSPARENT_COLOR);
var canvas = canvasRenderer.render();
canvas.classList.add('tile-view', 'canvas');
return canvas;
};
ns.PreviewFilmController.prototype.clonePreviewCanvas_ = function (canvas) {
var clone = pskl.CanvasUtils.clone(canvas);
clone.classList.add('tile-view', 'canvas');
return clone;
};
/**
* Calculate the preview zoom depending on the piskel size
*/

View File

@ -77,10 +77,16 @@
};
ns.PiskelController.prototype.getFrameAt = function (index) {
var hash = [];
var frames = this.getLayers().map(function (l) {
return l.getFrameAt(index);
var frame = l.getFrameAt(index);
hash.push(frame.getHash());
return frame;
});
return pskl.utils.FrameUtils.merge(frames);
var mergedFrame = pskl.utils.FrameUtils.merge(frames);
mergedFrame.id = hash.join('-');
mergedFrame.version = 0;
return mergedFrame;
};
ns.PiskelController.prototype.hasFrameAt = function (index) {

View File

@ -62,12 +62,26 @@
evt.preventDefault();
evt.stopPropagation();
this.beforeSaving_();
pskl.app.storageService.store({
success : this.onSaveSuccess_.bind(this),
error : this.onSaveError_.bind(this),
after : this.afterSaving_.bind(this)
});
var name = this.getName();
if (!name) {
name = window.prompt('Please specify a name', 'New piskel');
}
if (name) {
var description = this.getDescription();
var isPublic = !!this.isPublicCheckbox.prop('checked');
var descriptor = new pskl.model.piskel.Descriptor(name, description, isPublic);
this.piskelController.getPiskel().setDescriptor(descriptor);
this.beforeSaving_();
pskl.app.storageService.store({
success : this.onSaveSuccess_.bind(this),
error : this.onSaveError_.bind(this),
after : this.afterSaving_.bind(this)
});
}
};
ns.SaveController.prototype.onSaveLocalClick_ = function (evt) {