feat: SWF-to-PNG extraction pipeline + de-SWF roadmap
- extract-ui-pngs.sh: batch-exports all 377 Windows64 SWFs via ffdec (50,077 PNGs: bitmaps, shapes, sprite frames, named by export symbol) - tools/DumpLayout.java: dumps per-SWF layout JSON (exports, imports, sprite display lists with matrices and instance names) - docs/UI-DESWF-ROADMAP.md: phased plan to replace Iggy with a PNG-based iggy-shim, scene by scene
This commit is contained in:
120
tools/DumpLayout.java
Normal file
120
tools/DumpLayout.java
Normal file
@@ -0,0 +1,120 @@
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.tags.*;
|
||||
import com.jpexs.decompiler.flash.tags.base.*;
|
||||
import com.jpexs.decompiler.flash.types.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Dumps a SWF's UI structure as JSON: header, exported/imported symbols,
|
||||
* and per-sprite display lists (placements with matrices and instance names).
|
||||
* Usage: DumpLayout <swf-file> (JSON on stdout)
|
||||
*/
|
||||
public class DumpLayout {
|
||||
|
||||
static String esc(String s) {
|
||||
if (s == null) return "";
|
||||
return s.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "");
|
||||
}
|
||||
|
||||
static String matrixJson(MATRIX m) {
|
||||
if (m == null) return "null";
|
||||
return String.format(Locale.US,
|
||||
"{\"tx\":%.2f,\"ty\":%.2f,\"sx\":%.4f,\"sy\":%.4f,\"rot\":%b}",
|
||||
m.translateX / 20.0, m.translateY / 20.0,
|
||||
m.hasScale ? m.getScaleXFloat() : 1.0f,
|
||||
m.hasScale ? m.getScaleYFloat() : 1.0f,
|
||||
m.hasRotate);
|
||||
}
|
||||
|
||||
static void dumpPlacements(Iterable<Tag> tags, StringBuilder sb) {
|
||||
boolean first = true;
|
||||
int frame = 0;
|
||||
sb.append("[");
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof ShowFrameTag) { frame++; continue; }
|
||||
if (t instanceof PlaceObjectTypeTag) {
|
||||
PlaceObjectTypeTag p = (PlaceObjectTypeTag) t;
|
||||
if (!first) sb.append(",");
|
||||
first = false;
|
||||
sb.append(String.format(Locale.US,
|
||||
"{\"frame\":%d,\"depth\":%d,\"charId\":%d,\"name\":\"%s\",\"matrix\":%s}",
|
||||
frame, p.getDepth(), p.getCharacterId(),
|
||||
esc(p.getInstanceName()), matrixJson(p.getMatrix())));
|
||||
}
|
||||
}
|
||||
sb.append("]");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SWF swf = new SWF(new FileInputStream(args[0]), false);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(String.format(Locale.US,
|
||||
"\"file\":\"%s\",\"width\":%.0f,\"height\":%.0f,\"fps\":%.1f,",
|
||||
esc(new File(args[0]).getName()),
|
||||
swf.displayRect.getWidth() / 20.0, swf.displayRect.getHeight() / 20.0,
|
||||
swf.frameRate));
|
||||
|
||||
// exported symbols (name -> charId)
|
||||
sb.append("\"exports\":{");
|
||||
boolean first = true;
|
||||
for (Tag t : swf.getTags()) {
|
||||
if (t instanceof ExportAssetsTag) {
|
||||
ExportAssetsTag e = (ExportAssetsTag) t;
|
||||
for (int i = 0; i < e.tags.size(); i++) {
|
||||
if (!first) sb.append(",");
|
||||
first = false;
|
||||
sb.append("\"").append(esc(e.names.get(i))).append("\":").append(e.tags.get(i));
|
||||
}
|
||||
}
|
||||
if (t instanceof SymbolClassTag) {
|
||||
SymbolClassTag s = (SymbolClassTag) t;
|
||||
for (int i = 0; i < s.tags.size(); i++) {
|
||||
if (!first) sb.append(",");
|
||||
first = false;
|
||||
sb.append("\"").append(esc(s.names.get(i))).append("\":").append(s.tags.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("},");
|
||||
|
||||
// imports (runtime skin dependencies)
|
||||
sb.append("\"imports\":[");
|
||||
first = true;
|
||||
for (Tag t : swf.getTags()) {
|
||||
if (t instanceof ImportAssets2Tag) {
|
||||
ImportAssets2Tag imp = (ImportAssets2Tag) t;
|
||||
for (int i = 0; i < imp.tags.size(); i++) {
|
||||
if (!first) sb.append(",");
|
||||
first = false;
|
||||
sb.append(String.format("{\"url\":\"%s\",\"name\":\"%s\",\"charId\":%d}",
|
||||
esc(imp.url), esc(imp.names.get(i)), imp.tags.get(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("],");
|
||||
|
||||
// sprites with display lists
|
||||
sb.append("\"sprites\":{");
|
||||
first = true;
|
||||
for (Tag t : swf.getTags()) {
|
||||
if (t instanceof DefineSpriteTag) {
|
||||
DefineSpriteTag sp = (DefineSpriteTag) t;
|
||||
if (!first) sb.append(",");
|
||||
first = false;
|
||||
sb.append("\"").append(sp.spriteId).append("\":{\"frames\":")
|
||||
.append(sp.frameCount).append(",\"places\":");
|
||||
dumpPlacements(sp.getTags(), sb);
|
||||
sb.append("}");
|
||||
}
|
||||
}
|
||||
sb.append("},");
|
||||
|
||||
// main timeline
|
||||
sb.append("\"timeline\":");
|
||||
dumpPlacements(swf.getTags(), sb);
|
||||
sb.append("}");
|
||||
System.out.println(sb);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user