mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
651563f793
Migration to a Domain object (currently a FrameSheetModel, feel free to change its name). The model is being used by the slideshow (drawing each tiles), animation preview (drawing animation) and drawing (update model and redraw current tile). Now the rendering information are not stored in a canvas element that you paste from canvas to canvas but centralize in this model. The frame is described as an array of array: that will allow different rendering using the dpi constants and more flexibility (e.g. drawing a grid, serializing the data). Some minor modifications: - cleaning markup - adding background image to highlight transparent area
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
|
|
var FrameSheetModel = (function() {
|
|
|
|
var inst;
|
|
var frames = [];
|
|
var width;
|
|
var height;
|
|
|
|
var createEmptyFrame_ = function() {
|
|
var emptyFrame = new Array(width);
|
|
for (var columnIndex=0; columnIndex < width; columnIndex++) {
|
|
emptyFrame[columnIndex] = new Array(height);
|
|
}
|
|
return emptyFrame;
|
|
};
|
|
|
|
return {
|
|
validate: function() {
|
|
return true; // I'm always right dude
|
|
},
|
|
|
|
// Could be use to pass around model using long GET param (good enough for simple models) and
|
|
// do some temporary locastorage
|
|
serialize: function() {
|
|
throw "FrameSheet.serialize Not implemented"
|
|
},
|
|
|
|
addEmptyFrame: function() {
|
|
frames.push(createEmptyFrame_());
|
|
},
|
|
|
|
getFrameCount: function() {
|
|
return frames.length;
|
|
},
|
|
|
|
getFrameByIndex: function(index) {
|
|
if (isNaN(index)) {
|
|
throw "Bad argument value for getFrameByIndex method: <" + index + ">"
|
|
} else if (index < 0 || index > frames.length) {
|
|
throw "Out of bound index for frameSheet object."
|
|
}
|
|
|
|
return frames[index];
|
|
},
|
|
|
|
removeFrameByIndex: function(index) {
|
|
if(index < 0 || index > inst.getFrameCount()) {
|
|
throw "Bad index value for removeFrameByIndex.";
|
|
}
|
|
frames.splice(index, 1);
|
|
},
|
|
|
|
duplicateFrameByIndex: function(frameToDuplicateIndex) {
|
|
var frame = inst.getFrameByIndex(frameToDuplicateIndex);
|
|
var clonedFrame = [];
|
|
for(var i=0, l=frame.length; i<l; i++) {
|
|
clonedFrame.push(frame[i].slice(0));
|
|
}
|
|
frames.splice(frameToDuplicateIndex + 1, 0, clonedFrame);
|
|
},
|
|
|
|
getInstance: function(width_, height_) {
|
|
|
|
if (isNaN(width_) || isNaN(height_)) {
|
|
throw "Bad FrameSheetModel initialization in getInstance method.";
|
|
}
|
|
|
|
inst = this;
|
|
|
|
width = width_;
|
|
height = height_;
|
|
|
|
return inst;
|
|
}
|
|
}
|
|
})(); |