PsdToFgui.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const main_1 = require("./main");
  4. const puerts_1 = require("puerts");
  5. var FairyEditor = CS.FairyEditor;
  6. const FileUtils_1 = require("./FileUtils");
  7. const App = FairyEditor.App;
  8. class PsdToFgui {
  9. start() {
  10. let pluginPath = FairyEditor.App.pluginManager.basePath;
  11. let filterExtensions = ["psd"];
  12. let filter = new CS.SFB.ExtensionFilter("psd", ...filterExtensions);
  13. // let filters: CS.SFB.ExtensionFilter[] = [filter];
  14. let filters = CS.System.Array.CreateInstance((0, puerts_1.$typeof)(CS.SFB.ExtensionFilter), 1);
  15. filters.set_Item(0, filter);
  16. FairyEditor.IOUtil.BrowseForOpen("选择psd文件", pluginPath, filters, this.onSelectedPsd);
  17. }
  18. async onSelectedPsd(psdPath) {
  19. if (!psdPath) {
  20. App.consoleView.Log(`没有选择psd文件.`);
  21. return;
  22. }
  23. let psd2fguiPluginsPath = main_1.config.psd2fguiPluginsPath;
  24. if (!CS.System.IO.Directory.Exists(psd2fguiPluginsPath)) {
  25. psd2fguiPluginsPath = FairyEditor.App.project.basePath + "/psd2fgui";
  26. if (!CS.System.IO.Directory.Exists(psd2fguiPluginsPath)) {
  27. App.consoleView.LogWarning(`需要先配置psd2fgui插件. 路径:${psd2fguiPluginsPath}`);
  28. return;
  29. }
  30. }
  31. App.consoleView.Log(`psd2fgui插件路径:${psd2fguiPluginsPath} psdPath:${psdPath}`);
  32. let pkgPath = psdPath.replace(".psd", ".fairypackage");
  33. // let pkgFolder = psdPath.replace(".psd", "-fairypackage");
  34. // --nopack
  35. let result = FairyEditor.ProcessUtil.Start(`node convert ${psdPath} --ignore-font`, null, psd2fguiPluginsPath, false);
  36. if (!result) {
  37. while (!CS.System.IO.File.Exists(pkgPath)) {
  38. FairyEditor.App.consoleView.Log(`psd2fgui sleep wait for ${pkgPath}`);
  39. await FileUtils_1.default.sleep(1000);
  40. }
  41. App.consoleView.Log(`psd2fgui completed. 使用菜单<资源->导入资源包> 可以导入该资源包`);
  42. // App.Alert(`psd2fgui completed. 使用菜单<资源->导入资源包> 可以导入该资源包`);
  43. }
  44. else {
  45. App.consoleView.LogError(`psd2fgui 失败. result:${result}`);
  46. }
  47. // App.consoleView.Log(`psdToFgui result:${result} exist:${CS.System.IO.File.Exists(pkgPath)}`);
  48. // let pkg = FairyEditor.App.project.CreatePackage(pkgPath);
  49. // App.consoleView.Log(`psdToFgui pkgName:${pkg?.name ?? "null"}`);
  50. // if (pkg) {
  51. // FairyEditor.App.libView.ShowImportResourcesDialog(pkg);
  52. // }
  53. }
  54. }
  55. exports.default = PsdToFgui;