UNPKG

enka-network-api

Version:

Enka-network API wrapper for Genshin Impact.

60 lines (59 loc) 3.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CharacterDetails = void 0; const config_file_js_1 = require("config_file.js"); const AssetsNotFoundError_1 = require("../../errors/AssetsNotFoundError"); const ImageAssets_1 = require("../assets/ImageAssets"); const TextAssets_1 = require("../assets/TextAssets"); const character_utils_1 = require("../../utils/character_utils"); const ExcelTransformer_1 = require("../../client/ExcelTransformer"); class CharacterDetails { constructor(data, isArchon, enka) { this.enka = enka; this._data = data; const json = new config_file_js_1.JsonReader(ExcelTransformer_1.excelJsonOptions, this._data); this.id = json.getAsNumber("fetterId"); this.characterId = json.getAsNumber("avatarId"); this._nameId = (0, character_utils_1.getNameIdByCharacterId)(this.characterId, enka); this.birthday = (json.has("infoBirthMonth") && json.has("infoBirthDay")) ? { month: json.getAsNumber("infoBirthMonth"), day: json.getAsNumber("infoBirthDay") } : null; this.location = new TextAssets_1.TextAssets(json.getAsNumber("avatarNativeTextMapHash"), enka); this.vision = new TextAssets_1.TextAssets(json.getAsNumber("avatarVisionBeforTextMapHash"), enka); this.constellation = new TextAssets_1.TextAssets(isArchon ? json.getAsNumber("avatarConstellationAfterTextMapHash") : json.getAsNumber("avatarConstellationBeforTextMapHash"), enka); this.constellationIcon = new ImageAssets_1.ImageAssets(`Eff_UI_Talent_${this._nameId}`, enka); this.title = new TextAssets_1.TextAssets(json.getAsNumber("avatarTitleTextMapHash"), enka); this.description = new TextAssets_1.TextAssets(json.getAsNumber("avatarDetailTextMapHash"), enka); this.cv = { chinese: new TextAssets_1.TextAssets(json.getAsNumber("cvChineseTextMapHash"), enka), japanese: new TextAssets_1.TextAssets(json.getAsNumber("cvJapaneseTextMapHash"), enka), english: new TextAssets_1.TextAssets(json.getAsNumber("cvEnglishTextMapHash"), enka), korean: new TextAssets_1.TextAssets(json.getAsNumber("cvKoreanTextMapHash"), enka), }; } getCvByLanguage(lang) { lang !== null && lang !== void 0 ? lang : (lang = this.enka.options.defaultLanguage); switch (lang) { case "chs": case "cht": return this.cv.chinese; case "jp": return this.cv.japanese; case "kr": return this.cv.korean; default: return this.cv.english; } } static getById(id, isArchon, enka) { const data = Object.values(enka.cachedAssetsManager.getExcelData("FetterInfoExcelConfigData")).find(f => new config_file_js_1.JsonReader(ExcelTransformer_1.excelJsonOptions, f).getAsNumber("fetterId") === id); if (!data) throw new AssetsNotFoundError_1.AssetsNotFoundError("FetterInfo", id); return new CharacterDetails(data, isArchon, enka); } static getByCharacterId(id, isArchon, enka) { const data = enka.cachedAssetsManager.getExcelData("FetterInfoExcelConfigData", id); if (!data) throw new AssetsNotFoundError_1.AssetsNotFoundError("FetterInfo by avatarId", id); return new CharacterDetails(data, isArchon, enka); } } exports.CharacterDetails = CharacterDetails;