同步插件修改

This commit is contained in:
onvia 2023-07-31 09:26:24 +08:00
parent 40ee90491e
commit 6e294f7a19
5 changed files with 195 additions and 172 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,169 +1,186 @@
"use strict"; "use strict";
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.unload = exports.load = exports.methods = void 0; exports.unload = exports.load = exports.methods = void 0;
//@ts-ignore //@ts-ignore
const package_json_1 = __importDefault(require("../package.json")); const package_json_1 = __importDefault(require("../package.json"));
const fs_extra_1 = __importDefault(require("fs-extra")); const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path")); const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os")); const os_1 = __importDefault(require("os"));
const child_process_1 = __importDefault(require("child_process")); const child_process_1 = __importDefault(require("child_process"));
let exec = child_process_1.default.exec; let exec = child_process_1.default.exec;
const ENGINE_VER = "v342"; // const ENGINE_VER = "v342"; //
const packagePath = path_1.default.join(Editor.Project.path, "extensions", package_json_1.default.name); const packagePath = path_1.default.join(Editor.Project.path, "extensions", package_json_1.default.name);
const projectAssets = path_1.default.join(Editor.Project.path, "assets"); const projectAssets = path_1.default.join(Editor.Project.path, "assets");
const cacheFile = path_1.default.join(Editor.Project.path, "local", "psd-to-prefab-cache.json"); const cacheFile = path_1.default.join(Editor.Project.path, "local", "psd-to-prefab-cache.json");
const configFile = path_1.default.join(`${packagePath}/config/psd.config.json`); const configFile = path_1.default.join(`${packagePath}/config/psd.config.json`);
const nodejsFile = path_1.default.join(packagePath, "bin", `node${os_1.default.platform() == 'darwin' ? "" : ".exe"}`); const nodejsFile = path_1.default.join(packagePath, "bin", `node${os_1.default.platform() == 'darwin' ? "" : ".exe"}`);
const psd = path_1.default.join(packagePath, "libs", "psd2ui", "index.js"); const commandFile = path_1.default.join(packagePath, "libs", "psd2ui", `command.${os_1.default.platform() == 'darwin' ? "sh" : "bat"}`);
let uuid2md5 = new Map(); const psd = path_1.default.join(packagePath, "libs", "psd2ui", "index.js");
let cacheFileJson = {}; let uuid2md5 = new Map();
/** let cacheFileJson = {};
* @en /**
* @zh 为扩展的主进程的注册方法 * @en
*/ * @zh 为扩展的主进程的注册方法
exports.methods = { */
openPanel() { exports.methods = {
Editor.Panel.open(package_json_1.default.name); openPanel() {
}, Editor.Panel.open(package_json_1.default.name);
onClickPsd2UICache() { },
console.log(`main-> onClickPsd2UICache111 `); onClickPsd2UICache() {
return new Promise((resolve, reject) => { console.log(`main-> onClickPsd2UICache111 `);
console.log(`main-> onClickPsd2UICache`); return new Promise((resolve, reject) => {
let options = { console.log(`main-> onClickPsd2UICache`);
"project-assets": projectAssets, let options = {
"cache": cacheFile, "project-assets": projectAssets,
"init": true, "cache": cacheFile,
"engine-version": ENGINE_VER "init": true,
}; "engine-version": ENGINE_VER
Promise.all(_exec(options, [])).then(() => { };
console.log("[psd2prefab] 执行缓存结束"); Promise.all(_exec(options, [])).then(() => {
resolve(); console.log("[psd2prefab] 执行缓存结束");
}); resolve();
}); });
}, });
async onPsd2UIDropFiles(param) { },
let files = param.files; async onPsd2UIDropFiles(param) {
let isForceImg = param.isForceImg; let files = param.files;
let isImgOnly = param.isImgOnly; let isForceImg = param.isForceImg;
let output = param.output; let isImgOnly = param.isImgOnly;
let isPinyin = param.isPinyin; let output = param.output;
let options = { let isPinyin = param.isPinyin;
"project-assets": projectAssets, let options = {
"cache": cacheFile, "project-assets": projectAssets,
"engine-version": ENGINE_VER, "cache": cacheFile,
"pinyin": isPinyin, "engine-version": ENGINE_VER,
}; "pinyin": isPinyin,
let tasks = []; };
for (let i = 0; i < files.length; i++) { let tasks = [];
const file = files[i]; for (let i = 0; i < files.length; i++) {
let stat = fs_extra_1.default.statSync(file); const file = files[i];
if (stat.isFile()) { let stat = fs_extra_1.default.statSync(file);
let ext = path_1.default.extname(file); if (stat.isFile()) {
if (ext != '.psd') { let ext = path_1.default.extname(file);
continue; if (ext != '.psd') {
} continue;
} }
let args = JSON.parse(JSON.stringify(options)); }
args["input"] = file; let args = JSON.parse(JSON.stringify(options));
if (output) { args["input"] = file;
args["output"] = output; if (output) {
} args["output"] = output;
if (isImgOnly) { }
// 只导出图片 if (isImgOnly) {
args["img-only"] = true; // 只导出图片
} args["img-only"] = true;
else { }
// 强制导出图片 else {
if (isForceImg) { // 强制导出图片
args["force-img"] = true; if (isForceImg) {
} args["force-img"] = true;
args["config"] = configFile; }
} args["config"] = configFile;
_exec(args, tasks); }
} _exec(args, tasks);
Promise.all(tasks).then(() => { }
genUUID2MD5Mapping(); Promise.all(tasks).then(() => {
console.log("[ccc-tnt-psd2ui] psd 导出完成,输出位置为:", output ? output : "psd 同级目录"); genUUID2MD5Mapping();
}).catch((reason) => { console.log("[ccc-tnt-psd2ui] psd 导出完成,输出位置为:", output ? output : "psd 同级目录");
console.log("[ccc-tnt-psd2ui] 导出失败", reason); }).catch((reason) => {
}).finally(() => { console.log("[ccc-tnt-psd2ui] 导出失败", reason);
}); }).finally(() => {
}, });
}; },
function _exec(options, tasks) { };
let jsonContent = JSON.stringify(options); function _exec(options, tasks) {
if (!fs_extra_1.default.existsSync(nodejsFile)) { let jsonContent = JSON.stringify(options);
console.log(`[ccc-tnt-psd2ui] 没有内置 nodejs`, nodejsFile); if (!fs_extra_1.default.existsSync(nodejsFile)) {
return tasks; console.log(`[ccc-tnt-psd2ui] 没有内置 nodejs`, nodejsFile);
} return tasks;
// 处理权限问题 }
if (os_1.default.platform() === 'darwin') { // 处理权限问题
if (fs_extra_1.default.statSync(nodejsFile).mode != 33261) { if (os_1.default.platform() === 'darwin') {
console.log(`[ccc-tnt-psd2ui] 设置权限`); if (fs_extra_1.default.statSync(nodejsFile).mode != 33261) {
fs_extra_1.default.chmodSync(nodejsFile, 33261); console.log(`[ccc-tnt-psd2ui] 设置权限`);
} fs_extra_1.default.chmodSync(nodejsFile, 33261);
} }
console.log("[ccc-tnt-psd2ui] 命令参数:" + jsonContent); if (fs_extra_1.default.statSync(commandFile).mode != 33261) {
console.log("[ccc-tnt-psd2ui] 命令执行中"); console.log(`[ccc-tnt-psd2ui] commandFile 设置权限`);
let base64 = Buffer.from(jsonContent).toString("base64"); fs_extra_1.default.chmodSync(commandFile, 33261);
tasks.push(new Promise((rs) => { }
// console.log(`[ccc-tnt-psd2ui] `, `${nodejsFile} ${psd}` + ' ' + `--json ${base64}`); }
exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => { console.log("[ccc-tnt-psd2ui] 命令参数:" + jsonContent);
console.log("[ccc-tnt-psd2ui]:\n", stdout); console.log("[ccc-tnt-psd2ui] 命令执行中");
if (stderr) { let base64 = Buffer.from(jsonContent).toString("base64");
console.log(stderr); tasks.push(new Promise((rs) => {
} // console.log(`[ccc-tnt-psd2ui] `, `${nodejsFile} ${psd}` + ' ' + `--json ${base64}`);
rs(); // exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
}); // console.log("[ccc-tnt-psd2ui]:\n", stdout);
})); // if (stderr) {
return tasks; // console.log(stderr);
} // }
/** // rs();
* 资源删除的监听 // })
* let shellScript = commandFile; // 你的脚本路径
* @param {*} event let scriptArgs = `--json ${base64}`; // 你的脚本参数
*/ let command = os_1.default.platform() == 'darwin' ? `osascript -e 'tell app "Terminal" to do script "cd ${process.cwd()}; ${shellScript} ${scriptArgs}"'`
function onAssetDeletedListener(event) { : `start ${commandFile} ${scriptArgs}`;
if (uuid2md5.has(event)) { exec(command, (error, stdout, stderr) => {
let md5 = uuid2md5.get(event); console.log("[ccc-tnt-psd2ui]:\n", stdout);
console.log(`[ccc-tnt-psd2ui] 删除资源 md5: ${md5}, uuid: ${event}`); console.log("[ccc-tnt-psd2ui]: 程序执行完后请手动关闭终端窗口");
delete cacheFileJson[`${md5}`]; if (stderr) {
fs_extra_1.default.writeFileSync(cacheFile, JSON.stringify(cacheFileJson, null, 2)); console.log(stderr);
} }
} rs();
/** });
* 生成 uuid MD5 的映射 }));
* return tasks;
*/ }
function genUUID2MD5Mapping() { /**
if (!fs_extra_1.default.existsSync(cacheFile)) { * 资源删除的监听
return; *
} * @param {*} event
let content = fs_extra_1.default.readFileSync(cacheFile, 'utf-8'); */
let obj = JSON.parse(content); function onAssetDeletedListener(event) {
cacheFileJson = obj; if (uuid2md5.has(event)) {
for (const key in obj) { let md5 = uuid2md5.get(event);
const element = obj[key]; console.log(`[ccc-tnt-psd2ui] 删除资源 md5: ${md5}, uuid: ${event}`);
uuid2md5.set(element.textureUuid, key); delete cacheFileJson[`${md5}`];
} fs_extra_1.default.writeFileSync(cacheFile, JSON.stringify(cacheFileJson, null, 2));
} }
/** }
* @en Hooks triggered after extension loading is complete /**
* @zh 扩展加载完成后触发的钩子 * 生成 uuid MD5 的映射
*/ *
const load = function () { */
genUUID2MD5Mapping(); function genUUID2MD5Mapping() {
Editor.Message.addBroadcastListener("asset-db:asset-delete", onAssetDeletedListener); if (!fs_extra_1.default.existsSync(cacheFile)) {
}; return;
exports.load = load; }
/** let content = fs_extra_1.default.readFileSync(cacheFile, 'utf-8');
* @en Hooks triggered after extension uninstallation is complete let obj = JSON.parse(content);
* @zh 扩展卸载完成后触发的钩子 cacheFileJson = obj;
*/ for (const key in obj) {
const unload = function () { const element = obj[key];
Editor.Message.removeBroadcastListener("asset-db:asset-delete", onAssetDeletedListener); uuid2md5.set(element.textureUuid, key);
}; }
exports.unload = unload; }
/**
* @en Hooks triggered after extension loading is complete
* @zh 扩展加载完成后触发的钩子
*/
const load = function () {
genUUID2MD5Mapping();
Editor.Message.addBroadcastListener("asset-db:asset-delete", onAssetDeletedListener);
};
exports.load = load;
/**
* @en Hooks triggered after extension uninstallation is complete
* @zh 扩展卸载完成后触发的钩子
*/
const unload = function () {
Editor.Message.removeBroadcastListener("asset-db:asset-delete", onAssetDeletedListener);
};
exports.unload = unload;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -245,6 +245,12 @@ export abstract class PsdLayer {
if (!text || !PsdLayer.isPinyin) { if (!text || !PsdLayer.isPinyin) {
return text; return text;
} }
let reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
if (!reg.test(text)) {
return text;
}
let names = pinyin(text, { let names = pinyin(text, {
toneType: "none", toneType: "none",
type: "array" type: "array"