Files
Undecked/Backend/dist/Icons.js
2023-08-29 20:06:52 +02:00

46 lines
1.7 KiB
JavaScript

Object.defineProperty(exports, "__esModule", { value: true });
exports.Icons = void 0;
var fs_1 = require("fs");
var path = require("path");
var Logger_1 = require("./Logger");
var Icons = /** @class */ (function () {
function Icons() {
this.materialPath = path.join(__filename, '..', '..', '..', 'Static', 'materialicons');
this.icons = [];
this.iconIDs = [];
}
Icons.prototype.load = function (callback) {
var _this = this;
(0, Logger_1.Log)('info', 'Loading icons');
(0, fs_1.readdir)(path.join(this.materialPath, 'black'), function (err, files) {
if (err)
throw err;
for (var i = 0; i < files.length; i++) {
if (files[i].includes('.png') && !files[i].includes('_low')) {
var fileID = files[i].replace('.png', '');
_this.iconIDs.push(fileID);
_this.icons.push({ id: fileID, name: fileID.replace(/_/g, ' ') });
}
}
(0, Logger_1.Log)('info', "Loaded ".concat(files.length, " icon(s)"));
callback();
});
};
Icons.prototype.getList = function () {
return this.icons;
};
Icons.prototype.getPath = function (iconID, style) {
if (this.iconIDs.includes(iconID))
return path.join(this.materialPath, style, "".concat(iconID, ".png"));
console.log("Invalid icon '".concat(iconID, "'"));
return null;
};
return Icons;
}());
exports.Icons = Icons;
// export interface Icons {
// load: (callback: () => void) => void;
// getList: () => { id: string; name: string }[];
// getPath: (iconID: string, style: 'black' | 'white') => string;
// }
//# sourceMappingURL=Icons.js.map