UNPKG

enkanetwork

Version:

API wrapper for enka.network written on TypeScript which provides localization, caching and convenience

85 lines (84 loc) 4.08 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AssetsFinder = void 0; const AssetsManager_1 = require("../AssetsManager"); const CharacterFinder_1 = require("./CharacterFinder"); const ConstellationFinder_1 = require("./ConstellationFinder"); const CostumeFinder_1 = require("./CostumeFinder"); const NamecardFinder_1 = require("./NamecardFinder"); const ProfilePictureFinder_1 = require("./ProfilePictureFinder"); const ReliquaryFinder_1 = require("./ReliquaryFinder"); const ReliquarySetFinder_1 = require("./ReliquarySetFinder"); const SkillFinder_1 = require("./SkillFinder"); const WeaponFinder_1 = require("./WeaponFinder"); const adapters_1 = require("./adapters"); __exportStar(require("./adapters"), exports); __exportStar(require("./CharacterFinder"), exports); __exportStar(require("./NamecardFinder"), exports); __exportStar(require("./WeaponFinder"), exports); class AssetsFinder { data; localization; adapter; characters; namecards; costumes; weapons; reliquaries; reliquarySets; constellations; skills; profilePictures; constructor({ uiAssetsPath, adapter, dataManager = new AssetsManager_1.DataManager(), localizationManager = new AssetsManager_1.LocalizationManager(), } = {}) { this.adapter = adapter ?? new adapters_1.OriginAdapter({ baseUrl: uiAssetsPath }); this.data = dataManager; this.localization = localizationManager; this.characters = new CharacterFinder_1.CharacterFinder(dataManager.characters, localizationManager.characters); this.namecards = new NamecardFinder_1.NamecardFinder(dataManager.namecards, localizationManager.namecards); this.constellations = new ConstellationFinder_1.ConstellationFinder(dataManager.constellations, localizationManager.constellations); this.skills = new SkillFinder_1.SkillFinder(dataManager.skills, localizationManager.skills); this.costumes = new CostumeFinder_1.CostumeFinder(dataManager.costumes, localizationManager.costumes); this.weapons = new WeaponFinder_1.WeaponFinder(localizationManager.weapons); this.reliquaries = new ReliquaryFinder_1.ReliquaryFinder(localizationManager.reliquary); this.reliquarySets = new ReliquarySetFinder_1.ReliquarySetFinder(localizationManager.reliquarySets); this.profilePictures = new ProfilePictureFinder_1.ProfilePictureFinder(dataManager.profilePictures, localizationManager.profilePictures); } getAssetPath(filename) { return this.adapter.resolve(filename); } /** Await any in-flight background work in the adapter (e.g. cache downloads). */ async flush() { await this.adapter.flush?.(); } /** Resolve the given filenames (triggering caching) and await completion. */ async prefetch(filenames) { for (const filename of filenames) this.adapter.resolve(filename); await this.flush(); } /** * Warm the adapter's cache: resolve any extra `filenames` (e.g. derived ones) * and await all pending downloads. Call after `fetchUser` so every icon the * models reference — including `weapon.awakenIcon` — is on disk. */ async warm(filenames = []) { for (const filename of filenames) this.adapter.resolve(filename); await this.flush(); } } exports.AssetsFinder = AssetsFinder;