This commit is contained in:
Unknown
2018-03-18 20:50:58 -04:00
parent 17a7f8ccd1
commit 7725110e35
13 changed files with 411 additions and 112 deletions

4
scripts/compilejs.jsx Normal file
View File

@@ -0,0 +1,4 @@
#include lib.js
var stdout = newFile(arguments[0])
eval(arguments[1]);
stdout.close()

38
scripts/getActiveDoc.jsx Normal file
View File

@@ -0,0 +1,38 @@
#include lib.js
var stdout = newFile(arguments[0]);
var doc = app.activeDocument;
stdout.writeln(('{"Name": "' + doc.name +'", "Height":' +doc.height +
', "Width":' + doc.width + ', "ArtLayers": [').replace(/ px/g, ""));
function layers(lyrs) {
if (typeof lyrs === 'undefined')
return;
for (var i = 0; i < lyrs.length; i++) {
var lyr = lyrs[i];
stdout.write(('{"Name":"' + lyr.name + '", "Bounds": [[' + lyr.bounds[0] + ',' +
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
lyr.bounds[3] + ']], "Visible": ' + lyr.visible + '}').replace(/ px/g, ""));
if (i+1 != lyrs.length)
stdout.write(',');
stdout.writeln();
}
}
layers(doc.artLayers)
stdout.writeln('], "LayerSets": [');
function lyrSets(sets, nm) {
if (typeof sets === 'undefined')
return;
for (var i = 0; i < sets.length; i++) {
var set = sets[i];
var name = nm + set.name + "/";
stdout.write('{"Name": "' + set.name + '", "LayerSets": [');
// lyrSets(set.layerSets, name);
stdout.write('], "ArtLayers": [');
layers(set.artLayers);
stdout.write(']}');
if (i+1 != sets.length)
stdout.write(',');
}
}
lyrSets(doc.layerSets)
stdout.write(']}');
stdout.close();

View File

@@ -0,0 +1,50 @@
#include lib.js
var stdout = newFile(arguments[0]);
var doc = app.activeDocument;
stdout.write(('{"Name": "' + doc.name +'", "Height":' +doc.height +
', "Width":' + doc.width + ", ").replace(/ px/g, ""));
function layersNsets(obj) {
stdout.write('"ArtLayers": [');
lyrss(obj.artLayers, "")
stdout.write('], "LayerSets": [');
lyrSets(obj.layerSets, "");
// stdout.write('], "LayerSets": [');
}
function lyrss(lyrs, set) {
if (typeof lyrs === 'undefined')
return;
for (var i = 0; i < lyrs.length; i++) {
var lyr = lyrs[i];
stdout.write(('{"Name":"' + lyr.name + '", "Bounds": [[' + lyr.bounds[0] + ',' +
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
lyr.bounds[3] + ']], "Path": "' + set +
'", "Visible": ' + lyr.visible + '}').replace(/ px/g, ""));
if (i+1 != lyrs.length)
stdout.write(',');
}
}
function lyrSets(sets, nm) {
if (typeof sets === 'undefined')
return;
for (var i = 0; i < sets.length; i++) {
var set = sets[i];
var name = nm + set.name + "/";
stdout.write('{"Name": "' + set.name + '", "LayerSets": [');
lyrSets(set.layerSets, name);
stdout.write('], "Layers": [');
lyrss(set.artLayers, name);
stdout.write(']}');
if (i+1 != sets.length)
stdout.write(',');
}
}
layersNsets(doc)
stdout.writeln(']}');
alert(doc.layerSets.getByName("Group 2").layerSets.getByName("Group 1").layers.getByName("Layer 1").name)
stdout.close();

8
scripts/getLayer.jsx Normal file
View File

@@ -0,0 +1,8 @@
#include lib.js
var stdout = newFile(arguments[0]);
var lyr = eval(arguments[1]);
stdout.writeln(('{"Name":"' + lyr.name + '", "Bounds": [[' + lyr.bounds[0] + ',' +
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
lyr.bounds[3] + ']], "Visible": ' + lyr.visible + '}').replace(/ px/g, ""));
stdout.close();

15
scripts/getLayerSet.jsx Normal file
View File

@@ -0,0 +1,15 @@
#include lib.js
var stdout = newFile(arguments[0]);
var set = eval(arguments[1]);
stdout.writeln('{"Name": "'+set.name+'", "ArtLayers":[');
for (var i = 0; i < set.artLayers.length; i++) {
var lyr = set.artLayers[i];
stdout.write(('{"Name":"' + lyr.name + '", "Bounds": [[' + lyr.bounds[0] + ',' +
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
lyr.bounds[3] + ']], "Visible": ' + lyr.visible + '}').replace(/ px/g, ""));
if (i != set.artLayers.length - 1)
stdout.writeln(",");
}
stdout.write("]}")
stdout.close();

View File

@@ -1,18 +0,0 @@
#include lib.js
var stdout = newFile(arguments[0])
var set = getLayers(arguments[1])
stdout.writeln('[');
for (var l = 0; l < set.layers.length; l++) {
var lyr = set.layers[l]
var lyrset = arguments[1].replace(lyr.name, "")
stdout.write(('{"Name":"' + lyr.name + '", "Bounds": [[' + lyr.bounds[0] + ',' +
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
lyr.bounds[3] + ']], "LayerSet": "' + lyrset + '"}').replace(/ px/g, ""));
if (l != set.layers.length - 1)
stdout.write(',');
stdout.writeln();
}
stdout.writeln(']');
stdout.close()

View File

@@ -8,27 +8,27 @@ function newFile(path) {
return f
}
// Returns an array of ArtLayers from a layerSet or an ArtLayer.
function getLayers(path) {
try {
var doc = app.activeDocument
var path = path.split('/')
var lyrs = doc.layerSets.getByName(path[0])
for (var i = 1; i < path.length; i++) {
try {
lyrs = lyrs.layerSets.getByName(path[i])
} catch (e) {
lyrs = { layers: [lyrs.layers.getByName(path[i])] } }
}
return lyrs
} catch (e) {
if (e.message.indexOf('User') == -1)
alert(err(e));
else
throw new Exception('User cancelled the operation');
}
}
// Moves a layer
function positionLayer(lyr, x, y, alignment){
if(lyr.iisBackgroundLayer||lyr.positionLocked) return
var layerBounds = lyr.bounds;
var layerX = layerBounds[0].value;
if (alignment == 'top' || alignment == null)
var layerY = layerBounds[1].value;
else if (alignment == 'bottom')
var layerY = layerBounds[3].value;
var deltaX = x-layerX;
var deltaY = y-layerY;
lyr.translate(deltaX, deltaY);
}
// Prints an error message.
function err(e) {
return 'ERROR: ' + e.message + ' at ' + e.fileName + ':' + e.line;
}
function bounds(lyr) {
return ('"Bounds": [[' + lyr.bounds[0] + ',' +
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
lyr.bounds[3] + ']]').replace(/ px/g, "");
}

6
scripts/moveLayer.jsx Normal file
View File

@@ -0,0 +1,6 @@
#include lib.js
var stdout = newFile(arguments[0]);
var lyr = eval(arguments[1]);
lyr.translate((Number)(arguments[2]), (Number)(arguments[3]));
stdout.writeln('{' + bounds(lyr) + '}')
stdout.close();

View File

@@ -1,11 +0,0 @@
#include lib.js
var stdout = newFile(arguments[0])
var lyrs = getLayers(arguments[1])
var vis = arguments[2] == "true"
try {
for (var i = 0; i < lyrs.layers.length; i++)
lyrs.layers[i].visible = vis
} catch (e) {
stdout.writeln(err(e))
}
stdout.close()

View File

@@ -24,47 +24,34 @@ function main() {
formatText()
}
DeckCardPSD.prototype.formatText = function() {
var speed = this.textLayers.getByName('speed');
function formatText() {
var lyrs = getLayers(arguments[1])
var speed = lyrs.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');
// var short_text = this.setTextLayer('short_text', undefined, null, 'Arial', 'Regular',[this.bold_words, "Bold"]);
var short_text = lyrs.getByName('short_text')
var long_text = lyrs.getByName('long_text');
var flavor_text = lyrs.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;