From 3664d87751f4672c703841d82fb3555cee02115d Mon Sep 17 00:00:00 2001 From: Firstname Lastname Date: Wed, 29 Aug 2012 10:15:18 +0200 Subject: [PATCH] temp commit --- js/frameSheetModel.js | 29 ++++++++++++++++++++++++++++- js/piskel.js | 3 ++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/js/frameSheetModel.js b/js/frameSheetModel.js index 38232494..3a833d6c 100644 --- a/js/frameSheetModel.js +++ b/js/frameSheetModel.js @@ -19,7 +19,34 @@ var FrameSheetModel = (function() { }, getUsedColors : function () { - return ["#000", "#fff"] + var colors = []; + var pixels = this.getAllPixels(); + for (var i = 0 ; i < pixels.length ; i++) { + var pixel = pixels[i]; + if (pixel && colors.indexOf(pixel)) { + colors.push(pixel); + } + } + return colors; + }, + + getAllPixels : function () { + var pixels = []; + for (var i = 0 ; i < frames.length ; i++) { + pixels = pixels.concat(this.getFramePixels(frames[i])); + } + return pixels; + }, + + getFramePixels : function (frame) { + var pixels = []; + for (var i = 0 ; i < frame.length ; i++) { + var line = frame[i]; + for (var j = 0 ; j < line.length ; j++) { + pixels.push(line[j]); + } + } + return pixels; }, // Could be used to pass around model using long GET param (good enough for simple models) and diff --git a/js/piskel.js b/js/piskel.js index bdb582f9..090535d6 100644 --- a/js/piskel.js +++ b/js/piskel.js @@ -77,7 +77,7 @@ }, onPickerChange : function(evt) { - penColor = colorPicker.value; + penColor = "#" + this.colorPicker.value; }, initPalette : function (color) { @@ -88,6 +88,7 @@ var color = colors[i]; var colorEl = document.createElement("li"); colorEl.setAttribute("data-color", color); + colorEl.innerHTML = color; paletteEl.appendChild(colorEl); } },