mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Move intToHex to utils and change for to map
This commit is contained in:
parent
6ea9c248d8
commit
ffca6aa44c
|
@ -65,27 +65,6 @@
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO Move to utils
|
|
||||||
var componentToHex = function (c) {
|
|
||||||
var hex = c.toString(16);
|
|
||||||
return hex.length == 1 ? '0' + hex : hex;
|
|
||||||
};
|
|
||||||
|
|
||||||
var rgbToHex = function (r, g, b) {
|
|
||||||
return '#' + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
||||||
};
|
|
||||||
|
|
||||||
var intHexCache = {};
|
|
||||||
var intToHex = function(int) {
|
|
||||||
if (intHexCache[int]) {
|
|
||||||
return intHexCache[int];
|
|
||||||
}
|
|
||||||
|
|
||||||
var hex = rgbToHex(int & 0xff, int >> 8 & 0xff, int >> 16 & 0xff);
|
|
||||||
intHexCache[int] = hex;
|
|
||||||
return hex;
|
|
||||||
};
|
|
||||||
|
|
||||||
var frameCache = {};
|
var frameCache = {};
|
||||||
ns.CurrentColorsService.prototype.updateCurrentColors_ = function () {
|
ns.CurrentColorsService.prototype.updateCurrentColors_ = function () {
|
||||||
var layers = this.piskelController.getLayers();
|
var layers = this.piskelController.getLayers();
|
||||||
|
@ -135,11 +114,9 @@
|
||||||
// Remove transparent color from used colors
|
// Remove transparent color from used colors
|
||||||
delete colors[pskl.utils.colorToInt(Constants.TRANSPARENT_COLOR)];
|
delete colors[pskl.utils.colorToInt(Constants.TRANSPARENT_COLOR)];
|
||||||
|
|
||||||
var hexColors = [];
|
var hexColors = Object.keys(colors).map(function (color) {
|
||||||
for (var i in colors) {
|
return pskl.utils.intToHex(color);
|
||||||
hexColors.push(intToHex(i));
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.setCurrentColors(hexColors);
|
this.setCurrentColors(hexColors);
|
||||||
}.bind(this, colors);
|
}.bind(this, colors);
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,17 @@ if (!Uint32Array.prototype.fill) {
|
||||||
return hex.length == 1 ? '0' + hex : hex;
|
return hex.length == 1 ? '0' + hex : hex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var intHexCache = {};
|
||||||
|
ns.intToHex = function(int) {
|
||||||
|
if (intHexCache[int]) {
|
||||||
|
return intHexCache[int];
|
||||||
|
}
|
||||||
|
|
||||||
|
var hex = ns.rgbToHex(int & 0xff, int >> 8 & 0xff, int >> 16 & 0xff);
|
||||||
|
intHexCache[int] = hex;
|
||||||
|
return hex;
|
||||||
|
};
|
||||||
|
|
||||||
ns.normalize = function (value, def) {
|
ns.normalize = function (value, def) {
|
||||||
if (typeof value === 'undefined' || value === null) {
|
if (typeof value === 'undefined' || value === null) {
|
||||||
return def;
|
return def;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user