enkanetwork
Version:
API wrapper for enka.network written on TypeScript which provides localization, caching and convenience
30 lines (29 loc) • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SkillFinder = void 0;
const errors_1 = require("../../errors");
class SkillFinder {
data;
localization;
constructor(data, localization) {
this.data = data;
this.localization = localization;
}
// Searching for a **skill** by his ID
getById(id) {
const skill = this.data.find((skill) => skill.id === id);
if (!skill)
throw new errors_1.NoDataAssetsFound(`There is no skill with id = ${id}! (check the actuality of assets)`);
return skill;
}
getName(skill, language) {
const nameLocalizations = this.localization[skill.nameTextMapHash];
if (!nameLocalizations)
throw new errors_1.NoLocalizationAssetsFound(`There is no localization for skill with id = ${skill.id}! (check the actuality of assets)`);
const name = nameLocalizations[language];
if (!name)
throw new errors_1.NoLanguageFound("This language is not downloaded! Check the AssetsUpdater settings");
return name;
}
}
exports.SkillFinder = SkillFinder;