UNPKG

enka-network-api

Version:

Enka-network API wrapper for Genshin Impact.

80 lines (79 loc) 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateCache = validateCache; /** * @returns whether the cache is valid or not */ function validateCache(enka, showLog) { let result = true; const artifactsCheck = checkArtifacts(enka.getAllArtifacts(false), showLog); if (!artifactsCheck) result = false; const textAssetsChecks = [enka.getAllCharacters(), enka.getAllWeapons(), enka.getAllCostumes(), enka.getAllMaterials(), enka.getAllArtifacts(), enka.getAllArtifactSets()].reduce((a, b) => [...a, ...b], []).map(target => [target, checkTextAssets(target)]); if (textAssetsChecks.some(check => Object.keys(check[1]).length !== 0) && showLog) console.warn("Missing TextHashMapId", textAssetsChecks.filter(check => Object.keys(check[1]).length !== 0)); const noSkills = enka.getAllCharacters().filter(c => !c.elementalSkill || !c.normalAttack); if (noSkills.length !== 0) { result = false; if (showLog) console.error("No skills", noSkills); } const noFriendshipNameCard = enka.getAllCharacters().filter(c => !c.nameCard && c.id !== 10000005 && c.id !== 10000007); if (noFriendshipNameCard.length !== 0) { result = false; if (showLog) console.error("No friendship namecard", noFriendshipNameCard); } const noConstellationNames = enka.getAllCharacters().filter(c => { var _a, _b; return !((_b = (_a = c.details) === null || _a === void 0 ? void 0 : _a.constellation) === null || _b === void 0 ? void 0 : _b.getNullable()); }); if (noConstellationNames.length !== 0) { result = false; if (showLog) console.error("No constellation name", noConstellationNames); } return result; } function checkArtifacts(artifacts, showLog) { let result = true; const list = []; for (const a of artifacts) { const name = `${a.stars}:${a.name.get()}`; if (list.includes(name)) { if (showLog) console.error(`Duplicated artifacts detected! ${name}`); result = false; } list.push(name); } return result; } /** * @param {object} obj * @param {string[]} route * @returns {object} */ function checkTextAssets(obj, route = []) { const keys = Object.keys(obj); let missing = {}; for (const key of keys) { const value = obj[key]; const currentRoute = [...route, key]; if (value == null || value == undefined || typeof value !== "object") continue; const valueObject = value; if (valueObject.fetchUser) continue; // ignore enkaclient if (valueObject.get && typeof valueObject.get === "function") { // if text assets try { valueObject.get(); } catch (_a) { missing[valueObject.id] = currentRoute; } } else if (typeof value === "object") { missing = Object.assign(Object.assign({}, missing), checkTextAssets(valueObject, currentRoute)); } } return missing; }