Feature : Save Piskel project as File

First commit :
Removed Local storage feature
Added 'download project' 'open project' options

First attempt at simplifying right panel.

To be continued ...
This commit is contained in:
jdescottes
2014-06-23 00:49:54 +02:00
parent 23fd3c464c
commit 89466d582a
23 changed files with 366 additions and 214 deletions

View File

@@ -3,8 +3,8 @@
var BASE64_REGEX = /\s*;\s*base64\s*(?:;|$)/i;
ns.ImageToBlob = {
imageDataToBlob : function(dataURI, type, callback) {
ns.BlobUtils = {
dataToBlob : function(dataURI, type, callback) {
var header_end = dataURI.indexOf(","),
data = dataURI.substring(header_end + 1),
isBase64 = BASE64_REGEX.test(dataURI.substring(0, header_end)),
@@ -26,13 +26,18 @@
canvasToBlob : function(canvas, callback, type /*, ...args*/) {
type = type || "image/png";
if (this.mozGetAsFile) {
callback(this.mozGetAsFile("canvas", type));
if (canvas.mozGetAsFile) {
callback(canvas.mozGetAsFile("canvas", type));
} else {
var args = Array.prototype.slice.call(arguments, 2);
var dataURI = canvas.toDataURL.apply(canvas, args);
pskl.utils.ImageToBlob.imageDataToBlob(dataURI, type, callback);
pskl.utils.BlobUtils.dataToBlob(dataURI, type, callback);
}
},
stringToBlob : function (string, callback, type) {
type = type || "text/plain";
pskl.utils.BlobUtils.dataToBlob('data:'+type+',' + string, type, callback);
}
};
})();

24
src/js/utils/DateUtils.js Normal file
View File

@@ -0,0 +1,24 @@
(function () {
var ns = $.namespace('pskl.utils');
var pad = function (num) {
if (num < 10) {
return "0" + num;
} else {
return "" + num;
}
};
ns.DateUtils = {
format : function (date, format) {
return pskl.utils.Template.replace(format, {
Y : date.getFullYear(),
M : pad(date.getMonth() + 1),
D : pad(date.getDate()),
H : pad(date.getHours()),
m : pad(date.getMinutes()),
s : pad(date.getSeconds())
});
}
};
})();

View File

@@ -10,7 +10,7 @@
reader.readAsDataURL(file);
},
downloadAsFile : function (filename, content) {
downloadAsFile : function (content, filename) {
var saveAs = window.saveAs || (navigator.msSaveBlob && navigator.msSaveBlob.bind(navigator));
if (saveAs) {
saveAs(content, filename);

View File

@@ -17,6 +17,15 @@
return dummyEl.children[0];
},
getAndReplace : function (templateId, dict) {
var result = "";
var tpl = pskl.utils.Template.get(templateId);
if (tpl) {
result = pskl.utils.Template.replace(tpl, dict);
}
return result;
},
replace : function (template, dict) {
for (var key in dict) {
if (dict.hasOwnProperty(key)) {

View File

@@ -9,6 +9,9 @@
return JSON.stringify({
modelVersion : Constants.MODEL_VERSION,
piskel : {
name : piskel.getDescriptor().name,
description : piskel.getDescriptor().description,
fps : pskl.app.piskelController.getFPS(),
height : piskel.getHeight(),
width : piskel.getWidth(),
layers : serializedLayers,