UNPKG

tf2-item-format

Version:
86 lines 4.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Attributes_1 = __importDefault(require("./parseString/Attributes")); const decomposeName_1 = __importDefault(require("./shared/decomposeName")); const getConvertedIntAttributes_1 = __importDefault(require("./shared/getConvertedIntAttributes")); const getDefindexes_1 = __importDefault(require("./shared/getDefindexes")); const isEmpty_1 = __importDefault(require("./util/isEmpty")); const guards_1 = require("./shared/guards"); // Default behaviour should never happen. function parseString(schema, name, inNumbers = false, useDefindexes = false) { let attributes = new Attributes_1.default(schema, name); const itemName = (0, decomposeName_1.default)(name, attributes); // TODO: change this with overloads. const parsedAttributes = { name: itemName, craftable: attributes.craftable, quality: attributes.quality.value, }; if (inNumbers) { const convertedAttributes = (0, getConvertedIntAttributes_1.default)(schema, itemName, { killstreak: attributes.killstreak, wear: attributes.wear, effect: attributes.effect, quality: attributes.quality.value, outputQuality: attributes.usableItem && attributes.usableItem.outputQuality, texture: attributes.texture, }); if (!convertedAttributes.killstreak) delete convertedAttributes.killstreak; if (!convertedAttributes.wear) delete convertedAttributes.wear; if (!convertedAttributes.effect) delete convertedAttributes.effect; if (!(0, guards_1.hasDefindex)(convertedAttributes.texture)) delete convertedAttributes.texture; if (!(0, guards_1.hasDefindex)(convertedAttributes.outputQuality)) delete convertedAttributes.outputQuality; Object.assign(parsedAttributes, convertedAttributes); } const defindexes = useDefindexes ? (0, getDefindexes_1.default)(schema, itemName, attributes.usableItem || undefined) : {}; if ((0, guards_1.hasDefindex)(defindexes.defindex)) parsedAttributes.defindex = defindexes.defindex; if (attributes.quality.elevated) parsedAttributes.elevated = attributes.quality.elevated; if (attributes.isUniqueHat) parsedAttributes.isUniqueHat = attributes.isUniqueHat; if (attributes.australium) parsedAttributes.australium = attributes.australium; if (attributes.festivized) parsedAttributes.festivized = attributes.festivized; if (attributes.killstreak && !parsedAttributes.killstreak) parsedAttributes.killstreak = attributes.killstreak; if (attributes.wear && !parsedAttributes.wear) parsedAttributes.wear = attributes.wear; if ((0, guards_1.hasDefindex)(attributes.texture) && !(0, guards_1.hasDefindex)(parsedAttributes.texture)) parsedAttributes.texture = attributes.texture; if (attributes.effect && !parsedAttributes.effect) parsedAttributes.effect = attributes.effect; if (attributes.usableItem && !(0, isEmpty_1.default)(attributes.usableItem)) { if (attributes.usableItem.target) parsedAttributes.target = attributes.usableItem.target; if (attributes.usableItem.output) parsedAttributes.output = attributes.usableItem.output; if (!(0, guards_1.hasDefindex)(parsedAttributes.outputQuality) && (0, guards_1.hasDefindex)(attributes.usableItem.outputQuality)) parsedAttributes.outputQuality = attributes.usableItem.outputQuality; if ((0, guards_1.hasDefindex)(defindexes.targetDefindex)) parsedAttributes.targetDefindex = defindexes.targetDefindex; if ((0, guards_1.hasDefindex)(defindexes.outputDefindex)) parsedAttributes.outputDefindex = defindexes.outputDefindex; } if (attributes.itemNumber && !(0, isEmpty_1.default)(attributes.itemNumber)) parsedAttributes.itemNumber = attributes.itemNumber; // Move convertor to the last step. return parsedAttributes; } exports.default = parseString; //# sourceMappingURL=parseString.js.map