starrail-manager
Version:
The StarRail Manager is a Node.js wrapper for the MiHoMo API and StarRail Data used in Honkai: StarRail.\ **This is not an official Honkai: StarRail project.**
97 lines • 3.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseChar = parseChar;
const config_1 = require("../config");
function parseChar(data, index) {
var _a, _b, _c, _d;
if (!data || !data.characters || !data.characters[index])
return null;
const char = data.characters[index];
const skill = char.skills.slice(0, 4).map((s) => ({
level: s.level,
icon: config_1.config.StarRailPath + s.icon,
}));
const rank_icons = Array.from({ length: 6 }, (_, i) => ({
icon: config_1.config.StarRailPath + char.rank_icons[i],
lock: i >= char.rank ? true : false,
}));
const light_cone = char.light_cone
? {
name: char.light_cone.name,
rarity: char.light_cone.rarity,
rank: char.light_cone.rank,
icon: config_1.config.StarRailPath + char.light_cone.preview,
level: char.light_cone.level,
attributes: char.light_cone.attributes.map((a) => ({
name: cleanAffixName(a.name),
icon: config_1.config.StarRailPath + a.icon,
val: a.display,
})),
}
: undefined;
const relics = (_b = (_a = char.relics) === null || _a === void 0 ? void 0 : _a.map((r) => ({
name: r.name,
rarity: r.rarity,
level: r.level,
icon: config_1.config.StarRailPath + r.icon,
score: 0,
part: r.type,
main_affix: {
type: r.main_affix.type,
name: cleanAffixName(r.main_affix.name),
icon: config_1.config.StarRailPath + r.main_affix.icon,
val: r.main_affix.value,
dis: r.main_affix.display,
},
sub_affix: r.sub_affix.map((s) => ({
type: s.type,
name: cleanAffixName(s.name),
icon: config_1.config.StarRailPath + s.icon,
val: s.value,
dis: s.display,
})),
}))) !== null && _b !== void 0 ? _b : [];
const relic_sets = (_d = (_c = char.relic_sets) === null || _c === void 0 ? void 0 : _c.map((rs) => ({
name: rs.name,
icon: config_1.config.StarRailPath + rs.icon,
num: rs.num,
}))) !== null && _d !== void 0 ? _d : [];
const status = char.additions.map((add) => {
let val = add.display;
const match = char.attributes.find((attr) => attr.name === add.name);
if (match) {
val = add.percent ? ((add.value + match.value) * 100).toFixed(1) + "%" : (add.value + match.value).toFixed(0);
}
return {
name: cleanAffixName(add.name),
icon: config_1.config.StarRailPath + add.icon,
val,
};
});
const orderedNames = ["HP", "攻撃力", "防御力", "速度", "会心率", "会心ダメ", "撃破特効", "EP回復効率", "効果命中", "効果抵抗", "治癒量", "属性ダメ"];
status.sort((a, b) => orderedNames.indexOf(a.name) - orderedNames.indexOf(b.name));
return {
uid: data.player.uid,
id: char.id,
name: char.name,
level: char.level,
icon: config_1.config.StarRailPath + char.portrait,
total_score: 0,
skill,
rank_icons,
path: config_1.config.StarRailPath + char.path.icon,
element: config_1.config.StarRailPath + char.element.icon,
light_cone,
relics,
relic_sets,
status,
};
}
function cleanAffixName(name) {
return name
.replace(/..?属性ダメージ/, "属性ダメ")
.replace("会心ダメージ", "会心ダメ")
.replace("EP回復効率", "EP回復")
.replace("基礎", "");
}
//# sourceMappingURL=JsonParser.js.map