mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
intermediary
This commit is contained in:
parent
07cb37f2bf
commit
2509ba80a4
@ -94,7 +94,7 @@
|
|||||||
finishInitAppEngine_ : function () {
|
finishInitAppEngine_ : function () {
|
||||||
if (pskl.framesheetData_ && pskl.framesheetData_.content) {
|
if (pskl.framesheetData_ && pskl.framesheetData_.content) {
|
||||||
var piskel = pskl.utils.Serializer.createPiskel(pskl.framesheetData_.content);
|
var piskel = pskl.utils.Serializer.createPiskel(pskl.framesheetData_.content);
|
||||||
piskel.app.PiskelController.setPiskel(piskel);
|
pskl.app.piskelController.setPiskel(piskel);
|
||||||
pskl.app.animationController.setFPS(pskl.framesheetData_.fps);
|
pskl.app.animationController.setFPS(pskl.framesheetData_.fps);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -7,32 +7,94 @@
|
|||||||
|
|
||||||
ns.ImportController.prototype.init = function () {
|
ns.ImportController.prototype.init = function () {
|
||||||
this.fileUploadInput = $("[name=file-upload-input]");
|
this.fileUploadInput = $("[name=file-upload-input]");
|
||||||
|
this.urlInput = $("[name=url-input]");
|
||||||
this.importForm = $("[name=import-form]");
|
this.importForm = $("[name=import-form]");
|
||||||
this.importForm.submit(this.onImportFormSubmit_.bind(this));
|
this.importForm.submit(this.onImportFormSubmit_.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.ImportController.prototype.reset_ = function () {
|
||||||
|
this.importForm.get(0).reset();
|
||||||
|
};
|
||||||
|
|
||||||
ns.ImportController.prototype.onImportFormSubmit_ = function (evt) {
|
ns.ImportController.prototype.onImportFormSubmit_ = function (evt) {
|
||||||
evt.originalEvent.preventDefault();
|
evt.originalEvent.preventDefault();
|
||||||
|
var importType = this.getSelectedRadioValue_();
|
||||||
|
if (importType === 'FILE') {
|
||||||
|
this.importFromFile_();
|
||||||
|
} else if (importType === 'URL') {
|
||||||
|
this.importFromUrl_();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.ImportController.prototype.getSelectedRadioValue_ = function () {
|
||||||
|
var radios = this.getRadios_();
|
||||||
|
var selectedRadios = radios.filter(function(radio) {
|
||||||
|
return !!radio.checked;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (selectedRadios.length == 1) {
|
||||||
|
return selectedRadios[0].value;
|
||||||
|
} else {
|
||||||
|
throw "Unexpected error when retrieving selected radio";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.ImportController.prototype.importFromFile_ = function () {
|
||||||
var files = this.fileUploadInput.get(0).files;
|
var files = this.fileUploadInput.get(0).files;
|
||||||
if (files.length == 1) {
|
if (files.length == 1) {
|
||||||
var file = files[0];
|
var file = files[0];
|
||||||
if (this.isImage_(file)) {
|
if (this.isImage_(file)) {
|
||||||
this.readImageFile_(file);
|
this.readImageFile_(file);
|
||||||
} else {
|
} else {
|
||||||
|
this.reset_();
|
||||||
throw "File is not an image : " + file.type;
|
throw "File is not an image : " + file.type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.ImportController.prototype.readImageFile_ = function (imageFile) {
|
ns.ImportController.prototype.importFromUrl_ = function () {
|
||||||
pskl.utils.FileUtils.readFile(imageFile, this.processImageData_.bind(this));
|
var url = this.urlInput.get(0).value;
|
||||||
|
if (this.isUrl_(url)) {
|
||||||
|
this.processImageSource_(url);
|
||||||
|
} else {
|
||||||
|
this.reset_();
|
||||||
|
throw "Not a url : " + url;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.ImportController.prototype.processImageData_ = function (imageData) {
|
/**
|
||||||
|
* TODO : implement it properly
|
||||||
|
* @param {String} url potential url to test
|
||||||
|
* @return {Boolean} true if url looks like a URL
|
||||||
|
*/
|
||||||
|
ns.ImportController.prototype.isUrl_ = function (url) {
|
||||||
|
if (typeof url === 'string') {
|
||||||
|
return (/^http/).test(url);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.ImportController.prototype.getRadios_ = function () {
|
||||||
|
var radiosColl = this.importForm.get(0).querySelectorAll("[name=upload-source-type]"),
|
||||||
|
radios = Array.prototype.slice.call(radiosColl,0);
|
||||||
|
return radios;
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.ImportController.prototype.readImageFile_ = function (imageFile) {
|
||||||
|
pskl.utils.FileUtils.readFile(imageFile, this.processImageSource_.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an image from the given source (url or data-url), and onload forward to onImageLoaded
|
||||||
|
* TODO : should be a generic utility method, should take a callback
|
||||||
|
* @param {String} imageSource url or data-url, will be used as src for the image
|
||||||
|
*/
|
||||||
|
ns.ImportController.prototype.processImageSource_ = function (imageSource) {
|
||||||
var image = new Image();
|
var image = new Image();
|
||||||
image.onload = this.onImageLoaded_.bind(this);
|
image.onload = this.onImageLoaded_.bind(this);
|
||||||
image.src = imageData;
|
image.crossOrigin = '';
|
||||||
|
image.src = imageSource;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.ImportController.prototype.onImageLoaded_ = function (evt) {
|
ns.ImportController.prototype.onImageLoaded_ = function (evt) {
|
||||||
@ -66,10 +128,12 @@
|
|||||||
"A new Piskel will be created from your picture, size : " + w + "x" + h;
|
"A new Piskel will be created from your picture, size : " + w + "x" + h;
|
||||||
|
|
||||||
if (window.confirm(confirmationMessage)) {
|
if (window.confirm(confirmationMessage)) {
|
||||||
console.log(framesheet);
|
var piskel = pskl.utils.Serializer.createPiskel([framesheet]);
|
||||||
} else {
|
pskl.app.piskelController.setPiskel(piskel);
|
||||||
console.log("ABORT ABORT");
|
pskl.app.animationController.setFPS(12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.reset_();
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.ImportController.prototype.rgbToHex_ = function (r, g, b) {
|
ns.ImportController.prototype.rgbToHex_ = function (r, g, b) {
|
||||||
|
@ -3,19 +3,29 @@
|
|||||||
data-setting="user"
|
data-setting="user"
|
||||||
class="tool-icon gear-icon"
|
class="tool-icon gear-icon"
|
||||||
title="Preferences"
|
title="Preferences"
|
||||||
rel="tooltip" data-placement="left"></div>
|
rel="tooltip" data-placement="left">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
data-setting="import"
|
||||||
|
class="tool-icon import-icon"
|
||||||
|
title="Import an existing picture"
|
||||||
|
rel="tooltip" data-placement="left">
|
||||||
|
</div>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
class="tool-icon gallery-icon"
|
class="tool-icon gallery-icon"
|
||||||
title="Visit gallery"
|
title="Visit gallery"
|
||||||
href="http://juliandescottes.github.io/piskel-website/"
|
href="http://juliandescottes.github.io/piskel-website/"
|
||||||
rel="tooltip" data-placement="left" target="_blank"></a>
|
rel="tooltip" data-placement="left" target="_blank">
|
||||||
|
</a>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="tool-icon save-icon"
|
class="tool-icon save-icon"
|
||||||
title="Save to gallery"
|
title="Save to gallery"
|
||||||
onclick="pskl.app.storeSheet()"
|
onclick="pskl.app.storeSheet()"
|
||||||
rel="tooltip" data-placement="left" ></div>
|
rel="tooltip" data-placement="left" >
|
||||||
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
data-setting="gif"
|
data-setting="gif"
|
||||||
@ -25,13 +35,6 @@
|
|||||||
<span class="label">GIF</span>
|
<span class="label">GIF</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
|
||||||
data-setting="import"
|
|
||||||
class="tool-icon import-icon"
|
|
||||||
title="Import an existing picture"
|
|
||||||
rel="tooltip" data-placement="left">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="tool-icon upload-cloud-icon"
|
class="tool-icon upload-cloud-icon"
|
||||||
title="Upload as a spritesheet PNG"
|
title="Upload as a spritesheet PNG"
|
||||||
|
@ -5,15 +5,15 @@
|
|||||||
<div class="settings-item">
|
<div class="settings-item">
|
||||||
<form action="" method="POST" name="import-form">
|
<form action="" method="POST" name="import-form">
|
||||||
<div>
|
<div>
|
||||||
<input type="radio" name="upload-source-type" checked="checked " value="1"/>
|
<input type="radio" name="upload-source-type" checked="checked " value="FILE"/>
|
||||||
<label>From your computer :
|
<label>From your computer :
|
||||||
<input type="file" name="file-upload-input" value="file" />
|
<input type="file" name="file-upload-input" value="file" />
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input type="radio" name="upload-source-type" value="2"/>
|
<input type="radio" name="upload-source-type" value="URL"/>
|
||||||
<label>From the web :
|
<label>From the web :
|
||||||
<input type="text" placeholder="url" value="url" />
|
<input type="text" name="url-input" placeholder="url"/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" class="export-gif-upload-button" value="Import" />
|
<input type="submit" class="export-gif-upload-button" value="Import" />
|
||||||
|
Loading…
Reference in New Issue
Block a user