Files
yinx-cli/lib/plugins/ktx2/index.js
2025-12-22 15:01:10 +08:00

59 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import color from "picocolors";
import { createStepUI } from "../../utils/stepui.js";
import { title, getSteps } from "./config.js";
import { stopKeypress, waitForKey } from "../../keyboard.js";
import { checkToktx, scanImages, compressAll, runGltfExtension } from "./service.js";
const run = async () => {
checkToktx();
const ui = createStepUI({ title, getSteps });
const result = await ui.runInteractive();
if (!result) return "back";
stopKeypress();
const [exts, quality, encoding, mipmap, outputOpts] = result.results;
const config = { exts, quality, encoding, mipmap, outputOpts };
ui.showSummary([
"文件格式: " + config.exts.join(", "),
"压缩程度: " + config.quality,
"编码格式: " + config.encoding,
"Mipmap: " + config.mipmap,
"输出选项: " + config.outputOpts.join(", ")
]);
const { images, cwd } = scanImages(exts);
if (images.length === 0) {
console.log(color.yellow("当前目录没有匹配的图片"));
await waitForKey();
return "back";
}
console.log("📁 找到 " + color.cyan(images.length) + " 个待转换文件\n");
const { total, failed } = await compressAll(images, config, cwd);
if (failed > 0) {
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";
};
export default {
id: "ktx2",
name: "KTX2压缩",
desc: "纹理压缩为KTX2",
run,
};