2
0
mirror of https://github.com/ddaodan/bgi-scripts.git synced 2025-11-03 06:14:13 +08:00

Add files via upload

This commit is contained in:
ddaodan
2025-09-15 19:19:12 +08:00
committed by GitHub
parent 24119920fb
commit e1ed012991
10 changed files with 2117 additions and 0 deletions

40
build/icon/1.filter.js Normal file
View File

@@ -0,0 +1,40 @@
// 这个脚本每次原神更新使用一次
const fs = require('fs');
const path = require('path');
// 读取JSON文件
const jsonPath = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\Material.json';
const jsonData = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
// 设置源文件夹和目标文件夹
const sourceDir = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\ItemIcon-tiny';
const targetDir = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\newPng';
// 确保目标文件夹存在
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
// 读取源文件夹中的所有文件
fs.readdirSync(sourceDir).forEach(file => {
const fileName = path.parse(file).name; // 获取文件名(不含扩展名)
// 查找所有匹配项
const matchedItems = jsonData.filter(item => item.Icon === fileName);
if (matchedItems.length > 0) {
const sourcePath = path.join(sourceDir, file);
// 为每个匹配项创建文件
matchedItems.forEach(matchedItem => {
const targetPath = path.join(targetDir, `${matchedItem.Name}.png`);
// 复制并重命名文件
fs.copyFileSync(sourcePath, targetPath);
console.log(`已复制并重命名: ${file} -> ${matchedItem.Name}.png`);
});
}
});
console.log('处理完成');

45
build/icon/2.match.js Normal file
View File

@@ -0,0 +1,45 @@
// 这个脚本,有新的脚本目录就要使用
const fs = require('fs');
const path = require('path');
// 定义路径
const pathingDir = 'D:\\HuiPrograming\\Projects\\CSharp\\MiHoYo\\bettergi-scripts-list\\repo\\pathing';
const pngDir = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\newPng';
const outputDir = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\matchedPng';
// 确保输出目录存在
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
// 读取 pathing 目录下的所有文件夹名称
fs.readdir(pathingDir, { withFileTypes: true }, (err, entries) => {
if (err) {
console.error('读取 pathing 目录时出错:', err);
return;
}
// 过滤出目录
const directories = entries.filter(entry => entry.isDirectory()).map(dir => dir.name);
// 遍历目录名称
directories.forEach(dirName => {
const pngPath = path.join(pngDir, `${dirName}.png`);
const outputPath = path.join(outputDir, `${dirName}.png`);
// 检查对应的 PNG 文件是否存在
if (fs.existsSync(pngPath)) {
// 复制文件
fs.copyFile(pngPath, outputPath, err => {
if (err) {
console.error(`复制 ${dirName}.png 时出错:`, err);
} else {
console.log(`成功复制 ${dirName}.png 到 matchedPng 文件夹`);
}
});
} else {
console.log(`未找到对应的 PNG 文件: ${dirName}.png`);
}
});
});

59
build/icon/3.icon.js Normal file
View File

@@ -0,0 +1,59 @@
// 用于给每个脚本目录添加icon
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
// 定义路径
const sourcePath = 'D:\\HuiPrograming\\Projects\\CSharp\\MiHoYo\\bettergi-scripts-list\\repo\\pathing';
const iconSourcePath = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\matchedIco';
const desktopIniPath = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\desktop.ini';
// 读取源目录
fs.readdir(sourcePath, { withFileTypes: true }, (err, entries) => {
if (err) {
console.error('读取源目录时出错:', err);
return;
}
// 遍历每个目录
entries.filter(entry => entry.isDirectory()).forEach(dir => {
const dirPath = path.join(sourcePath, dir.name);
const iconSourceFile = path.join(iconSourcePath, `${dir.name}.ico`);
const iconDestFile = path.join(dirPath, 'icon.ico');
const desktopIniDestFile = path.join(dirPath, 'desktop.ini');
// 检查图标源文件是否存在
if (!fs.existsSync(iconSourceFile)) {
console.log(`警告:${dir.name} 的图标文件不存在,跳过所有操作`);
return; // 跳过当前目录的所有后续操作
}
// 复制图标文件
fs.copyFile(iconSourceFile, iconDestFile, (err) => {
if (err) {
console.error(`复制图标文件到 ${dir.name} 时出错:`, err);
return; // 如果复制图标失败,跳过后续操作
}
console.log(`成功复制图标文件到 ${dir.name}`);
// 复制desktop.ini文件
fs.copyFile(desktopIniPath, desktopIniDestFile, (err) => {
if (err) {
console.error(`复制desktop.ini到 ${dir.name} 时出错:`, err);
return; // 如果复制desktop.ini失败跳过后续操作
}
console.log(`成功复制desktop.ini到 ${dir.name}`);
// 执行cmd命令
exec(`attrib +R "${dirPath}"`, (err, stdout, stderr) => {
if (err) {
console.error(`执行attrib命令时出错 ${dir.name}:`, err);
return;
}
console.log(`成功为 ${dir.name} 设置只读属性`);
});
});
});
});
});

View File

@@ -0,0 +1,38 @@
// 只找新的png文件然后复制到diffPng目录
const fs = require('fs');
const path = require('path');
// 定义路径
const pngDir = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\matchedPng';
const iconDir = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\matchedIco';
// 定义输出目录
const outputDir = 'E:\\HuiTask\\更好的原神\\2.资料\\图标处理\\diffPng';
// 确保输出目录存在
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// 获取两个目录中的文件列表并去除扩展名
const getPureFilenames = (dir) => {
return fs.readdirSync(dir).map(file => path.parse(file).name);
};
const pngFiles = getPureFilenames(pngDir);
const icoFiles = getPureFilenames(iconDir);
// 找出在PNG目录存在但在ICO目录不存在的文件
const unmatchedPng = pngFiles.filter(name => !icoFiles.includes(name));
// 复制不匹配的PNG文件到输出目录
unmatchedPng.forEach(filename => {
const sourcePath = path.join(pngDir, `${filename}.png`);
const destPath = path.join(outputDir, `${filename}.png`);
fs.copyFileSync(sourcePath, destPath);
});
console.log(`找到并复制了 ${unmatchedPng.length} 个不匹配的 PNG 文件到: ${outputDir}`);
// 然后去 https://offlineconverter.com/ 转换为ico