Skip to content

Commit

Permalink
Fixed running on stage and newWindow edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Karl committed Oct 30, 2015
1 parent d28649b commit 4d2090b
Showing 1 changed file with 56 additions and 30 deletions.
86 changes: 56 additions & 30 deletions src/Commands/Utilities/Copy Layers To Bitmap.jsfl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
var bitmapName;
var scale = localToGlobalScale();

// The prompt was cancelled
if (scale === null)
{
return;
}

// If we're inside a symbol, use the name of the
if (timeline.libraryItem)
{
Expand All @@ -56,18 +62,17 @@
bitmapName = bitmapName.substr(index + 1);
}
}
else if (dom.name)
else
{
if (!dom.name)
{
return alert("Please save document first.");
}

// Chop of the ".fla" or ".xfl" extension
bitmapName = dom.name.substr(0, dom.name.lastIndexOf('.'));
}

// Cancelled
if (!bitmapName)
{
return alert("Error: Invalid bitmap name");
}

// The number of layers
var origLength = timeline.layers.length;

Expand Down Expand Up @@ -207,11 +212,20 @@

var scaleX = 1;
var scaleY = 1;
var scale;

var timeline = doc.getTimeline();
var libraryItem = timeline.libraryItem;
var originalItem = libraryItem = timeline.libraryItem;
var steps = 0;

// We're on the main stage, ignore the rest set to 100%
if (!libraryItem)
{
return 1;
}

var scaleKey = 'copyLayersToBitmapScale';

while(libraryItem)
{
// Go "up" a nested level
Expand All @@ -221,30 +235,32 @@
// Get the new timeline
timeline = doc.getTimeline();

var foundItem = false;
for(var i = 0; i < timeline.layers.length; i++)
var element = doc.selection[0];
if (element && element.libraryItem == libraryItem)
{
var frame = timeline.layers[i].frames[timeline.currentFrame];
if(!frame)
continue;

for(var j = 0; j < frame.elements.length; j++)
{
var element = frame.elements[j];
if (element.libraryItem == libraryItem)
{
scaleX *= element.scaleX;
scaleY *= element.scaleY;
foundItem = true;
break;
}
}
if(foundItem)
break;
scaleX *= element.scaleX;
scaleY *= element.scaleY;
}
if (!foundItem)
else
{
break;
// Go back into the symbol after we exited
doc.library.editItem(libraryItem.name);

// Get the saved scale amount
var defaultScale = libraryItem.hasData(scaleKey) ?
libraryItem.getData(scaleKey) : 1;

// Aask for the scale
var scale = prompt("Output scale", defaultScale);

if (!scale) return null;

scale = parseFloat(scale);

// Save the scale to use at the default later on
libraryItem.addData(scaleKey, "double", scale);

return scale;
}
libraryItem = timeline.libraryItem;
}
Expand All @@ -265,8 +281,18 @@
scaleX = Math.round(scaleX * 100000) / 100000;
scaleY = Math.round(scaleY * 100000) / 100000;

// Get the larger scale size
scale = Math.max(scaleX, scaleY);

// Save the scale to the library item if we have it
if (originalItem)
{
// Save the scale to use at the default later on
originalItem.addData(scaleKey, "double", scale);
}

// Get the largest scale
return Math.max(scaleX, scaleY);
return scale;
}

}());

0 comments on commit 4d2090b

Please sign in to comment.