diff --git a/src/js/app.js b/src/js/app.js index ca1f875f..a139346e 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -36,6 +36,8 @@ this.piskelController.init(); this.paletteImportService = new pskl.service.palette.PaletteImportService(); + this.paletteImportService.init(); + this.paletteService = new pskl.service.palette.PaletteService(); this.paletteService.addDynamicPalette(new pskl.service.palette.CurrentColorsPalette()); @@ -95,7 +97,7 @@ this.selectionManager = new pskl.selection.SelectionManager(this.piskelController); this.selectionManager.init(); - this.historyService = new pskl.service.HistoryService(this.corePiskelController); + this.historyService = new pskl.service.HistoryService(this.piskelController); this.historyService.init(); this.notificationController = new pskl.controller.NotificationController(); @@ -131,7 +133,9 @@ this.imageUploadService = new pskl.service.ImageUploadService(); this.imageUploadService.init(); - this.savedStatusService = new pskl.service.SavedStatusService(this.piskelController, this.historyService); + this.savedStatusService = new pskl.service.SavedStatusService( + this.piskelController, + this.historyService); this.savedStatusService.init(); this.backupService = new pskl.service.BackupService(this.piskelController); @@ -140,7 +144,9 @@ this.beforeUnloadService = new pskl.service.BeforeUnloadService(this.piskelController); this.beforeUnloadService.init(); - this.headerController = new pskl.controller.HeaderController(this.piskelController, this.savedStatusService); + this.headerController = new pskl.controller.HeaderController( + this.piskelController, + this.savedStatusService); this.headerController.init(); this.penSizeService = new pskl.service.pensize.PenSizeService(); @@ -156,7 +162,8 @@ this.userWarningController.init(); this.performanceReportService = new pskl.service.performance.PerformanceReportService( - this.piskelController, this.currentColorsService); + this.piskelController, + this.currentColorsService); this.performanceReportService.init(); this.drawingLoop = new pskl.rendering.DrawingLoop(); diff --git a/src/js/controller/piskel/PublicPiskelController.js b/src/js/controller/piskel/PublicPiskelController.js index e8d82b9b..cc741ef6 100644 --- a/src/js/controller/piskel/PublicPiskelController.js +++ b/src/js/controller/piskel/PublicPiskelController.js @@ -1,6 +1,12 @@ (function () { var ns = $.namespace('pskl.controller.piskel'); + /** + * The PublicPiskelController is a decorator on PiskelController, provides the same API + * but will fire RESET/SAVE events when appropriate so that other objects get notified + * when important changes are made on the current Piskel. + * @param {PiskelController} piskelController the wrapped PiskelController + */ ns.PublicPiskelController = function (piskelController) { this.piskelController = piskelController; pskl.utils.wrap(this, this.piskelController); @@ -38,6 +44,10 @@ pskl.app.shortcutService.registerShortcut(shortcuts.MISC.DUPLICATE_FRAME, this.duplicateCurrentFrame.bind(this)); }; + ns.PublicPiskelController.prototype.getWrappedPiskelController = function () { + return this.piskelController; + }; + ns.PublicPiskelController.prototype.setPiskel = function (piskel, preserveState) { this.piskelController.setPiskel(piskel, preserveState); diff --git a/src/js/service/HistoryService.js b/src/js/service/HistoryService.js index 60f363f8..2e387235 100644 --- a/src/js/service/HistoryService.js +++ b/src/js/service/HistoryService.js @@ -2,7 +2,9 @@ var ns = $.namespace('pskl.service'); ns.HistoryService = function (piskelController, shortcutService, deserializer, serializer) { - this.piskelController = piskelController || pskl.app.piskelController; + // Use the real piskel controller that will not fire events when calling setters + this.piskelController = piskelController.getWrappedPiskelController(); + this.shortcutService = shortcutService || pskl.app.shortcutService; this.deserializer = deserializer || pskl.utils.serialization.arraybuffer.ArrayBufferDeserializer; this.serializer = serializer || pskl.utils.serialization.arraybuffer.ArrayBufferSerializer; diff --git a/src/js/service/palette/PaletteImportService.js b/src/js/service/palette/PaletteImportService.js index 3e81e935..4168653b 100644 --- a/src/js/service/palette/PaletteImportService.js +++ b/src/js/service/palette/PaletteImportService.js @@ -9,6 +9,7 @@ }; ns.PaletteImportService = function () {}; + ns.PaletteImportService.prototype.init = function () {}; ns.PaletteImportService.prototype.read = function (file, onSuccess, onError) { var reader = this.getReader_(file, onSuccess, onError); diff --git a/test/js/service/HistoryServiceTest.js b/test/js/service/HistoryServiceTest.js index c85f6541..1251a772 100644 --- a/test/js/service/HistoryServiceTest.js +++ b/test/js/service/HistoryServiceTest.js @@ -22,7 +22,16 @@ describe("History Service suite", function() { }; var createMockHistoryService = function () { - var mockPiskelController = { getPiskel : function () {}, getFPS : function () { return 12; } }; + var mockPiskelController = { + getWrappedPiskelController: function () { + return { + getPiskel : function () {}, + getFPS : function () { + return 12; + } + } + } + }; var mockShortcutService = { registerShortcuts : function () {}, registerShortcut : function () {}