优化导出
This commit is contained in:
parent
009d4f62f5
commit
708dc913d0
@ -106,11 +106,34 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
if (this.saveFolder === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.documentName = app.activeDocument.name.slice(0, -4);
|
||||
|
||||
// 导出整个psd作为png参考图
|
||||
var i, j, k, len, ref1, removeFiles;
|
||||
var baseFolder = Folder(this.saveFolder + "/" + this.documentName);
|
||||
if (baseFolder.exists) {
|
||||
removeFiles = baseFolder.getFiles();
|
||||
for (i = j = 0, ref1 = removeFiles.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) {
|
||||
if (removeFiles[i].name.startsWith(this.documentName) && removeFiles[i].name.endsWith('.png')) {
|
||||
removeFiles[i].remove();
|
||||
}
|
||||
}
|
||||
baseFolder.remove();
|
||||
}
|
||||
baseFolder.create();
|
||||
saveFile = new File(baseFolder.fsName + "/" + "__background__.png");
|
||||
options = new ExportOptionsSaveForWeb();
|
||||
options.format = SaveDocumentType.PNG;
|
||||
options.PNG8 = false;
|
||||
options.optimized = true;
|
||||
options.interlaced = false;
|
||||
app.activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, options);
|
||||
|
||||
|
||||
copiedDoc = app.activeDocument.duplicate(app.activeDocument.name.slice(0, -4) + '.copy.psd');
|
||||
copiedDoc.quickMaskMode = false;
|
||||
Util.deselectLayers();
|
||||
|
||||
var legal = this.checkLayerName(copiedDoc);
|
||||
if (!legal) {
|
||||
copiedDoc.close(SaveOptions.DONOTSAVECHANGES);
|
||||
@ -135,7 +158,20 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
if (after_close) {
|
||||
return app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
}
|
||||
return alert('导出完成!');
|
||||
|
||||
var scriptFolder = new File($.fileName).path;
|
||||
var batFileName = scriptFolder + "/run_step2.bat";
|
||||
|
||||
var batFile = new File(batFileName);
|
||||
batFile.open("w");
|
||||
batFile.writeln("cd /d %~dp0");
|
||||
// -src image -dst image_3
|
||||
batFile.writeln("start step2.exe -src " + baseFolder.fsName + " -dst "+ baseFolder.fsName + "_output");
|
||||
batFile.close();
|
||||
|
||||
batFile = new File(batFileName);
|
||||
batFile.execute();
|
||||
return;
|
||||
};
|
||||
|
||||
Baum.prototype.selectDocumentArea = function (document) {
|
||||
@ -242,6 +278,42 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
var ref1 = root.layers
|
||||
for (var j = 0; j < ref1.length; j++) {
|
||||
var layer = ref1[j];
|
||||
//使用别名替换关键字符
|
||||
if (layer.typename === 'ArtLayer')
|
||||
{
|
||||
if (layer.kind !== LayerKind.TEXT) // 图片
|
||||
{
|
||||
var ss = layer.name.split("@");
|
||||
var opt = Util.parseOption(ss[1]);
|
||||
|
||||
if (layer.name.startsWith("%"))
|
||||
{
|
||||
layer.name = layer.name.substring(1, layer.name.length);
|
||||
if (Util.isEmptyObject(opt) || !opt["图片"])
|
||||
{
|
||||
layer.name += "@图片";
|
||||
}
|
||||
}else if (layer.name.startsWith("$"))
|
||||
{
|
||||
layer.name = layer.name.substring(1, layer.name.length);
|
||||
if (Util.isEmptyObject(opt))
|
||||
{
|
||||
layer.name += "@图片";
|
||||
}
|
||||
else
|
||||
{
|
||||
layer.name += ",图片";
|
||||
}
|
||||
layer.name += "=导出";
|
||||
}
|
||||
|
||||
if (layer.name.indexOf("@图片") < 0 && layer.name.indexOf(",图片") < 0)
|
||||
{
|
||||
layer.name = "#" + layer.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ss = layer.name.split("@");
|
||||
//忽略但保留父节点宽高影响,则不移除
|
||||
if (Util.isInferiorIgnoreByName(ss[0])) {
|
||||
@ -311,9 +383,9 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
}
|
||||
|
||||
//文件名合规检测
|
||||
var reg = /^[0-9a-zA-Z"_""\-"]*$/g;
|
||||
var reg = /^[0-9a-zA-Z\u4e00-\u9fa5"_""\-"]*$/g;
|
||||
if (!reg.test(ss[0])) {
|
||||
alert("\"" + layer.name + "\" 名字不合法,只能含有英文、数字、-、_")
|
||||
alert("\"" + layer.name + "\" 名字不合法,只能含有中文、英文、数字、-、_")
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -663,7 +735,6 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
if (opt['全屏']) { hash['full'] = "True"; hash['stretchxy'] = "True"; }
|
||||
if (opt['竖直列表']) { hash['type'] = "List"; hash['scroll'] = "vertical"; }
|
||||
if (opt['水平列表']) { hash['type'] = "List"; hash['scroll'] = "horizontal"; }
|
||||
if (opt['图片']) { hash['imageName'] = opt['图片']; } else { hash['imageName'] = name; }
|
||||
if (opt['遮罩']) { hash['type'] = "Mask"; hash['mask'] = "hard" }
|
||||
//按钮可以覆盖遮罩,并在按钮上用遮罩组件
|
||||
if (opt['按钮']) { hash['type'] = "Button"; }
|
||||
@ -673,6 +744,7 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
if (opt['进度条']) { hash['type'] = "Slider"; }
|
||||
if (opt['滚动条']) { hash['type'] = "Scrollbar"; }
|
||||
if (opt['开关']) { hash['type'] = "Toggle"; }
|
||||
if (opt['图片']) { hash['imageName'] = name; }
|
||||
if (opt['预制体']) {
|
||||
hash['type'] = "Prefab";
|
||||
if (layer.typename !== 'ArtLayer') {
|
||||
@ -863,28 +935,8 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
var outputDoc
|
||||
|
||||
PsdToImage.prototype.run = function (document, saveFolder, documentName) {
|
||||
var i, j, k, len, ref1, removeFiles, results, snapShotId, target, targets;
|
||||
var k, len, results, snapShotId, target, targets;
|
||||
this.baseFolder = Folder(saveFolder + "/" + documentName);
|
||||
if (this.baseFolder.exists) {
|
||||
removeFiles = this.baseFolder.getFiles();
|
||||
for (i = j = 0, ref1 = removeFiles.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) {
|
||||
if (removeFiles[i].name.startsWith(documentName) && removeFiles[i].name.endsWith('.png')) {
|
||||
removeFiles[i].remove();
|
||||
}
|
||||
}
|
||||
this.baseFolder.remove();
|
||||
}
|
||||
|
||||
this.baseFolder.create();
|
||||
|
||||
// 导出整个psd作为png参考图
|
||||
saveFile = new File(this.baseFolder.fsName + "/" + "__background__.png");
|
||||
options = new ExportOptionsSaveForWeb();
|
||||
options.format = SaveDocumentType.PNG;
|
||||
options.PNG8 = false;
|
||||
options.optimized = true;
|
||||
options.interlaced = false;
|
||||
document.exportDocument(saveFile, ExportType.SAVEFORWEB, options);
|
||||
|
||||
targets = this.allLayers(document);
|
||||
//snapShotId = Util.takeSnapshot(document);
|
||||
@ -943,7 +995,7 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
return
|
||||
}
|
||||
//预制体不切图
|
||||
if (opt['预制体']) {
|
||||
if (opt['预制体'] || !opt['图片']) {
|
||||
return
|
||||
}
|
||||
fileNames.push(fileName);
|
||||
@ -981,6 +1033,16 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
// }
|
||||
|
||||
if (!layer.isBackgroundLayer) {
|
||||
if (opt['图片'] !== "导出")
|
||||
{
|
||||
fileName += "-noexport";
|
||||
}
|
||||
|
||||
if (opt['九宫格'])
|
||||
{
|
||||
fileName += "-slice";
|
||||
}
|
||||
|
||||
this.snipImage(outputDoc, layer, opt);
|
||||
}
|
||||
|
||||
@ -1587,6 +1649,10 @@ function s2t(t) { return stringIDToTypeID(t) }
|
||||
}
|
||||
};
|
||||
|
||||
Util.isEmptyObject = function (obj) {
|
||||
for (var key in obj) { if (obj.hasOwnProperty(key)) { return false; } } return true;
|
||||
}
|
||||
|
||||
Util.parseOption = function (text) {
|
||||
var elements, j, len, opt, optText, ref1;
|
||||
if (!text) {
|
||||
|
2
.PhotoshopScript/JSZXPsd2Unity/run_step2.bat
Normal file
2
.PhotoshopScript/JSZXPsd2Unity/run_step2.bat
Normal file
@ -0,0 +1,2 @@
|
||||
cd /d %~dp0
|
||||
start step2.exe -src C:\Users\93685\Desktop\Sample -dst C:\Users\93685\Desktop\Sample_output
|
BIN
.PhotoshopScript/JSZXPsd2Unity/step2.exe
Normal file
BIN
.PhotoshopScript/JSZXPsd2Unity/step2.exe
Normal file
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user