mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Palette creator can save palettes to local storage
This commit is contained in:
38
src/js/model/Palette.js
Normal file
38
src/js/model/Palette.js
Normal file
@@ -0,0 +1,38 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.model');
|
||||
|
||||
ns.Palette = function (id, name, colors) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.colors = colors;
|
||||
};
|
||||
|
||||
ns.Palette.fromObject = function (paletteObj) {
|
||||
var colors = paletteObj.colors.slice(0 , paletteObj.colors.length);
|
||||
return new ns.Palette(paletteObj.id, paletteObj.name, colors);
|
||||
};
|
||||
|
||||
ns.Palette.prototype.get = function (index) {
|
||||
return this.colors[index];
|
||||
};
|
||||
|
||||
ns.Palette.prototype.set = function (index, color) {
|
||||
this.colors[index] = color;
|
||||
};
|
||||
|
||||
ns.Palette.prototype.add = function (color) {
|
||||
this.colors.push(color);
|
||||
};
|
||||
|
||||
ns.Palette.prototype.size = function () {
|
||||
return this.colors.length;
|
||||
};
|
||||
|
||||
ns.Palette.prototype.removeAt = function (index) {
|
||||
this.colors.splice(index, 1);
|
||||
};
|
||||
|
||||
ns.Palette.prototype.move = function (oldIndex, newIndex) {
|
||||
this.colors.splice(newIndex, 0, this.colors.splice(oldIndex, 1)[0]);
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user