UNPKG

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.**

89 lines 3.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Character = void 0; const config_1 = require("../config"); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); const languages = ["cht", "cn", "de", "en", "es", "fr", "id", "jp", "kr", "pt", "ru", "th", "vi"]; /** * get character and weight data or set weight data */ class Character { constructor(options = {}) { var _a; this.lang = (_a = options.lang) !== null && _a !== void 0 ? _a : "en"; if (!languages.includes(this.lang)) { throw new Error(`The Language is not supported: ${options.lang}`); } } /** * get character base data from StarRailRes * @param name - character name or id * @returns character data in json */ getCharBase(name) { const charData = JSON.parse(fs_1.default.readFileSync(config_1.config.StarRailPath + `index_min/${this.lang}/characters.json`, "utf-8")); if (typeof name === "number") { return charData[name]; } else if (typeof name === "string") { for (const id in charData) { const char = charData[id]; if (char.name.includes(name)) { return char; } } } return null; } /** * get character weight data from StarRailScore * @param name - character name * @param num - weight number(default: 0) * @returns character weight data in json */ getCharWeight(name, num) { const charDataSelf = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(__dirname, config_1.config.customWightPath), "utf-8")); const charId = this.getCharBase(name).id; let length = 0; if (charDataSelf[charId] !== undefined) length = charDataSelf[charId].length; if (num == null) { return length + 1; } else if (num == 0) { const charData = JSON.parse(fs_1.default.readFileSync(config_1.config.scorePath + "score.json", "utf-8")); return charData[charId]; } else { if (charDataSelf[charId] === undefined) return `${this.getCharBase(name).name} の重要度データがありません。`; return charDataSelf[charId][num - 1]; } } /** * set custom character weight data * @param name - character name * @param data - weight data * @returns text message */ setCharWeight(name, data) { const charData = this.getCharBase(name); const charId = charData.id; const charName = charData.name; const charDataSelf = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(__dirname, config_1.config.customWightPath), "utf-8")); if (charDataSelf[charId]) { charDataSelf[charId].push(data); } else { charDataSelf[charId] = [data]; } fs_1.default.writeFileSync(path_1.default.resolve(__dirname, config_1.config.customWightPath), JSON.stringify(charDataSelf, null, 2), "utf-8"); return `${charName} の重要度データを作成しました。`; } } exports.Character = Character; //# sourceMappingURL=character.js.map