Skip to content

Commit

Permalink
Fixed FLA export shape tweens (morphshapes)
Browse files Browse the repository at this point in the history
as 2 testdata as uncompressed
  • Loading branch information
jindrapetrik committed Mar 19, 2023
1 parent 6ef0164 commit 2b0e163
Show file tree
Hide file tree
Showing 42 changed files with 5,205 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ All notable changes to this project will be documented in this file.
- Do not display fonts added to stage (for example in testdata/as2.swf, the vertical text - sprite 10)
- AS2 Class detection - TemporaryRegisterMark handling
- FLA export scripts location
- FLA export shape tweens (morphshapes)

### Changed
- AS1/2/3 P-code - format Number values with EcmaScript toString function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private static void convertShapeEdge(MATRIX mat, ShapeRecordAdvanced record, dou
}
}

private static void convertShapeEdges(double startX, double startY, MATRIX mat, List<ShapeRecordAdvanced> recordsAdvanced, StringBuilder ret) {
private static void convertShapeEdges(boolean close, double startX, double startY, MATRIX mat, List<ShapeRecordAdvanced> recordsAdvanced, StringBuilder ret) {

double x = startX;
double y = startY;
Expand All @@ -296,11 +296,26 @@ private static void convertShapeEdges(double startX, double startY, MATRIX mat,
if (!hasMove) {
ret.append("! ").append(formatEdgeDouble(startX, false)).append(" ").append(formatEdgeDouble(startY, false));
}
double lastMoveToX = startX;
double lastMoveToY = startY;

for (ShapeRecordAdvanced rec : recordsAdvanced) {
if (rec instanceof StyleChangeRecordAdvanced) {
StyleChangeRecordAdvanced scr = (StyleChangeRecordAdvanced)rec;
if (scr.stateMoveTo) {
lastMoveToX = scr.moveDeltaX;
lastMoveToY = scr.moveDeltaY;
}
}
convertShapeEdge(mat, rec, x, y, ret);
x = rec.changeX(x);
y = rec.changeY(y);
}
//hack for morphshapes. TODO: make this better
if (close && (Double.compare(lastMoveToX, x) != 0 || Double.compare(lastMoveToY, y) != 0)) {
StraightEdgeRecordAdvanced ser = new StraightEdgeRecordAdvanced(lastMoveToX - x, lastMoveToY - y);
convertShapeEdge(mat, ser, x, y, ret);
}
}

private static String getScaleMode(ILINESTYLE lineStyle) {
Expand Down Expand Up @@ -821,7 +836,7 @@ private static List<String> getShapeLayers(HashMap<Integer, CharacterTag> charac
currentLayer.writeAttribute("strokeStyle", strokeStyle);
}
StringBuilder edgesSb = new StringBuilder();
convertShapeEdges(startEdgeX, startEdgeY, mat, edges, edgesSb);
convertShapeEdges(((fillStyle0 > 0 || fillStyle1 > 0) && morphshape), startEdgeX, startEdgeY, mat, edges, edgesSb);
currentLayer.writeAttribute("edges", edgesSb.toString());
currentLayer.writeEndElement();
hasEdge = true;
Expand Down Expand Up @@ -908,7 +923,7 @@ private static List<String> getShapeLayers(HashMap<Integer, CharacterTag> charac
currentLayer.writeAttribute("strokeStyle", lastStrokeStyle);
}
StringBuilder edgesSb = new StringBuilder();
convertShapeEdges(startEdgeX, startEdgeY, mat, edges, edgesSb);
convertShapeEdges(((lastFillStyle0 > 0 || lastFillStyle1 > 0) && morphshape), startEdgeX, startEdgeY, mat, edges, edgesSb);
currentLayer.writeAttribute("edges", edgesSb.toString());
currentLayer.writeEndElement();
hasEdge = true;
Expand Down Expand Up @@ -936,7 +951,7 @@ private static List<String> getShapeLayers(HashMap<Integer, CharacterTag> charac
currentLayer.writeAttribute("strokeStyle", strokeStyle);
}
StringBuilder edgesSb = new StringBuilder();
convertShapeEdges(startEdgeX, startEdgeY, mat, edges, edgesSb);
convertShapeEdges(((fillStyle0 > 0 || fillStyle1 > 0) && morphshape), startEdgeX, startEdgeY, mat, edges, edgesSb);
currentLayer.writeAttribute("edges", edgesSb.toString());
currentLayer.writeEndElement();
hasEdge = true;
Expand All @@ -959,7 +974,7 @@ private static List<String> getShapeLayers(HashMap<Integer, CharacterTag> charac
}

/**
* A hack. This will remove a stroked path with no fill which has same stroke as subsequent path.
* A hack. This will remove a stroked path with no fill which has same stroke as subsequent path (or is its prefix).
* This happens in the morphshape edges. This needs to be cleaned up before exporting to FLA.
*
* @param layer
Expand Down Expand Up @@ -1001,7 +1016,7 @@ private static String removeOnlyStrokeEdgesBeforeSameFilled(String layer) {
if (prevStrokeOnly != null &&
strokeStyle != null &&
strokeStyle.equals(prevStrokeOnly) &&
prevEdgesStr.equals(edgesStr)) {
edgesStr.startsWith(prevEdgesStr)) {
Node edgeToRemove = prevNode;
edgeToRemove.getParentNode().removeChild(edgeToRemove);
}
Expand Down
Binary file removed libsrc/ffdec_lib/testdata/as2/as2.fla
Binary file not shown.
Loading

0 comments on commit 2b0e163

Please sign in to comment.