feat: 角色天赋图鉴(支持自定义等级)

This commit is contained in:
bietiaop 2024-09-02 16:22:23 +08:00
parent 4f02e6b2ce
commit 15b14eece4
23 changed files with 937 additions and 124 deletions

View file

@ -9,7 +9,7 @@ const PartnerId2SpriteId = getMapData('PartnerId2Data');
* @param {string | number} id
* @param {boolean} full 显示全称
* @param {boolean} en 是否为英文
* @returns string | null
* @returns {string | null}
*/
export const IDToCharName = (id, full = true, en = false) => {
const data = PartnerId2SpriteId?.[id];
@ -22,7 +22,7 @@ export const IDToCharName = (id, full = true, en = false) => {
/**
*
* @param {string | number} id
* @returns string | null
* @returns {string | null}
*/
export const IDToCharSprite = id => {
const data = PartnerId2SpriteId?.[id];
@ -32,7 +32,7 @@ export const IDToCharSprite = id => {
/**
* @param {string} name
* @returns number | null
* @returns {number | null}
*/
export const charNameToID = name => {
for (const [id, data] of Object.entries(PartnerId2SpriteId)) {
@ -43,7 +43,7 @@ export const charNameToID = name => {
/**
* @param {string} name
* @returns string | null
* @returns {string | null}
*/
export const charNameToSprite = name => {
for (const [_id, data] of Object.entries(PartnerId2SpriteId)) {
@ -53,8 +53,8 @@ export const charNameToSprite = name => {
};
/**
* @param {string} alias
* @returns string | null
* @param {string} _alias
* @returns {string | null}
*/
export const aliasToName = _alias => {
const alias = settings.getConfig('alias');
@ -67,7 +67,7 @@ export const aliasToName = _alias => {
/**
* @param {string} _alias
* @returns string | null
* @returns {string | null}
*/
export const aliasToSprite = _alias => {
const name = aliasToName(_alias);
@ -76,7 +76,7 @@ export const aliasToSprite = _alias => {
/**
* @param {string} name
* @returns number | null
* @returns {number | null}
*/
export const aliasToID = name => {
const _name = aliasToName(name);
@ -86,7 +86,7 @@ export const aliasToID = name => {
/**
* 获取所有角色ID
* @returns string[]
* @returns {string[]}
*/
export const getAllCharactersID = () => {
return Object.keys(PartnerId2SpriteId);

View file

@ -135,7 +135,7 @@ export const getSuit3DImage = async suitId => {
/**
* 获取Hakush角色数据
* @param {string} charId
* @returns {Promise<string>}
* @returns {Promise<object | null>} 文件内容JSON
*/
export const getHakushCharacter = async charId => {
const filename = `${charId}.json`;

View file

@ -1,5 +1,5 @@
import path from 'path';
import { imageResourcesPath } from '../path.js';
import { imageResourcesPath, dataResourcesPath } from '../path.js';
export const ZZZ_SQUARE_AVATAR_PATH = path.join(
imageResourcesPath,
@ -18,7 +18,7 @@ export const ZZZ_SQUARE_AVATAR_PATH = path.join(
// const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides');
export const HAKUSH_CHARACTER_DATA_PATH = path.join(
imageResourcesPath,
dataResourcesPath,
'hakush/data/character'
),
HAKUSH_WEAPON_DATA_PATH = path.join(imageResourcesPath, 'hakush/data/weapon');
HAKUSH_WEAPON_DATA_PATH = path.join(dataResourcesPath, 'hakush/data/weapon');

View file

@ -1,4 +1,5 @@
import path from 'path';
import fs from 'fs';
import { checkFile } from './core.js';
import { getResourceRemotePath } from '../assets.js';
import * as MysURL from '../assets/mysurl.js';
@ -10,6 +11,7 @@ import * as LocalURI from './const.js';
* @param {keyof LocalURI} localBase 本地地址
* @param {string} filename 文件名
* @param {keyof MysURL} newBase 新远程地址
* @returns {Promise<string | null>} 保存路径
*/
export const downloadMysImage = async (
base,
@ -38,6 +40,7 @@ export const downloadMysImage = async (
* @param {keyof LocalURI} localBase 本地地址
* @param {string} filename 文件名
* @param {string} replaceFilename 替换文件名(如果资源不存在)
* @returns {Promise<string | null>} 保存路径
*/
export const downloadResourceImage = async (
remoteLabel,
@ -62,6 +65,7 @@ export const downloadResourceImage = async (
* @param {keyof HakushURL} base 远程地址
* @param {keyof LocalURI} localBase 本地地址
* @param {string} filename 文件名
* @returns {Promise<object | null>} 文件内容JSON
*/
export const downloadHakushFile = async (base, localBase, filename = '') => {
base = HakushURL[base];
@ -71,5 +75,17 @@ export const downloadHakushFile = async (base, localBase, filename = '') => {
if (filename) {
url += `/${filename}`;
}
return checkFile(url, finalPath);
const filepath = await checkFile(url, finalPath);
if (filepath) {
// 打开文件
const file = fs.openSync(filepath, 'r');
// 读取文件内容
const content = fs.readFileSync(file);
// 关闭文件
fs.closeSync(file);
// 返回文件内容
return JSON.parse(content.toString());
} else {
return null;
}
};

19
lib/hakush.js Normal file
View file

@ -0,0 +1,19 @@
import { Character } from '../model/hakush/character.js';
import * as convert from './convert.js';
import { getHakushCharacter } from './download.js';
export const getHakushCharacterData = async alias => {
const name = convert.char.aliasToName(alias);
const id = convert.char.charNameToID(name);
if (!id) return null;
const data = await getHakushCharacter(id);
if (!data) return null;
const result = new Character(data);
return result;
};
export const isSkillLevelLegal = (key, level) => {
if (key === 'CoreLevel') {
return !!level && level >= 0 && level <= 6;
}
return !!level && level >= 1 && level <= 12;
};

View file

@ -21,6 +21,8 @@ export const resourcesPath = path.join(pluginPath, 'resources');
export const imageResourcesPath = path.join(resourcesPath, 'images');
export const dataResourcesPath = path.join(resourcesPath, 'data');
export const mapResourcesPath = path.join(resourcesPath, 'map');
// config 路径