mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Merged
This commit is contained in:
122
js/app.js
122
js/app.js
@@ -10,12 +10,19 @@
|
||||
ns.app = {
|
||||
|
||||
init : function () {
|
||||
/**
|
||||
* True when piskel is running in static mode (no back end needed).
|
||||
* When started from APP Engine, appEngineToken_ (Boolean) should be set on window.pskl
|
||||
*/
|
||||
this.isAppEngineVersion = !!pskl.appEngineToken_;
|
||||
|
||||
this.shortcutService = new pskl.service.keyboard.ShortcutService();
|
||||
this.shortcutService.init();
|
||||
|
||||
var size = this.readSizeFromURL_();
|
||||
var piskel = new pskl.model.Piskel(size.width, size.height);
|
||||
piskel.setDescriptor("New Piskel", "Some text ...");
|
||||
|
||||
var descriptor = new pskl.model.piskel.Descriptor('New Piskel', '');
|
||||
var piskel = new pskl.model.Piskel(size.width, size.height, descriptor);
|
||||
|
||||
var layer = new pskl.model.Layer("Layer 1");
|
||||
var frame = new pskl.model.Frame(size.width, size.height);
|
||||
@@ -65,31 +72,31 @@
|
||||
this.imageUploadService = new pskl.service.ImageUploadService();
|
||||
this.imageUploadService.init();
|
||||
|
||||
|
||||
this.cheatsheetService = new pskl.service.keyboard.CheatsheetService();
|
||||
this.cheatsheetService.init();
|
||||
|
||||
if (this.isAppEngineVersion) {
|
||||
this.storageService = new pskl.service.AppEngineStorageService(this.piskelController);
|
||||
} else {
|
||||
this.storageService = new pskl.service.GithubStorageService(this.piskelController);
|
||||
}
|
||||
this.storageService.init();
|
||||
|
||||
|
||||
var drawingLoop = new pskl.rendering.DrawingLoop();
|
||||
drawingLoop.addCallback(this.render, this);
|
||||
drawingLoop.start();
|
||||
|
||||
this.initBootstrapTooltips_();
|
||||
this.initTooltips_();
|
||||
|
||||
/**
|
||||
* True when piskel is running in static mode (no back end needed).
|
||||
* When started from APP Engine, appEngineToken_ (Boolean) should be set on window.pskl
|
||||
*/
|
||||
this.isStaticVersion = !pskl.appEngineToken_;
|
||||
|
||||
if (this.isStaticVersion) {
|
||||
this.finishInitStatic_();
|
||||
} else {
|
||||
if (this.isAppEngineVersion) {
|
||||
this.finishInitAppEngine_();
|
||||
} else {
|
||||
this.finishInitGithub_();
|
||||
}
|
||||
},
|
||||
|
||||
finishInitStatic_ : function () {
|
||||
finishInitGithub_ : function () {
|
||||
var framesheetId = this.readFramesheetIdFromURL_();
|
||||
if (framesheetId) {
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{
|
||||
@@ -102,15 +109,16 @@
|
||||
},
|
||||
|
||||
finishInitAppEngine_ : function () {
|
||||
if (pskl.framesheetData_ && pskl.framesheetData_.content) {
|
||||
pskl.utils.serialization.Deserializer.deserialize(pskl.framesheetData_.content, function (piskel) {
|
||||
if (pskl.appEnginePiskelData_ && pskl.appEnginePiskelData_.piskel) {
|
||||
pskl.utils.serialization.Deserializer.deserialize(pskl.appEnginePiskelData_.piskel, function (piskel) {
|
||||
piskel.setDescriptor(pskl.appEnginePiskelData_.descriptor);
|
||||
pskl.app.piskelController.setPiskel(piskel);
|
||||
pskl.app.animationController.setFPS(pskl.framesheetData_.fps);
|
||||
pskl.app.animationController.setFPS(pskl.appEnginePiskelData_.fps);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
initBootstrapTooltips_ : function () {
|
||||
initTooltips_ : function () {
|
||||
$('body').tooltip({
|
||||
selector: '[rel=tooltip]'
|
||||
});
|
||||
@@ -123,8 +131,8 @@
|
||||
},
|
||||
|
||||
readSizeFromURL_ : function () {
|
||||
var sizeParam = this.readUrlParameter_("size"),
|
||||
size;
|
||||
var sizeParam = this.readUrlParameter_("size");
|
||||
var size;
|
||||
// parameter expected as size=64x48 => size=widthxheight
|
||||
var parts = sizeParam.split("x");
|
||||
if (parts && parts.length == 2 && !isNaN(parts[0]) && !isNaN(parts[1])) {
|
||||
@@ -149,13 +157,12 @@
|
||||
},
|
||||
|
||||
readUrlParameter_ : function (paramName) {
|
||||
var searchString = window.location.search.substring(1),
|
||||
i, val, params = searchString.split("&");
|
||||
|
||||
for (i = 0; i < params.length; i++) {
|
||||
val = params[i].split("=");
|
||||
if (val[0] == paramName) {
|
||||
return window.unescape(val[1]);
|
||||
var searchString = window.location.search.substring(1);
|
||||
var params = searchString.split("&");
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var param = params[i].split("=");
|
||||
if (param[0] == paramName) {
|
||||
return window.unescape(param[1]);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
@@ -182,65 +189,8 @@
|
||||
xhr.send();
|
||||
},
|
||||
|
||||
storeSheet : function (event) {
|
||||
if (this.isStaticVersion) {
|
||||
this.storeSheetStatic_();
|
||||
} else {
|
||||
this.storeSheetAppEngine_();
|
||||
}
|
||||
|
||||
if(event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
storeSheetStatic_ : function () {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var formData = new FormData();
|
||||
formData.append('framesheet_content', this.piskelController.serialize());
|
||||
formData.append('fps_speed', $('#preview-fps').val());
|
||||
|
||||
xhr.open('POST', Constants.STATIC.URL.SAVE, true);
|
||||
|
||||
xhr.onload = function(e) {
|
||||
if (this.status == 200) {
|
||||
var baseUrl = window.location.href.replace(window.location.search, "");
|
||||
window.location.href = baseUrl + "?frameId=" + this.responseText;
|
||||
} else {
|
||||
this.onerror(e);
|
||||
}
|
||||
};
|
||||
xhr.onerror = function(e) {
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{"content": "Saving failed ("+this.status+")"}]);
|
||||
};
|
||||
xhr.send(formData);
|
||||
},
|
||||
|
||||
storeSheetAppEngine_ : function () {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var formData = new FormData();
|
||||
formData.append('framesheet_content', this.piskelController.serialize());
|
||||
formData.append('fps_speed', $('#preview-fps').val());
|
||||
formData.append('name', $('#piskel-name').val());
|
||||
formData.append('frames', this.piskelController.getFrameCount());
|
||||
formData.append('preview', this.getFirstFrameAsPng());
|
||||
formData.append('framesheet', this.getFramesheetAsPng());
|
||||
|
||||
xhr.open('POST', Constants.APPENGINE.URL.SAVE, true);
|
||||
|
||||
xhr.onload = function(e) {
|
||||
if (this.status == 200) {
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{"content": "Successfully saved !"}]);
|
||||
} else {
|
||||
this.onerror(e);
|
||||
}
|
||||
};
|
||||
xhr.onerror = function(e) {
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{"content": "Saving failed ("+this.status+")"}]);
|
||||
};
|
||||
xhr.send(formData);
|
||||
store : function (callbacks) {
|
||||
this.storageService.store(callbacks);
|
||||
},
|
||||
|
||||
getFirstFrameAsPng : function () {
|
||||
|
||||
Reference in New Issue
Block a user