UNPKG

enka-network-api

Version:

Enka-network API wrapper for Genshin Impact.

60 lines (59 loc) 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Costume = 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 CharacterData_1 = require("./CharacterData"); const ExcelTransformer_1 = require("../../client/ExcelTransformer"); class Costume { constructor(data, enka) { this.enka = enka; this._data = data; const json = new config_file_js_1.JsonReader(ExcelTransformer_1.excelJsonOptions, this._data); this.id = json.getAsNumber("skinId"); this.name = new TextAssets_1.TextAssets(json.getAsNumber("nameTextMapHash"), enka); this.description = new TextAssets_1.TextAssets(json.getAsNumber("descTextMapHash"), enka); this.characterId = json.getAsNumber("characterId"); this.isDefault = json.getAsBooleanWithDefault(false, "isDefault"); this._nameId = !this.isDefault ? [json.getAsString("jsonName")].map(jsonName => jsonName.slice(jsonName.lastIndexOf("_") + 1))[0] : (0, character_utils_1.getNameIdByCharacterId)(this.characterId, enka); this.icon = new ImageAssets_1.ImageAssets(`UI_AvatarIcon_${this._nameId}`, enka); this.sideIcon = new ImageAssets_1.ImageAssets(`UI_AvatarIcon_Side_${this._nameId}`, enka); this.splashImage = new ImageAssets_1.ImageAssets(!this.isDefault ? `UI_Costume_${this._nameId}` : `UI_Gacha_AvatarImg_${this._nameId}`, enka); this.stars = !this.isDefault ? json.getAsNumber("quality") : null; this.cardIcon = new ImageAssets_1.ImageAssets(this.isDefault ? "UI_AvatarIcon_Costume_Card" : `UI_AvatarIcon_${this._nameId}_Card`, enka); } getCharacterData() { return CharacterData_1.CharacterData.getById(this.characterId, this.enka); } static getById(characterId, id, enka) { const data = enka.cachedAssetsManager.getExcelData("AvatarCostumeExcelConfigData", characterId, id); if (!data) throw new AssetsNotFoundError_1.AssetsNotFoundError("Costume", id); return new Costume(data, enka); } // TODO: make this faster static getBySkinId(id, enka) { const json = Object.values(enka.cachedAssetsManager.getExcelData("AvatarCostumeExcelConfigData")) .flatMap(c => Object.values(c)) .map(c => new config_file_js_1.JsonReader(ExcelTransformer_1.excelJsonOptions, c)) .find(j => j.getAsNumber("skinId") === id); if (!json) throw new AssetsNotFoundError_1.AssetsNotFoundError("Costume", id); return new Costume(json.getAsJsonObject(), enka); } static getDefaultCostumeByCharacterId(characterId, enka) { const characterCostumes = enka.cachedAssetsManager.getExcelData("AvatarCostumeExcelConfigData", characterId); if (!characterCostumes) throw new AssetsNotFoundError_1.AssetsNotFoundError("Costume for character id", characterId); const json = Object.values(characterCostumes) .map(c => new config_file_js_1.JsonReader(ExcelTransformer_1.excelJsonOptions, c)) .find(j => j.getAsNumber("characterId") === characterId && j.getAsBooleanWithDefault(false, "isDefault")); if (!json) throw new AssetsNotFoundError_1.AssetsNotFoundError("Default costume", characterId); return new Costume(json.getAsJsonObject(), enka); } } exports.Costume = Costume;