piskel/src/js/app.js

207 lines
7.3 KiB
JavaScript
Raw Normal View History

/**
* @require Constants
* @require Events
*/
(function () {
var ns = $.namespace('pskl');
/**
* Main application controller
*/
ns.app = {
init : function () {
2013-12-19 02:22:25 +04:00
/**
* 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 = pskl.UserSettings.get(pskl.UserSettings.DEFAULT_SIZE);
2013-12-11 00:25:36 +04:00
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);
2014-08-21 02:50:59 +04:00
layer.addFrame(frame);
piskel.addLayer(layer);
this.corePiskelController = new pskl.controller.piskel.PiskelController(piskel);
this.corePiskelController.init();
this.piskelController = new pskl.controller.piskel.PublicPiskelController(this.corePiskelController);
this.piskelController.init();
this.paletteImportService = new pskl.service.palette.PaletteImportService();
this.paletteService = new pskl.service.palette.PaletteService();
2014-09-18 09:18:07 +04:00
this.paletteService.addDynamicPalette(new pskl.service.palette.CurrentColorsPalette());
2015-09-14 22:41:10 +03:00
this.selectedColorsService = new pskl.service.SelectedColorsService();
this.selectedColorsService.init();
2015-09-16 21:27:51 +03:00
this.mouseStateService = new pskl.service.MouseStateService();
this.mouseStateService.init();
this.paletteController = new pskl.controller.PaletteController();
this.paletteController.init();
this.currentColorsService = new pskl.service.CurrentColorsService(this.piskelController);
this.currentColorsService.init();
this.palettesListController = new pskl.controller.PalettesListController(this.currentColorsService);
this.palettesListController.init();
this.cursorCoordinatesController = new pskl.controller.CursorCoordinatesController(this.piskelController);
this.cursorCoordinatesController.init();
this.drawingController = new pskl.controller.DrawingController(
this.piskelController,
this.paletteController,
$('#drawing-canvas-container'));
this.drawingController.init();
this.previewController = new pskl.controller.preview.PreviewController(
this.piskelController,
$('#animated-preview-canvas-container'));
this.previewController.init();
this.minimapController = new pskl.controller.MinimapController(
this.piskelController,
this.previewController,
this.drawingController,
$('.minimap-container'));
this.minimapController.init();
this.framesListController = new pskl.controller.FramesListController(
this.piskelController,
$('#preview-list'));
this.framesListController.init();
this.layersListController = new pskl.controller.LayersListController(this.piskelController);
this.layersListController.init();
this.settingsController = new pskl.controller.settings.SettingsController(this.piskelController);
2013-06-16 12:17:50 +04:00
this.settingsController.init();
this.dialogsController = new pskl.controller.dialogs.DialogsController(this.piskelController);
this.dialogsController.init();
this.toolController = new pskl.controller.ToolController();
this.toolController.init();
this.selectionManager = new pskl.selection.SelectionManager(this.piskelController);
this.selectionManager.init();
this.historyService = new pskl.service.HistoryService(this.corePiskelController);
2012-09-16 15:10:05 +04:00
this.historyService.init();
this.notificationController = new pskl.controller.NotificationController();
this.notificationController.init();
2014-11-20 01:00:25 +03:00
this.transformationsController = new pskl.controller.TransformationsController();
this.transformationsController.init();
this.progressBarController = new pskl.controller.ProgressBarController();
this.progressBarController.init();
this.canvasBackgroundController = new pskl.controller.CanvasBackgroundController();
this.canvasBackgroundController.init();
this.galleryStorageService = new pskl.service.storage.GalleryStorageService(this.piskelController);
this.galleryStorageService.init();
this.localStorageService = new pskl.service.storage.LocalStorageService(this.piskelController);
this.localStorageService.init();
this.desktopStorageService = new pskl.service.storage.DesktopStorageService(this.piskelController);
this.desktopStorageService.init();
2013-09-07 19:50:43 +04:00
this.imageUploadService = new pskl.service.ImageUploadService();
this.imageUploadService.init();
this.cheatsheetService = new pskl.service.keyboard.CheatsheetService();
this.cheatsheetService.init();
this.savedStatusService = new pskl.service.SavedStatusService(this.piskelController);
this.savedStatusService.init();
this.backupService = new pskl.service.BackupService(this.piskelController);
this.backupService.init();
this.beforeUnloadService = new pskl.service.BeforeUnloadService(this.piskelController);
this.beforeUnloadService.init();
this.fileDropperService = new pskl.service.FileDropperService(
this.piskelController,
document.querySelector('#drawing-canvas-container'));
this.fileDropperService.init();
2014-07-12 02:41:39 +04:00
var drawingLoop = new pskl.rendering.DrawingLoop();
drawingLoop.addCallback(this.render, this);
drawingLoop.start();
2013-12-11 00:25:36 +04:00
this.initTooltips_();
var piskelData = this.getPiskelInitData_();
if (piskelData && piskelData.piskel) {
this.loadPiskel_(piskelData.piskel, piskelData.descriptor, piskelData.fps);
2013-10-10 02:06:11 +04:00
}
2014-08-22 02:37:35 +04:00
if (pskl.devtools) {
pskl.devtools.init();
2014-08-22 02:37:35 +04:00
}
if (pskl.utils.Environment.detectNodeWebkit() && pskl.utils.UserAgent.isMac) {
var gui = require('nw.gui');
var mb = new gui.Menu({type:'menubar'});
mb.createMacBuiltin('Piskel');
gui.Window.get().menu = mb;
}
2013-10-10 02:06:11 +04:00
},
loadPiskel_ : function (serializedPiskel, descriptor, fps) {
pskl.utils.serialization.Deserializer.deserialize(serializedPiskel, function (piskel) {
piskel.setDescriptor(descriptor);
pskl.app.piskelController.setPiskel(piskel);
pskl.app.previewController.setFPS(fps);
});
2013-10-10 02:06:11 +04:00
},
getPiskelInitData_ : function () {
return pskl.appEnginePiskelData_;
},
2014-02-10 04:00:16 +04:00
isLoggedIn : function () {
var piskelData = this.getPiskelInitData_();
return piskelData && piskelData.isLoggedIn;
2014-02-10 04:00:16 +04:00
},
2013-12-11 00:25:36 +04:00
initTooltips_ : function () {
$('body').tooltip({
selector: '[rel=tooltip]'
});
},
render : function (delta) {
this.drawingController.render(delta);
this.previewController.render(delta);
this.framesListController.render(delta);
},
2013-10-10 02:06:11 +04:00
getFirstFrameAsPng : function () {
var firstFrame = this.piskelController.getFrameAt(0);
var firstFrameCanvas = pskl.utils.FrameUtils.toImage(firstFrame);
return firstFrameCanvas.toDataURL('image/png');
2013-10-10 02:06:11 +04:00
},
getFramesheetAsPng : function () {
var renderer = new pskl.rendering.PiskelRenderer(this.piskelController);
var framesheetCanvas = renderer.renderAsCanvas();
return framesheetCanvas.toDataURL('image/png');
}
};
})();