Skip to content

Commit

Permalink
Added Local To Global Scale to Copy Layers.
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Oct 29, 2015
1 parent 33a48b6 commit 0cc31fa
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 85 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ Create animation event labels on the timeline which work with `springroll.easelj

This command combines all layers on the current timeline non-destructively into a single bitmap. All the layers are guided, locked and hidden. Running the script again will undo this convert and give you the normal vector layers.

#### Utilities/Local To Global Scale

Get the global scale that a nested clip is displayed at. Only available for editing the symbol in place. This can be combined with the Copy Layer To Bitmap command to generate bitmaps that are rendered _only_ as large as they need to be.

#### HTML5 Canvas Post Publish

This is not a command. This script automatically is invoked whenever an HTML5 Canvas FLA is published. It does two things: first, a JSON file is created of the `lib.properties` (which contains the manifest, size, framerate, etc) of the current document. Also, the output file is optimize to better work with a JavaScript minification tool (e.g., [Uglify](https://github.com/mishoo/UglifyJS2)).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.2.0",
"version": "1.3.0",
"private": true,
"devDependencies": {
"grunt": "^0.4.5",
Expand Down
85 changes: 74 additions & 11 deletions src/Commands/Utilities/Copy Layers To Bitmap.jsfl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(function()
{
var DATA_KEY = 'copyLayersToBitmapScale';
var DEFAULT_DATA_KEY = 'copyLayersToBitmapScaleDefaultGlobal';
var SCALE_PROMPT = 'Output scale';

var dom = fl.getDocumentDOM();
Expand Down Expand Up @@ -49,8 +48,6 @@
var bitmapName;
var scale;
var defaultScale;
var defaultGlobalScale = dom.documentHasData(DEFAULT_DATA_KEY) ?
dom.getDataFromDocument(DEFAULT_DATA_KEY) : '1.0';

// If we're inside a symbol, use the name of the
if (timeline.libraryItem)
Expand All @@ -64,7 +61,7 @@
}

// Get and save scale for library item
defaultScale = item.hasData(DATA_KEY) ? item.getData(DATA_KEY) : defaultGlobalScale;
defaultScale = item.hasData(DATA_KEY) ? item.getData(DATA_KEY) : localToGlobalScale();
scale = prompt(SCALE_PROMPT, defaultScale);
if (!scale)
{
Expand All @@ -79,7 +76,7 @@
bitmapName = dom.name.substr(0, dom.name.lastIndexOf('.'));

// Get and save scale for document
defaultScale = dom.documentHasData(DATA_KEY) ? dom.getDataFromDocument(DATA_KEY) : defaultGlobalScale;
defaultScale = dom.documentHasData(DATA_KEY) ? dom.getDataFromDocument(DATA_KEY) : localToGlobalScale();
scale = prompt(SCALE_PROMPT, defaultScale);
if (!scale)
{
Expand All @@ -101,10 +98,6 @@
return alert("Error: Invalid scale amount");
}


// Save the default setting
dom.addDataToDocument(DEFAULT_DATA_KEY, "double", scale);

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

Expand Down Expand Up @@ -235,5 +228,75 @@
}
return status;
}

}());

function localToGlobalScale()
{
var doc = fl.getDocumentDOM();

if (!doc) return;

var scaleX = 1;
var scaleY = 1;

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

while(libraryItem)
{
// Go "up" a nested level
doc.exitEditMode();
steps++;

// Get the new timeline
timeline = doc.getTimeline();

var foundItem = false;
for(var i = 0; i < timeline.layers.length; i++)
{
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;
}
if (!foundItem)
{
break;
}
libraryItem = timeline.libraryItem;
}

// Go back to where we started
if (steps)
{
while(steps--)
{
if (doc.selection.length)
{
doc.enterEditMode("inPlace");
}
}
}

// Do a little rounding
scaleX = Math.round(scaleX * 100000) / 100000;
scaleY = Math.round(scaleY * 100000) / 100000;

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

}());
67 changes: 0 additions & 67 deletions src/Commands/Utilities/Local To Global Scale.jsfl

This file was deleted.

3 changes: 1 addition & 2 deletions src/io.springroll.toolkit.mxi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name="SpringRoll Flash Toolkit"
id="io.springroll.toolkit"
requires-restart="true"
version="1.2.0">
version="1.3.0">
<author name="SpringRoll"/>
<description>
<![CDATA[Commands for Exporting, Optimizing and Publish HTML5 Canvas documents]]>
Expand Down Expand Up @@ -37,7 +37,6 @@
<file source="Commands/Optimizing/HTML5 Canvas Size Report.jsfl" destination="$Flash/Commands/Optimizing/" />

<file source="Commands/Utilities/Copy Layers To Bitmap.jsfl" destination="$Flash/Commands/Utilities/" />
<file source="Commands/Utilities/Local To Global Scale.jsfl" destination="$Flash/Commands/Utilities/" />

<file source="Tools/HTMLCanvasPostPublish.jsfl" destination="$Flash/Tools/" />

Expand Down

0 comments on commit 0cc31fa

Please sign in to comment.