tf2-item-format
Version:
Format's TF2 items like backpack.tf does
39 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isQualityException = isQualityException;
exports.getQualityExceptions = getQualityExceptions;
exports.findQualityExceptions = findQualityExceptions;
const schemaCache_1 = require("../../../shared/schemaCache");
function isQualityException(schema, quality, name) {
const exceptions = getQualityExceptions(schema, quality);
return exceptions.some((e) => name == e || name.includes(e + " ") || name.includes(" " + e));
}
function getQualityCacheKey(quality) {
return `${quality}Exceptions`;
}
function getQualityExceptions(schema, quality) {
const cacheKey = getQualityCacheKey(quality);
let exceptions = schemaCache_1.cache.get(schema, cacheKey);
if (exceptions) {
return exceptions;
}
exceptions = findQualityExceptions(schema, quality);
schemaCache_1.cache.save(schema, cacheKey, exceptions);
return exceptions;
}
function findQualityExceptions(schema, quality) {
const items = schema.getItems();
const effects = schema.getEffects();
const textures = schema.getTextures();
const effectExceptionsForQuality = Object.keys(effects).filter((effect) => effect.includes(quality));
const textureExceptionsForQuality = Object.keys(textures).filter((texture) => texture.includes(quality));
const nameExceptionsForQuality = items
.filter((item) => item.item_name.includes(`${quality} `))
.map((item) => item.item_name);
return [
...effectExceptionsForQuality,
...textureExceptionsForQuality,
...nameExceptionsForQuality,
];
}
//# sourceMappingURL=exceptions.js.map