UNPKG

enkanetwork

Version:

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

36 lines (35 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CharacterFinder = void 0; const errors_1 = require("../../errors"); class CharacterFinder { data; localization; constructor(data, localization) { this.data = data; this.localization = localization; } // Searching for a **character** by his ID (and by his skillDepotId) getById(id, skillDepotId) { if (skillDepotId) { const character = this.data.find((character) => character.id === id && character.skillDepotId === skillDepotId); if (!character) throw new errors_1.NoDataAssetsFound(`There is no character with id = ${id} and skillDepotId = ${skillDepotId}! (check the actuality of assets)`); return character; } const character = this.data.find((character) => character.id === id); if (!character) throw new errors_1.NoDataAssetsFound(`There is no character with id = ${id}! (check the actuality of assets)`); return character; } getName(character, language) { const nameLocalization = this.localization[character.nameTextMapHash]; if (!nameLocalization) throw new errors_1.NoLocalizationAssetsFound(`There is no localization for character with id = ${character.id}! (check the actuality of assets)`); const name = nameLocalization[language]; if (!name) throw new errors_1.NoLanguageFound("This language is not downloaded! Check the AssetsUpdater settings"); return name; } } exports.CharacterFinder = CharacterFinder;