12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import { config } from "./main";
- import { $typeof } from "puerts";
- import FairyEditor = CS.FairyEditor;
- import FileUtils from "./FileUtils";
- const App = FairyEditor.App;
- export default class PsdToFgui {
- public start() {
- let pluginPath = FairyEditor.App.pluginManager.basePath;
- let filterExtensions: string[] = ["psd"];
- let filter = new CS.SFB.ExtensionFilter("psd",...filterExtensions);
- // let filters: CS.SFB.ExtensionFilter[] = [filter];
- let filters = CS.System.Array.CreateInstance($typeof(CS.SFB.ExtensionFilter), 1) as CS.System.Array$1<CS.SFB.ExtensionFilter>;
- filters.set_Item(0, filter);
-
- FairyEditor.IOUtil.BrowseForOpen("选择psd文件", pluginPath, filters, this.onSelectedPsd);
- }
- private async onSelectedPsd(psdPath: string) {
- if (!psdPath) {
- App.consoleView.Log(`没有选择psd文件.`);
- return;
- }
- let psd2fguiPluginsPath = config.psd2fguiPluginsPath;
- if (!CS.System.IO.Directory.Exists(psd2fguiPluginsPath)) {
- psd2fguiPluginsPath = FairyEditor.App.project.basePath + "/psd2fgui";
- if (!CS.System.IO.Directory.Exists(psd2fguiPluginsPath)) {
- App.consoleView.LogWarning(`需要先配置psd2fgui插件. 路径:${psd2fguiPluginsPath}`);
- return;
- }
- }
- App.consoleView.Log(`psd2fgui插件路径:${psd2fguiPluginsPath} psdPath:${psdPath}`);
- let pkgPath = psdPath.replace(".psd", ".fairypackage");
- // let pkgFolder = psdPath.replace(".psd", "-fairypackage");
- // --nopack
- let result = FairyEditor.ProcessUtil.Start(`node convert ${psdPath} --ignore-font`, null, psd2fguiPluginsPath, false);
- if (!result) {
- while(!CS.System.IO.File.Exists(pkgPath)) {
- FairyEditor.App.consoleView.Log(`psd2fgui sleep wait for ${pkgPath}`);
- await FileUtils.sleep(1000)
- }
- App.consoleView.Log(`psd2fgui completed. 使用菜单<资源->导入资源包> 可以导入该资源包`);
- // App.Alert(`psd2fgui completed. 使用菜单<资源->导入资源包> 可以导入该资源包`);
- }
- else {
- App.consoleView.LogError(`psd2fgui 失败. result:${result}`);
- }
- // App.consoleView.Log(`psdToFgui result:${result} exist:${CS.System.IO.File.Exists(pkgPath)}`);
- // let pkg = FairyEditor.App.project.CreatePackage(pkgPath);
- // App.consoleView.Log(`psdToFgui pkgName:${pkg?.name ?? "null"}`);
- // if (pkg) {
- // FairyEditor.App.libView.ShowImportResourcesDialog(pkg);
- // }
- }
- }
|