UNPKG

tf2-item-format

Version:
136 lines 4.55 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 = default_1; const stringify_1 = __importDefault(require("./stringify")); const guards_1 = require("./shared/guards"); const guards_2 = require("./types/guards"); const DEFAULT_OPTIONS = { unuSkinsToDecorated: true, }; /** * Creates a listing object that you can sent to backpack.tf * @todo work with SKU attributes */ function default_1(schema, item, options = {}) { options = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options); let name; if ((0, guards_2.skuTypeGuard)(item)) { name = schema.getName(item.defindex); } else if ((0, guards_2.nameTypeGuard)(item)) { name = item.name; } else { throw new Error('Defindex or Name is missing.'); } return { quality: getQuality(schema, item, options), craftable: item.craftable ? 1 : 0, item_name: getItem(schema, name, item), priceindex: getPriceindex(schema, name, item), }; } function getQuality(schema, item, options) { let { quality } = item; const { elevated } = item; if (options.unuSkinsToDecorated && isUnusualSkin(item)) { /* - decorated - unusual - strange decorated - strange unusual - strange */ quality = 'Decorated Weapon'; } return elevated ? `Strange ${schema.getQualityName(quality)}` : quality; } function getItem(schema, name, item) { return (0, stringify_1.default)(schema, { name: getRightName(schema, name, item), australium: item.australium, // Don't add it if it's already in the name. killstreak: isKillstreakKit(name) || isFabricator(name) ? 0 : item.killstreak, craftable: true, festivized: item.festivized, quality: 6, wear: item.wear, }, { determineUniqueHat: false }); } function getRightName(schema, name, item) { // We keep kit in the name but backpack.tf does not accept it. if (isFabricator(name)) return name.replace('Kit ', ''); if ((0, guards_1.hasDefindex)(item.texture)) return `${schema.getTextureName(item.texture)} | ${name}`; return name; } function getPriceindex(schema, name, item) { let targetDefindex; let outputDefindex; if ((0, guards_2.skuTypeGuard)(item)) { targetDefindex = item.targetDefindex; outputDefindex = item.outputDefindex; } else if ((0, guards_2.nameTypeGuard)(item)) { targetDefindex = item.targetDefindex || (item.target && schema.getDefindex(item.target)); outputDefindex = item.outputDefindex || (item.output && schema.getDefindex(item.output)); } if (item.effect) { return schema.getEffectEnum(item.effect); } if (item.itemNumber && isCrate(item.itemNumber)) return item.itemNumber.value; if (isUnusualfierOrStrangifier(name)) return targetDefindex; if (isChemistrySet(name)) { let priceindex = `${outputDefindex}-${schema.getQualityEnum(item.outputQuality)}`; if (hasTarget(targetDefindex)) priceindex += `-${targetDefindex}`; return priceindex; } if (isKillstreakKit(name)) return `${schema.getKillstreakEnum(item.killstreak)}-${targetDefindex}`; // as defindex if (isFabricator(name)) return `${getKitDefindex(schema, item)}-6-${targetDefindex}`; return 0; } function isCrate(itemNumber) { return itemNumber.type === 'crate'; } function isUnusualfierOrStrangifier(name) { return !!(name && (name === 'Unusualifier' || name === 'Strangifier')); } function isChemistrySet(name) { return name.includes('Chemistry Set'); } function hasTarget(targetDefindex) { return !!targetDefindex || targetDefindex === 0; } function isKillstreakKit(name) { return name.includes('Kit') && !isFabricator(name); } function isFabricator(name) { return name.includes('Fabricator'); } function getKitDefindex(schema, item) { return schema.getDefindex((0, stringify_1.default)(schema, { name: 'Kit', killstreak: item.killstreak, craftable: true, quality: 6, })); } function isUnusualSkin(item) { return item.effect && item.texture && item.wear; } //# sourceMappingURL=createBPListing.js.map