camelot-unchained
Version:
Camelot Unchained Client Library
57 lines (49 loc) • 2.37 kB
JavaScript
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var defaultColors = ['#19b24b', '#feeb00', '#fe1e14', '#200000'];
var WoundColors = function () {
function WoundColors() {
_classCallCheck(this, WoundColors);
this.key = 'cse.wound.colors';
this.load();
}
_createClass(WoundColors, [{
key: 'load',
value: function load() {
var value = localStorage.getItem(this.key);
if (value && typeof value === 'string') {
this.colors = value.split(',');
// stored color validation
for (var i = 0; i < this.colors.length; i++) {
var color = this.colors[i];
var isValidColor = /(^#[0-9A-F]{6}$)/i.test(color) && color.length == 7;
if (!isValidColor) {
this.colors[i] = '#ffffff';
}
}
} else {
this.colors = defaultColors;
}
}
}, {
key: 'save',
value: function save() {
localStorage.setItem(this.key, this.colors.join(','));
}
}, {
key: 'getColorForWound',
value: function getColorForWound(wound) {
return this.colors[wound] || defaultColors[0];
}
}]);
return WoundColors;
}();
exports.WoundColors = WoundColors;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = WoundColors;