genshin-manager
Version:
<div align="center"> <p> <a href="https://www.npmjs.com/package/genshin-manager"><img src="https://img.shields.io/npm/v/genshin-manager.svg?maxAge=3600" alt="npm version" /></a> <a href="https://www.npmjs.com/package/genshin-manager"><img src="https:
222 lines (221 loc) • 10.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectKeyDecoder = void 0;
const Client_1 = require("../client/Client");
/**
* Class of replace data
*/
class ReplaceData {
constructor(oldKey, newKey) {
this.oldKey = oldKey;
this.newKey = newKey;
}
}
/**
* Class of object key decoder
*/
class ObjectKeyDecoder {
/**
* Create a ObjectKeyDecoder
*/
constructor() {
var _a, _b, _c, _d, _e;
/**
* object key replace data
*/
this.replaceDatas = [];
// Replace key of ProfilePictureExcelConfigData (add infoId&type)
if (Client_1.Client._hasCachedExcelBinOutputByName('ProfilePictureExcelConfigData')) {
const profilePictureDataArray = Object.values(Client_1.Client._getCachedExcelBinOutputByName('ProfilePictureExcelConfigData'));
const dummyProfilePicture = profilePictureDataArray.find((data) => data.id === 99999);
this.replaceDatas.push(new ReplaceData((_a = Object.entries(dummyProfilePicture).find(([, v]) => v === 'PROFILE_PICTURE_UNLOCK_BY_ITEM')) === null || _a === void 0 ? void 0 : _a[0], 'type'));
}
// Replace key of WeaponPromoteExcelConfigData (add promoteLevel & unlockMaxLevel)
if (Client_1.Client._hasCachedExcelBinOutputByName('WeaponPromoteExcelConfigData')) {
const weaponPromoteDataArray = Object.values(Client_1.Client._getCachedExcelBinOutputByName('WeaponPromoteExcelConfigData'));
const sampleWeaponPromoteData = weaponPromoteDataArray.find((data) => data.weaponPromoteId === 11101 && data.requiredPlayerLevel === 15);
this.replaceDatas.push(new ReplaceData((_b = Object.entries(sampleWeaponPromoteData).find(([, v]) => v === 1)) === null || _b === void 0 ? void 0 : _b[0], 'promoteLevel'));
this.replaceDatas.push(new ReplaceData((_c = Object.entries(sampleWeaponPromoteData).find(([, v]) => v === 40)) === null || _c === void 0 ? void 0 : _c[0], 'unlockMaxLevel'));
}
// Replace key of AvatarPromoteExcelConfigData (add promoteLevel & unlockMaxLevel)
if (Client_1.Client._hasCachedExcelBinOutputByName('AvatarPromoteExcelConfigData')) {
const avatarPromoteDataArray = Object.values(Client_1.Client._getCachedExcelBinOutputByName('AvatarPromoteExcelConfigData'));
const sampleAvatarPromoteData = avatarPromoteDataArray.find((data) => data.avatarPromoteId === 2 && data.requiredPlayerLevel === 15);
this.replaceDatas.push(new ReplaceData((_d = Object.entries(sampleAvatarPromoteData).find(([, v]) => v === 1)) === null || _d === void 0 ? void 0 : _d[0], 'promoteLevel'));
this.replaceDatas.push(new ReplaceData((_e = Object.entries(sampleAvatarPromoteData).find(([, v]) => v === 40)) === null || _e === void 0 ? void 0 : _e[0], 'unlockMaxLevel'));
}
}
/**
* Execute JsonParser key decoder
* @param jsonData JsonParser
* @param filename ExcelBinOutput Filename
* @returns Objects to cache
*/
execute(jsonData, filename) {
this.decode(jsonData);
return this.setKey(jsonData, filename);
}
/**
* Decode JsonParser key
* @param jsonData JsonParser
* @returns Decoded JsonParser
*/
decode(jsonData) {
const jsonArray = jsonData.get();
jsonArray.forEach((v) => {
const obj = v;
this.replaceDatas.forEach((replaceData) => {
if (obj[replaceData.oldKey] !== undefined)
obj[replaceData.newKey] = obj[replaceData.oldKey];
});
});
return jsonData;
}
/**
* Set key to store in cache
* @param jsonData JsonParser
* @param filename ExcelBinOutput Filename
* @returns Objects to cache
*/
setKey(jsonData, filename) {
const jsonArray = jsonData.get();
const cacheObject = {};
// eslint-disable-next-line complexity
jsonArray.forEach((json) => {
var _a;
const obj = json;
switch (filename) {
case 'ManualTextMapConfigData':
cacheObject[obj.textMapId] = Object.assign(obj, {
textMapContentTextMapHash: ((_a = obj.textMapContent) !== null && _a !== void 0 ? _a : obj.textMapContentTextMapHash),
});
break;
case 'WeaponCurveExcelConfigData':
;
obj.curveInfos.forEach((curve) => {
const level = obj.level;
const value = curve.value;
const type = curve.type;
if (!cacheObject[type])
cacheObject[type] = {};
cacheObject[type][level] = value;
});
break;
case 'WeaponPromoteExcelConfigData':
if (!cacheObject[obj.weaponPromoteId])
cacheObject[obj.weaponPromoteId] = {};
cacheObject[obj.weaponPromoteId][(!obj.promoteLevel ? 0 : obj.promoteLevel)] = obj;
break;
case 'ReliquaryLevelExcelConfigData':
;
obj.addProps.forEach((prop) => {
if (!obj.rank)
return;
const rank = obj.rank;
const level = obj.level - 1;
const value = prop.value;
const type = prop.propType;
if (!cacheObject[type])
cacheObject[type] = {};
let cache = cacheObject[type];
if (!cache[rank])
cache[rank] = {};
cache = cache[rank];
cache[level] = value;
});
break;
case 'ReliquarySetExcelConfigData':
cacheObject[obj.setId] = obj;
break;
case 'AvatarExcelConfigData':
if (obj.id > 11000000 || obj.id === 10000001)
break;
cacheObject[obj.id] = obj;
break;
case 'AvatarCostumeExcelConfigData':
cacheObject[obj.skinId] = obj;
break;
case 'AvatarTalentExcelConfigData':
cacheObject[obj.talentId] = obj;
break;
case 'AvatarCurveExcelConfigData':
;
obj.curveInfos.forEach((curve) => {
var _a;
const level = obj.level;
const value = (_a = curve.value) !== null && _a !== void 0 ? _a : 0;
const type = curve.type;
if (!cacheObject[type])
cacheObject[type] = {};
cacheObject[type][level] = value;
});
break;
case 'AvatarPromoteExcelConfigData':
if (!cacheObject[obj.avatarPromoteId])
cacheObject[obj.avatarPromoteId] = {};
cacheObject[obj.avatarPromoteId][(!obj.promoteLevel ? 0 : obj.promoteLevel)] = obj;
break;
case 'ProudSkillExcelConfigData':
if (!cacheObject[obj.proudSkillGroupId])
cacheObject[obj.proudSkillGroupId] = {};
cacheObject[obj.proudSkillGroupId][obj.proudSkillId % 100] = obj;
break;
case 'FetterInfoExcelConfigData':
cacheObject[obj.avatarId] = obj;
break;
case 'EquipAffixExcelConfigData':
cacheObject[obj.affixId] = obj;
break;
case 'TowerScheduleExcelConfigData':
cacheObject[obj.scheduleId] = obj;
break;
case 'TowerFloorExcelConfigData':
cacheObject[obj.floorId] = obj;
break;
case 'TowerLevelExcelConfigData':
cacheObject[obj.levelId] = obj;
break;
case 'DungeonLevelEntityConfigData':
if (obj.show !== true)
break; //Because the same id exists. Added as a temporary workaround
cacheObject[obj.clientId] = obj;
break;
case 'MonsterExcelConfigData':
cacheObject[obj.id] = obj;
break;
case 'MonsterDescribeExcelConfigData':
cacheObject[obj.id] = obj;
break;
case 'AnimalCodexExcelConfigData':
cacheObject[obj.describeId] = obj;
break;
case 'MonsterCurveExcelConfigData':
;
obj.curveInfos.forEach((curve) => {
var _a;
const level = obj.level;
const value = (_a = curve.value) !== null && _a !== void 0 ? _a : 0;
const type = curve.type;
if (!cacheObject[type])
cacheObject[type] = {};
cacheObject[type][level] = value;
});
break;
case 'FetterStoryExcelConfigData':
cacheObject[obj.fetterId] = obj;
break;
case 'DungeonEntryExcelConfigData':
cacheObject[obj.id] = obj;
break;
case 'FettersExcelConfigData':
cacheObject[obj.fetterId] = obj;
break;
default:
cacheObject[obj.id] = obj;
break;
}
});
return cacheObject;
}
}
exports.ObjectKeyDecoder = ObjectKeyDecoder;