fix: 1.1内容

This commit is contained in:
bietiaop 2024-08-15 18:06:35 +08:00
parent 267a790cbc
commit 4a54442fae
6 changed files with 226 additions and 220 deletions

View file

@ -1,6 +1,11 @@
import path from 'path';
import fs from 'fs';
import { ZZZ_SQUARE_AVATAR, ZZZ_SQUARE_BANGBOO } from './mysapi/api.js';
import {
ZZZ_SQUARE_AVATAR,
ZZZ_SQUARE_BANGBOO,
NEW_ZZZ_SQUARE_BANGBOO,
NEW_ZZZ_SQUARE_AVATAR,
} from './mysapi/api.js';
import { imageResourcesPath } from './path.js';
import { char, equip, weapon } from './convert.js';
import { getResourceRemotePath } from './assets.js';
@ -46,6 +51,23 @@ export const downloadFile = async (url, savePath) => {
}
};
/**
* 查看文件是否存在如果存在则返回路径否则下载文件
* @param {string} url 下载地址
* @param {string} savePath 保存路径
* @returns {Promise<string | null>} 保存路径
*/
export const checkFile = async (url, savePath) => {
if (fs.existsSync(savePath)) {
const stats = fs.statSync(savePath);
if (stats.size > 0) {
return savePath;
}
}
const download = await downloadFile(url, savePath);
return download;
};
/**
* 获取角色头像方形
* @param {string | number} charID
@ -54,16 +76,13 @@ export const downloadFile = async (url, savePath) => {
export const getSquareAvatar = async charID => {
const filename = `role_square_avatar_${charID}.png`;
const avatarPath = path.join(ZZZ_SQUARE_AVATAR_PATH, filename);
if (fs.existsSync(avatarPath)) {
const stats = fs.statSync(avatarPath);
if (stats.size > 0) {
return avatarPath;
}
let url = `${ZZZ_SQUARE_AVATAR}/${filename}`;
let result = await checkFile(url, avatarPath);
if (!result) {
url = `${NEW_ZZZ_SQUARE_AVATAR}/${filename}`;
result = await checkFile(url, avatarPath);
}
const url = `${ZZZ_SQUARE_AVATAR}/${filename}`;
const savePath = avatarPath;
const download = await downloadFile(url, savePath);
return download;
return result;
};
/**
@ -77,16 +96,9 @@ export const getSmallSquareAvatar = async charID => {
if (!sprite) return null;
const filename = `IconRoleGeneral${sprite}.png`;
const avatarPath = path.join(ZZZ_SMALL_SQUARE_AVATAR_PATH, filename);
if (fs.existsSync(avatarPath)) {
const stats = fs.statSync(avatarPath);
if (stats.size > 0) {
return avatarPath;
}
}
const url = await getResourceRemotePath('role_general', filename);
const savePath = avatarPath;
const download = await downloadFile(url, savePath);
return download;
const result = await checkFile(url, avatarPath);
return result;
};
/**
@ -97,16 +109,13 @@ export const getSmallSquareAvatar = async charID => {
export const getSquareBangboo = async bangbooId => {
const filename = `bangboo_rectangle_avatar_${bangbooId}.png`;
const bangbooPath = path.join(ZZZ_SQUARE_BANGBOO_PATH, filename);
if (fs.existsSync(bangbooPath)) {
const stats = fs.statSync(bangbooPath);
if (stats.size > 0) {
return bangbooPath;
}
let url = `${ZZZ_SQUARE_BANGBOO}/${filename}`;
let result = await checkFile(url, bangbooPath);
if (!result) {
url = `${NEW_ZZZ_SQUARE_BANGBOO}/${filename}`;
result = await checkFile(url, bangbooPath);
}
const url = `${ZZZ_SQUARE_BANGBOO}/${filename}`;
const savePath = bangbooPath;
const download = await downloadFile(url, savePath);
return download;
return result;
};
/**
@ -116,18 +125,17 @@ export const getSquareBangboo = async bangbooId => {
*/
export const getWeaponImage = async id => {
const name = weapon.IDToWeaponFileName(id);
const filename = `${name}.png`;
let filename = `${name}_High.png`;
const weaponPath = path.join(ZZZ_WEAPON_PATH, filename);
if (fs.existsSync(weaponPath)) {
const stats = fs.statSync(weaponPath);
if (stats.size > 0) {
return weaponPath;
}
}
const url = await getResourceRemotePath('weapon', filename);
const savePath = weaponPath;
const download = await downloadFile(url, savePath);
return download;
let result = await checkFile(url, weaponPath);
if (!result) {
filename = `${name}.png`;
const weaponPath = path.join(ZZZ_WEAPON_PATH, filename);
const url = await getResourceRemotePath('weapon', filename);
result = await checkFile(url, weaponPath);
}
return result;
};
/**
@ -140,16 +148,9 @@ export const getRoleImage = async id => {
if (!sprite) return null;
const filename = `IconRole${sprite}.png`;
const rolePath = path.join(ZZZ_ROLE_PATH, filename);
if (fs.existsSync(rolePath)) {
const stats = fs.statSync(rolePath);
if (stats.size > 0) {
return rolePath;
}
}
const url = await getResourceRemotePath('role', filename);
const savePath = rolePath;
const download = await downloadFile(url, savePath);
return download;
const result = await checkFile(url, rolePath);
return result;
};
/**
@ -162,16 +163,9 @@ export const getRoleCircleImage = async id => {
if (!sprite) return null;
const filename = `IconRoleCircle${sprite}.png`;
const roleCirclePath = path.join(ZZZ_ROLE_CIRCLE_PATH, filename);
if (fs.existsSync(roleCirclePath)) {
const stats = fs.statSync(roleCirclePath);
if (stats.size > 0) {
return roleCirclePath;
}
}
const url = await getResourceRemotePath('role_circle', filename);
const savePath = roleCirclePath;
const download = await downloadFile(url, savePath);
return download;
const result = await checkFile(url, roleCirclePath);
return result;
};
/**
@ -183,16 +177,9 @@ 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)) {
const stats = fs.statSync(suitPath);
if (stats.size > 0) {
return suitPath;
}
}
const url = await getResourceRemotePath('suit', filename);
const savePath = suitPath;
const download = await downloadFile(url, savePath);
return download;
const result = await checkFile(url, suitPath);
return result;
};
/**
@ -204,14 +191,7 @@ 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)) {
const stats = fs.statSync(suitPath);
if (stats.size > 0) {
return suitPath;
}
}
const url = await getResourceRemotePath('suit_3d', filename);
const savePath = suitPath;
const download = await downloadFile(url, savePath);
return download;
const result = await checkFile(url, suitPath);
return result;
};