增加转格式
This commit is contained in:
@ -1,40 +1,49 @@
|
||||
import color from "picocolors";
|
||||
import { checkToktx, scanImages, compressAll } from "./compressor.js";
|
||||
import { runInteractive, showSummary } from "./ui.js";
|
||||
import { runGltfExtension } from "./gltf.js";
|
||||
import { stopKeypress, waitForKey } from "../keyboard.js";
|
||||
|
||||
export async function run() {
|
||||
// 检查 toktx
|
||||
checkToktx();
|
||||
|
||||
// 运行交互界面
|
||||
const result = await runInteractive();
|
||||
|
||||
// ESC 返回主菜单
|
||||
if (!result) return "back";
|
||||
|
||||
const [exts, quality, encoding, mipmap, outputOpts] = result;
|
||||
stopKeypress();
|
||||
|
||||
const { results } = result;
|
||||
const [exts, quality, encoding, mipmap, outputOpts] = results;
|
||||
const config = { exts, quality, encoding, mipmap, outputOpts };
|
||||
showSummary([
|
||||
"文件格式: " + config.exts.join(", "),
|
||||
"压缩程度: " + config.quality,
|
||||
"编码格式: " + config.encoding,
|
||||
"Mipmap: " + config.mipmap,
|
||||
"输出选项: " + config.outputOpts.join(", ")
|
||||
]);
|
||||
|
||||
// 显示配置摘要
|
||||
showSummary(config);
|
||||
|
||||
// 扫描文件
|
||||
const { images, cwd } = scanImages(exts);
|
||||
|
||||
if (images.length === 0) {
|
||||
console.log(color.yellow("当前目录没有匹配的图片"));
|
||||
return;
|
||||
await waitForKey();
|
||||
return "back";
|
||||
}
|
||||
|
||||
console.log(`📁 找到 ${color.cyan(images.length)} 个待转换文件\n`);
|
||||
|
||||
// 执行压缩
|
||||
console.log("📁 找到 " + color.cyan(images.length) + " 个待转换文件\n");
|
||||
const { total, failed } = await compressAll(images, config, cwd);
|
||||
|
||||
// 显示结果
|
||||
if (failed > 0) {
|
||||
console.log(color.yellow(`\n⚠️ 完成,但有 ${failed} 个文件失败`));
|
||||
console.log(color.yellow("\n⚠️ 完成,但有 " + failed + " 个文件失败"));
|
||||
} else {
|
||||
console.log(color.green("\n🎉 全部文件压缩完成!"));
|
||||
}
|
||||
|
||||
if (outputOpts.includes("gltfExtension")) {
|
||||
console.log(color.cyan("\n正在修改 glTF 文件..."));
|
||||
const { success, count } = runGltfExtension();
|
||||
if (success) console.log(color.green("✓ 已修改 " + count + " 个 glTF 文件"));
|
||||
}
|
||||
|
||||
await waitForKey();
|
||||
return "back";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user