feat: panel

This commit is contained in:
bietiaop 2024-07-13 17:52:31 +08:00
parent 35c8c95b80
commit 27171c5727
77 changed files with 2126 additions and 312 deletions

View file

@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs';
import { ZZZ_SQUARE_AVATAR, ZZZ_SQUARE_BANGBOO } from './mysapi/api.js';
import { imageResourcesPath } from './path.js';
import { weapon } from './convert.js';
import { char, equip, weapon } from './convert.js';
import { getResourceRemotePath } from './assets.js';
const ZZZ_SQUARE_AVATAR_PATH = path.join(imageResourcesPath, 'square_avatar');
@ -11,9 +11,18 @@ const ZZZ_SQUARE_BANGBOO_PATH = path.join(
'bangboo_square_avatar'
);
const ZZZ_WEAPON_PATH = path.join(imageResourcesPath, 'weapon');
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides');
const ZZZ_ROLE_PATH = path.join(imageResourcesPath, 'role');
const ZZZ_ROLE_CIRCLE_PATH = path.join(imageResourcesPath, 'role_circle');
const ZZZ_SUIT_3D_PATH = path.join(imageResourcesPath, 'suit_3d');
const ZZZ_SUIT_PATH = path.join(imageResourcesPath, 'suit');
// const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides');
// 将下面的下载封装起来支持错误重试5次
/**
* 下载文件
* @param {string} url 下载地址
* @param {string} savePath 保存路径
* @returns
*/
const downloadFile = async (url, savePath) => {
const _download = async (url, savePath, retry = 0) => {
if (retry > 5) {
@ -36,7 +45,7 @@ const downloadFile = async (url, savePath) => {
};
/**
*
* 获取角色头像方形
* @param {string | number} charID
* @returns Promise<string>
*/
@ -51,7 +60,7 @@ export const getSquareAvatar = async charID => {
};
/**
*
* 获取邦布头像方形
* @param {string | number} bangbooId
* @returns Promise<string>
*/
@ -66,7 +75,7 @@ export const getSquareBangboo = async bangbooId => {
};
/**
* Get weapon image path
* 获取武器图片
* @param {string} id
* @returns Promise<string>
*/
@ -80,6 +89,72 @@ export const getWeaponImage = async id => {
const url = await getResourceRemotePath('weapon', filename);
const savePath = weaponPath;
const download = await downloadFile(url, savePath);
logger.mark('getWeaponImage', download);
logger.debug('getWeaponImage', download);
return download;
};
/**
* 获取角色图片
* @param {string | number} id
* @returns Promise<string>
*/
export const getRoleImage = async id => {
const sprite = char.IDToCharSprite(id);
if (sprite === null) return null;
const filename = `IconRole${sprite}.png`;
const rolePath = path.join(ZZZ_ROLE_PATH, filename);
if (fs.existsSync(rolePath)) return rolePath;
const url = await getResourceRemotePath('role', filename);
const savePath = rolePath;
const download = await downloadFile(url, savePath);
return download;
};
/**
* 获取角色圆形图片
* @param {string | number} id
* @returns Promise<string>
*/
export const getRoleCircleImage = async id => {
const sprite = char.IDToCharSprite(id);
if (sprite === null) return null;
const filename = `IconRoleCircle${sprite}.png`;
const roleCirclePath = path.join(ZZZ_ROLE_CIRCLE_PATH, filename);
if (fs.existsSync(roleCirclePath)) return roleCirclePath;
const url = await getResourceRemotePath('role_circle', filename);
const savePath = roleCirclePath;
const download = await downloadFile(url, savePath);
return download;
};
/**
* 获取套装图片
* @param {string | number} suitId
* @returns Promise<string>
*/
export const getSuitImage = async suitId => {
const suitName = equip.equipIdToSprite(suitId);
const filename = `${suitName}.png`;
const suitPath = path.join(ZZZ_SUIT_PATH, filename);
if (fs.existsSync(suitPath)) return suitPath;
const url = await getResourceRemotePath('suit', filename);
const savePath = suitPath;
const download = await downloadFile(url, savePath);
return download;
};
/**
* 获取3D套装图片
* @param {string | number} suitId
* @returns Promise<string>
*/
export const getSuit3DImage = async suitId => {
const suitName = equip.equipIdToSprite(suitId);
const filename = `${suitName}_3d.png`;
const suitPath = path.join(ZZZ_SUIT_3D_PATH, filename);
if (fs.existsSync(suitPath)) return suitPath;
const url = await getResourceRemotePath('suit_3d', filename);
const savePath = suitPath;
const download = await downloadFile(url, savePath);
return download;
};