UNPKG

tf2-item-format

Version:
177 lines 8.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ItemName_1 = __importDefault(require("./ParsedEcon/ItemName")); const hasAppData_1 = __importDefault(require("./ParsedEcon/hasAppData")); const getTags_1 = __importDefault(require("./ParsedEcon/getTags")); const getPropertyAttributes_1 = __importDefault(require("./ParsedEcon/getPropertyAttributes")); const getNameAttributes_1 = __importDefault(require("./ParsedEcon/getNameAttributes")); const getDescriptions_1 = __importDefault(require("./ParsedEcon/getDescriptions")); const getDefindex_1 = __importDefault(require("./ParsedEcon/getDefindex")); const getLevel_1 = __importDefault(require("./ParsedEcon/getLevel")); const getCrateNumber_1 = __importDefault(require("./ParsedEcon/getCrateNumber")); const getUses_1 = __importDefault(require("./ParsedEcon/getUses")); const getConvertedIntAttributes_1 = __importDefault(require("../shared/getConvertedIntAttributes")); const getDefindexes_1 = __importDefault(require("../shared/getDefindexes")); const guards_1 = require("../shared/guards"); /** * Parser class. * @todo Remove this entirely with better types. */ class ParsedEcon { constructor(schema, item, options) { this.schema = schema; this.item = Object.assign({}, item); this.options = options; this.itemName = new ItemName_1.default(this); this.fullEcon = (0, hasAppData_1.default)(this.item); this.tags = (0, getTags_1.default)(this); this.descriptions = (0, getDescriptions_1.default)(this); this.properties = (0, getPropertyAttributes_1.default)(this); this.nameAttrs = (0, getNameAttributes_1.default)(this); this.trueDefindex = (0, getDefindex_1.default)(this); this.level = (0, getLevel_1.default)(this); this.crateNumber = (0, getCrateNumber_1.default)(this); this.uses = (0, getUses_1.default)(this); } get id() { return this.item.assetid; } /** * Gets name from ECON. * @return {string} */ get name() { return this.itemName.origin; } getImageURL() { return `https://steamcommunity-a.akamaihd.net/economy/image/${this.item.icon_url}/`; } getLargeImageURL() { return `https://steamcommunity-a.akamaihd.net/economy/image/${this.item.icon_url_large}/`; } getNameAttributes(name, inNumbers, useDefindexes) { const texture = this.descriptions.texture || this.nameAttrs.texture; const itemNumber = this.getItemNumber(); let attrs = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ tradable: this.properties.tradable, craftable: this.descriptions.craftable, quality: this.tags.quality }, ((0, guards_1.hasDefindex)(texture) ? { texture } : {})), (this.tags.wear ? { wear: this.tags.wear } : {})), (this.properties.elevated ? { elevated: this.properties.elevated } : {})), (this.nameAttrs.australium ? { australium: this.nameAttrs.australium } : {})), (this.descriptions.festivized ? { festivized: this.descriptions.festivized } : {})), (this.descriptions.effect ? { effect: this.descriptions.effect } : {})), (this.nameAttrs.isUniqueHat ? { isUniqueHat: this.nameAttrs.isUniqueHat } : {})), (this.descriptions.killstreak.value ? { killstreak: this.descriptions.killstreak.value } : {})), (this.nameAttrs.target ? { target: this.nameAttrs.target } : {})), (this.nameAttrs.output ? { output: this.nameAttrs.output } : {})), (this.nameAttrs.outputQuality ? { outputQuality: this.nameAttrs.outputQuality } : {})), (itemNumber ? { itemNumber } : {})); if (inNumbers) { const convertedAttributes = (0, getConvertedIntAttributes_1.default)(this.schema, name, attrs); attrs.killstreak = convertedAttributes.killstreak; attrs.wear = convertedAttributes.wear; attrs.effect = convertedAttributes.effect; attrs.quality = convertedAttributes.quality; attrs.texture = convertedAttributes.texture; attrs.outputQuality = convertedAttributes.outputQuality; } if (useDefindexes) { // Add them here. const defindexes = (0, getDefindexes_1.default)(this.schema, name, this.nameAttrs.output || this.nameAttrs.target ? { target: this.nameAttrs.target, output: this.nameAttrs.output, outputQuality: this.nameAttrs.outputQuality, } : undefined); if (this.options.useTrueDefindex && this.trueDefindex !== -1) { attrs.defindex = this.trueDefindex; } else if ((0, guards_1.hasDefindex)(defindexes.defindex)) attrs.defindex = defindexes.defindex; if ((0, guards_1.hasDefindex)(defindexes.outputDefindex)) attrs.outputDefindex = defindexes.outputDefindex; if ((0, guards_1.hasDefindex)(defindexes.targetDefindex)) attrs.targetDefindex = defindexes.targetDefindex; } const cleanAttrs = removeUndefined(attrs); if ((0, guards_1.hasDefindex)(attrs.texture)) { cleanAttrs.texture = attrs.texture; } if ((0, guards_1.hasDefindex)(attrs.defindex)) { cleanAttrs.defindex = attrs.defindex; } if ((0, guards_1.hasDefindex)(attrs.outputDefindex)) { cleanAttrs.outputDefindex = attrs.outputDefindex; } if ((0, guards_1.hasDefindex)(attrs.targetDefindex)) { cleanAttrs.targetDefindex = attrs.targetDefindex; } if ((0, guards_1.hasDefindex)(attrs.quality)) { cleanAttrs.quality = attrs.quality; } cleanAttrs.craftable = attrs.craftable; return cleanAttrs; } getAttributes(shortName, inNumbers, useDefindexes) { // Types are silent now. let attributes; if (inNumbers === true) { if (useDefindexes) attributes = this.getNameAttributes(shortName, true, true); else attributes = this.getNameAttributes(shortName, true, false); } else if (useDefindexes === true) { attributes = this.getNameAttributes(shortName, false, true); } else { attributes = this.getNameAttributes(shortName, false, false); } return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, attributes), { level: this.level, classes: this.tags.classes, type: this.tags.type }), (this.descriptions.killstreak.killstreaker ? { killstreaker: this.descriptions.killstreak.killstreaker } : {})), (this.descriptions.killstreak.sheen ? { sheen: this.descriptions.killstreak.sheen } : {})), (this.tags.collection ? { collection: this.tags.collection } : {})), (this.tags.grade ? { grade: this.tags.grade } : {})), (this.descriptions.paint ? Object.assign({ paint: this.descriptions.paint }, (useDefindexes ? { paintDefindex: this.schema.getDefindex(this.descriptions.paint), } : {})) : {})), { parts: this.descriptions.parts, spells: this.descriptions.spells, marketable: this.properties.marketable, commodity: this.properties.commodity }), (this.uses ? { uses: this.uses } : {})); } getItemNumber() { if (this.nameAttrs.itemNumber || this.descriptions.itemNumber) return this.nameAttrs.itemNumber || this.descriptions.itemNumber; if (this.crateNumber) { return { value: this.crateNumber, type: 'crate', }; } } } exports.default = ParsedEcon; /** * Fix. */ function removeUndefined(obj) { const newObj = {}; const keys = Object.keys(obj); for (let i = 0; i < keys.length; i++) { const key = keys[i]; // TODO: fix. // @ts-ignore const value = obj[key]; // @ts-ignore if (value) newObj[key] = value; } return newObj; } //# sourceMappingURL=ParsedEcon.js.map