Renamed UsedColorsService to CurrentColorsService + exposed getCurrentColors explicitly

This commit is contained in:
jdescottes 2014-05-08 22:11:16 +02:00
parent 453fbcf88e
commit 94ce3907da
4 changed files with 14 additions and 8 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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);
};
})();

View File

@ -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",