UNPKG

rl-loadout-lib

Version:

Load Rocket League assets into three.js

79 lines 3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const rocket_config_1 = require("../model/rocket-config"); const ids_1 = require("./ids"); const util_1 = require("./util"); /** * Make a json fetch request. * @param request request information passed to fetch(). * @throws an error object if the request was not successful * @return the json response object */ function doRequest(request) { return __awaiter(this, void 0, void 0, function* () { const response = yield fetch(request); const json = yield response.json(); if (!response.ok) { throw { status: response.status, body: json }; } return json; }); } exports.doRequest = doRequest; /** * Change the URL of an asset file based on the configuration. * @param path path to the original asset. * @param rocketConfig configuration */ function getAssetUrl(path, rocketConfig) { if (util_1.StringUtil.nullOrEmpty(path)) { return undefined; } if (path.endsWith('.tga')) { if (rocketConfig.textureQuality === rocket_config_1.TextureQuality.LOW && !path.endsWith('_S.tga')) { path = path.replace('.tga', '_S.tga'); } if (rocketConfig.textureFormat === rocket_config_1.TextureFormat.PNG) { path = path.replace('.tga', '.png'); } } if (path.endsWith('.glb') && rocketConfig.useCompressedModels && !path.endsWith('.draco.glb')) { path = path.replace('.glb', '.draco.glb'); } return `${rocketConfig.assetHost}/${path}`; } exports.getAssetUrl = getAssetUrl; /** * Tiered items can share items but use different assets. This function changes asset urls based on what tier the item is. * @param bodyId in-game id of the item * @param path path to the asset */ function fixTierUrl(bodyId, path) { if (path == undefined || path.length === 0) { return undefined; } if (path.toLowerCase().includes('TierAll')) { return path; } if (ids_1.TIER_2_BODIES.has(bodyId)) { return path.replace('Tier1', 'Tier2'); } else if (ids_1.TIER_3_BODIES.has(bodyId)) { return path.replace('Tier1', 'Tier3'); } return path; } exports.fixTierUrl = fixTierUrl; //# sourceMappingURL=network.js.map