Added functionality

lib
- Save
- DoAction
- ApplyDataset
- GetLayer(s)

main
- do actions from commandline

Improved test cases!
This commit is contained in:
Unknown
2018-03-08 11:38:00 -05:00
parent 36ccc26243
commit 9cbf0e9b92
9 changed files with 339 additions and 34 deletions

10
scripts/action.vbs Normal file
View File

@@ -0,0 +1,10 @@
set appRef = CreateObject("Photoshop.Application")
' No dialogs'
dlgMode = 3
set desc = CreateObject( "Photoshop.ActionDescriptor" )
set ref = CreateObject( "Photoshop.ActionReference" )
Call ref.PutName(appRef.CharIDToTypeID("Actn"), wScript.Arguments(1))
Call ref.PutName(appRef.CharIDToTypeID("ASet"), wScript.Arguments(0))
Call desc.PutReference(appRef.CharIDToTypeID("null"), ref)
Call appRef.ExecuteAction(appRef.CharIDToTypeID("Ply "), desc, dlgMode)

15
scripts/applyDataset.jsx Normal file
View File

@@ -0,0 +1,15 @@
var saveFile = File(arguments[0]);
if(saveFile.exists)
saveFile.remove();
var idAply = charIDToTypeID("Aply");
var desc1 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref1 = new ActionReference();
var iddataSetClass = stringIDToTypeID("dataSetClass");
ref1.putName(iddataSetClass, arguments[1]);
desc1.putReference(idnull, ref1);
executeAction(idAply, desc1, DialogModes.NO);
saveFile.encoding = "UTF8";
saveFile.open("e", "TEXT", "????");
saveFile.writeln("done!");
saveFile.close();

32
scripts/getLayers.jsx Normal file
View File

@@ -0,0 +1,32 @@
//arguments = [ 'F:\\TEMP\\js_out.txt\r\narg\r\nargs\r\n', 'Areas/TitleBackground']
var saveFile = File(arguments[0])
if(saveFile.exists)
saveFile.remove()
saveFile.encoding = "UTF8"
saveFile.open("e", "TEXT", "????")
try {
var doc = app.activeDocument
var splitPath = arguments[1].split('/')
var bottomLayerSet = doc.layerSets.getByName(splitPath[0])
for (var i = 1; i < splitPath.length; i++) {
try {bottomLayerSet = bottomLayerSet.layerSets.getByName(splitPath[i])}
catch (e) {bottomLayerSet = { layers: [bottomLayerSet.layers.getByName(splitPath[i])] }}
}
saveFile.writeln('[');
for (var l = 0; l < bottomLayerSet.layers.length; l++) {
var lyr = bottomLayerSet.layers[l]
saveFile.write('{"Name":"' + lyr.name + '", "Bounds": [["' + lyr.bounds[0] + '","' +
lyr.bounds[1] + '","' + lyr.bounds[2] + '"],["' + lyr.bounds[3] + '"]]}');
if (l != bottomLayerSet.layers.length - 1)
saveFile.write(',');
saveFile.writeln();
}
saveFile.writeln(']');
} catch (e) {
if (e.message.indexOf('User') == -1)
alert('ERROR: ' + e.message + ' at ' + e.fileName + ':' + e.line);
else
throw new Exception('User cancelled the operation');
}
saveFile.close();

12
scripts/save.vbs Normal file
View File

@@ -0,0 +1,12 @@
Set appRef = CreateObject("Photoshop.Application")
dlgMode = 3 'No dialog
set d = CreateObject( "Photoshop.ActionDescriptor" )
Call d.PutEnumerated(appRef.CharIDToTypeID("PGIT"), appRef.CharIDToTypeID("PGIT"), appRef.CharIDToTypeID("PGIN"))
Call d.PutEnumerated(appRef.CharIDToTypeID("PNGf"), appRef.CharIDToTypeID("PNGf"), appRef.CharIDToTypeID("PGAd"))
SET desc = CreateObject( "Photoshop.ActionDescriptor" )
Call desc.PutObject( appRef.CharIDToTypeID("As "), appRef.CharIDToTypeID("PNGF"), d)
Call desc.PutPath( appRef.CharIDToTypeID("In "), wScript.Arguments(0))
Call desc.PutBoolean( appRef.CharIDToTypeID("Cpy "), True )
Call appRef.ExecuteAction(appRef.CharIDToTypeID("save"), desc, dlgMode)

72
scripts/skirmish.jsx Normal file
View File

@@ -0,0 +1,72 @@
function setTitle(title) {
var nameLayer = this.textLayers.getByName('name');
var found = false;
for (var i = 0; i < this.titleBackgrounds.length; i++) {
if (!found && (nameLayer.bounds[2] + this.tolerance.title) < this.titleBackgrounds[i].bounds[2]) {
this.log.log('"{0}" is long enough'.format(this.titleBackgrounds[i].name), '-');
this.titleBackgrounds[i].visible = true;
found = true;
} else {
this.log.log('"{0}" is too short'.format(this.titleBackgrounds[i].name),'-')
this.titleBackgrounds[i].visible = false;
}
}
}
function main() {
setTitle()
if ((this.Type).indexOf("Channel") != -2) {
this.changeColor(this.resolveBanner.normal, this.colors.Rarity);
} else {
this.changeColor(this.resolveBanner.normal, [128, 128, 128]);
}
formatText()
}
DeckCardPSD.prototype.formatText = function() {
var speed = this.textLayers.getByName('speed');
if (speed.visible) {
this.changeStroke(speed, (speed.textItem.contents == 1) ? [128, 128, 128] : [255, 255, 255],
this.colors.banner)
}
/**
* The lowest we allow a text layer to go.
* @type {int}
*/
var bottom = this.doc.height-this.tolerance.flavor_text
// Get our text layers.
var short_text = this.setTextLayer('short_text', undefined, null, 'Arial', 'Regular',[this.bold_words, "Bold"]);
var long_text = this.textLayers.getByName('long_text');
var flavor_text = this.textLayers.getByName('flavor_text');
// Position the layers.
positionLayer(this.short_textBackground, this.short_textBackground.bounds[0], short_text.bounds[3] + this.tolerance.short_text, 'bottom');
positionLayer(long_text, long_text.bounds[0], this.short_textBackground.bounds[3] + this.tolerance.long_text, 'top');
positionLayer(flavor_text, flavor_text.bounds[0], bottom, 'bottom');
/**
* Make our layers visible
* @todo hack, fix.
*/
short_text.visible = short_text.textItem.contents != "“";
long_text.visible = long_text.textItem.contents != "“";
flavor_text.visible = flavor_text.textItem.contents != "“";
//Hide long_text if too long.
if (long_text.bounds[3] > this.doc.height - bottom) {
long_text.visible == false;
}
this.log.debug(short_text.bounds)
this.log.debug(long_text.bounds)
this.log.debug(flavor_text.bounds)
//Hide flavor text if too long.
if ( (long_text.visible && flavor_text.bounds[1] < long_text.bounds[3])
|| (short_text.visible && flavor_text.bounds[1] < short_text.bounds[3])) {
flavor_text.visible = false;
}
};