Merge pull request #90 from grosbouddha/clean-framesheet-reset

Fix broken palette when switching tiles
This commit is contained in:
grosbouddha 2012-09-16 08:31:42 -07:00
commit f18a9114fc
2 changed files with 26 additions and 13 deletions

View File

@ -28,7 +28,7 @@ Events = {
REDRAW_PREVIEWFILM: "REDRAW_PREVIEWFILM", REDRAW_PREVIEWFILM: "REDRAW_PREVIEWFILM",
GRID_DISPLAY_STATE_CHANGED: "GRID_DISPLAY_STATE_CHANGED", GRID_DISPLAY_STATE_CHANGED: "GRID_DISPLAY_STATE_CHANGED",
/** /**
* The framesheet was reseted and is now probably drastically different. * The framesheet was reseted and is now probably drastically different.
* Number of frames, content of frames, color used for the palette may have changed. * Number of frames, content of frames, color used for the palette may have changed.

View File

@ -14,15 +14,22 @@
$.publish(Events.COLOR_SELECTED, [inputPicker.val(), evt.data.isPrimary]); $.publish(Events.COLOR_SELECTED, [inputPicker.val(), evt.data.isPrimary]);
}; };
/** /**
* @private * @private
*/ */
ns.PaletteController.prototype.createPalette_ = function (colors) { ns.PaletteController.prototype.createPaletteMarkup_ = function (colors) {
// Always adding transparent color // Always adding transparent color
this.paletteRoot.html('<span class="palette-color transparent-color" data-color="TRANSPARENT" title="Transparent"></span>'); this.paletteRoot.html('<span class="palette-color transparent-color" data-color="TRANSPARENT" title="Transparent"></span>');
for(var color in colors) {
for(var i=0, l=this.paletteColors.length; i<l; i++) {
if(color != Constants.TRANSPARENT_COLOR) { if(color != Constants.TRANSPARENT_COLOR) {
this.addColorToPalette_(color); var color = this.paletteColors[i];
var colorEl = document.createElement("li");
colorEl.className = "palette-color";
colorEl.setAttribute("data-color", color);
colorEl.setAttribute("title", color);
colorEl.style.background = color;
this.paletteRoot.append(colorEl);
} }
} }
}; };
@ -32,16 +39,19 @@
*/ */
ns.PaletteController.prototype.addColorToPalette_ = function (color) { ns.PaletteController.prototype.addColorToPalette_ = function (color) {
if (this.paletteColors.indexOf(color) == -1 && color != Constants.TRANSPARENT_COLOR) { if (this.paletteColors.indexOf(color) == -1 && color != Constants.TRANSPARENT_COLOR) {
var colorEl = document.createElement("li");
colorEl.className = "palette-color";
colorEl.setAttribute("data-color", color);
colorEl.setAttribute("title", color);
colorEl.style.background = color;
this.paletteRoot.append(colorEl);
this.paletteColors.push(color); this.paletteColors.push(color);
} }
}; };
/**
* @private
*/
ns.PaletteController.prototype.addColorsToPalette_ = function (colors) {
for(var color in colors) {
this.addColorToPalette_(color);
}
};
/** /**
* @private * @private
*/ */
@ -86,16 +96,19 @@
this.framesheet = framesheet; this.framesheet = framesheet;
// Initialize palette: // Initialize palette:
this.createPalette_(this.framesheet.getUsedColors()); this.addColorsToPalette_(this.framesheet.getUsedColors());
this.createPaletteMarkup_();
$.subscribe(Events.FRAMESHEET_RESET, $.proxy(function(evt) { $.subscribe(Events.FRAMESHEET_RESET, $.proxy(function(evt) {
this.createPalette_(this.framesheet.getUsedColors()); this.addColorsToPalette_(this.framesheet.getUsedColors());
this.createPaletteMarkup_();
}, this)); }, this));
this.paletteRoot.mouseup($.proxy(this.onPaletteColorClick_, this)); this.paletteRoot.mouseup($.proxy(this.onPaletteColorClick_, this));
$.subscribe(Events.COLOR_SELECTED, $.proxy(function(evt, color) { $.subscribe(Events.COLOR_SELECTED, $.proxy(function(evt, color) {
this.addColorToPalette_(color); this.addColorToPalette_(color);
this.createPaletteMarkup_();
}, this)); }, this));
// Initialize colorpickers: // Initialize colorpickers: