UNPKG

tf2-item-format

Version:
102 lines 3.42 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getUsableItem; exports.isKitException = isKitException; exports.getKitExceptions = getKitExceptions; exports.findKitExceptions = findKitExceptions; const getKillstreak_1 = __importDefault(require("../../shared/getKillstreak")); const schemaCache_1 = require("../../shared/schemaCache"); const SCHEMA_CACHE_KILLSTREAK_EXCEPTIONS_KEY = 'killstreakExceptions'; /** * Finds out which usable item it is * and its type * `output` or `target` * @param {string} name * @return {Object} */ function getUsableItem(schema, name) { // TODO: add series to itemNumber. // For chemistry sets the quality is predefined if (isStrangifierChemistrySet(name)) { return { target: name.replace(' Strangifier Chemistry Set', ''), output: 'Strangifier', outputQuality: 'Unique', }; } if (isChemistrySet(name)) { return { output: name .replace(' Chemistry Set', '') .replace("Collector's ", ''), outputQuality: "Collector's", }; } const item = getItemIfTarget(schema, name); if (item) { return { target: name .replace(` ${item}`, '') .replace(`${(0, getKillstreak_1.default)(name)} `, '') // Incase its uncraftable .replace('Non-Craftable ', '') // For Unusualifiers .replace('Unusual ', ''), }; } return null; } function isStrangifierChemistrySet(name) { return name.includes(' Strangifier Chemistry Set'); } function getItemIfTarget(schema, name) { const match = name.match(/ (Kit Fabricator|Strangifier|Unusualifier)/); if (match) { return match[1]; } if (!name.includes(' Kit')) { return; } if (isKitException(schema, name)) { return undefined; } return 'Kit'; } function isChemistrySet(name) { return name.includes(' Chemistry Set'); } function isKitException(schema, name) { return getKitExceptions(schema).some((exception) => name.includes(exception)); } function getKitExceptions(schema) { let exceptions = schemaCache_1.cache.get(schema, SCHEMA_CACHE_KILLSTREAK_EXCEPTIONS_KEY); if (exceptions) { return exceptions; } exceptions = findKitExceptions(schema); schemaCache_1.cache.save(schema, SCHEMA_CACHE_KILLSTREAK_EXCEPTIONS_KEY, exceptions); return exceptions; } function findKitExceptions(schema) { const items = schema.getItems(); const textures = schema.getTextures(); const effects = schema.getEffects(); const effectKitExceptions = Object.keys(effects).filter((effect) => effect.includes('Kit')); const textureKitExceptions = Object.keys(textures).filter((texture) => texture.includes('Kit')); const nameKitExceptions = items .filter((item) => { return ( // Exclude killstreak kits item.item_name !== 'Kit' && item.item_name.includes('Kit')); }) .map((item) => item.item_name); return [ ...effectKitExceptions, ...textureKitExceptions, ...nameKitExceptions, ]; } //# sourceMappingURL=getUsableItem.js.map