diff --git a/src/js/app.js b/src/js/app.js index bc5d8299..ecca93f5 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -39,10 +39,10 @@ this.paletteController = new pskl.controller.PaletteController(); this.paletteController.init(); - this.usedColorsService = new pskl.service.UsedColorsService(this.piskelController); - this.usedColorsService.init(); + this.currentColorsService = new pskl.service.CurrentColorsService(this.piskelController); + this.currentColorsService.init(); - this.palettesListController = new pskl.controller.PalettesListController(this.paletteController, this.usedColorsService); + this.palettesListController = new pskl.controller.PalettesListController(this.paletteController, this.currentColorsService); this.palettesListController.init(); this.cursorCoordinatesController = new pskl.controller.CursorCoordinatesController(this.piskelController); diff --git a/src/js/controller/PalettesListController.js b/src/js/controller/PalettesListController.js index b0255372..efbe9acd 100644 --- a/src/js/controller/PalettesListController.js +++ b/src/js/controller/PalettesListController.js @@ -64,7 +64,7 @@ var colors = []; var paletteId = this.colorPaletteSelect_.value; if (paletteId === Constants.CURRENT_COLORS_PALETTE_ID) { - colors = this.usedColorService.currentColors; + colors = this.usedColorService.getCurrentColors(); } else { var palette = this.getPaletteById(paletteId, this.retrievePalettes()); if (palette) { diff --git a/src/js/service/UsedColorsService.js b/src/js/service/CurrentColorsService.js similarity index 79% rename from src/js/service/UsedColorsService.js rename to src/js/service/CurrentColorsService.js index bb97691e..e8f282cf 100644 --- a/src/js/service/UsedColorsService.js +++ b/src/js/service/CurrentColorsService.js @@ -1,18 +1,22 @@ (function () { var ns = $.namespace('pskl.service'); - ns.UsedColorsService = function (piskelController) { + ns.CurrentColorsService = function (piskelController) { this.piskelController = piskelController; this.currentColors = []; this.framesColorsCache_ = {}; }; - ns.UsedColorsService.prototype.init = function () { + ns.CurrentColorsService.prototype.init = function () { $.subscribe(Events.PISKEL_RESET, this.onPiskelUpdated_.bind(this)); $.subscribe(Events.TOOL_RELEASED, this.onPiskelUpdated_.bind(this)); }; - ns.UsedColorsService.prototype.onPiskelUpdated_ = function (evt) { + ns.CurrentColorsService.prototype.getCurrentColors = function () { + return this.currentColors; + }; + + ns.CurrentColorsService.prototype.onPiskelUpdated_ = function (evt) { var layers = this.piskelController.getLayers(); var frames = layers.map(function (l) {return l.getFrames();}).reduce(function (p, n) {return p.concat(n);}); var colors = {}; @@ -40,6 +44,8 @@ return 0; } }); + + // TODO : only fire if there was a change $.publish(Events.CURRENT_COLORS_UPDATED, colors); }; })(); \ No newline at end of file diff --git a/src/piskel-script-list.js b/src/piskel-script-list.js index a11eb57b..3bc34634 100644 --- a/src/piskel-script-list.js +++ b/src/piskel-script-list.js @@ -106,7 +106,7 @@ "js/service/keyboard/KeycodeTranslator.js", "js/service/keyboard/CheatsheetService.js", "js/service/ImageUploadService.js", - "js/service/UsedColorsService.js", + "js/service/CurrentColorsService.js", // Tools "js/drawingtools/BaseTool.js",