mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
feat: 角色天赋图鉴(支持自定义等级)
This commit is contained in:
parent
4f02e6b2ce
commit
15b14eece4
23 changed files with 937 additions and 124 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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`;
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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
19
lib/hakush.js
Normal 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;
|
||||
};
|
||||
|
|
@ -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 路径
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue