mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-11-18 19:50:00 +01:00
Co-authored-by: DrPerkyLegit <116128211+DrPerkyLegit@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Anaël <60509176+Bakoubak@users.noreply.github.com> Reviewed-on: https://git.neolegacy.dev/neoStudiosLCE/neoLegacy/pulls/4205
74 lines
3.0 KiB
Java
74 lines
3.0 KiB
Java
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.*;
|
|
|
|
public class AddDeathMessageLabel {
|
|
private static final float SCALE = 0.5f;
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
if (args.length < 1) {
|
|
System.out.println("Usage: AddDeathMessageLabel <swf_file> [output_file]");
|
|
System.exit(1);
|
|
}
|
|
String inputPath = args[0];
|
|
String outputPath = args.length > 1 ? args[1] : inputPath;
|
|
|
|
SWF swf = new SWF(new FileInputStream(inputPath), false);
|
|
|
|
PlaceObject3Tag title = null;
|
|
Integer respawnY = null;
|
|
int maxDepth = 0;
|
|
for (Tag tag : swf.getTags()) {
|
|
if (tag instanceof PlaceObjectTypeTag) {
|
|
PlaceObjectTypeTag po = (PlaceObjectTypeTag) tag;
|
|
if ("DeathMessage".equals(po.getInstanceName())) {
|
|
System.out.println("DeathMessage already exists in " + inputPath + ", skipping.");
|
|
return;
|
|
}
|
|
if ("Title".equals(po.getInstanceName()) && tag instanceof PlaceObject3Tag) title = (PlaceObject3Tag) tag;
|
|
if ("Respawn".equals(po.getInstanceName())) respawnY = po.getMatrix().translateY;
|
|
if (po.getDepth() > maxDepth) maxDepth = po.getDepth();
|
|
}
|
|
}
|
|
if (title == null || respawnY == null) {
|
|
System.err.println("ERROR: Title or Respawn not found in " + inputPath);
|
|
System.exit(1);
|
|
}
|
|
|
|
int centreX = (swf.displayRect.Xmax + swf.displayRect.Xmin) / 2;
|
|
int titleX = title.matrix.translateX;
|
|
int titleY = title.matrix.translateY;
|
|
|
|
PlaceObject3Tag label = new PlaceObject3Tag(swf);
|
|
label.placeFlagHasClassName = title.placeFlagHasClassName;
|
|
label.placeFlagHasName = true;
|
|
label.placeFlagHasMatrix = true;
|
|
label.placeFlagHasImage = title.placeFlagHasImage;
|
|
label.placeFlagHasCharacter = title.placeFlagHasCharacter;
|
|
label.placeFlagMove = title.placeFlagMove;
|
|
label.className = title.className;
|
|
label.characterId = title.characterId;
|
|
label.name = "DeathMessage";
|
|
label.depth = maxDepth + 1;
|
|
MATRIX m = new MATRIX(title.matrix);
|
|
m.hasScale = true;
|
|
m.scaleX = title.matrix.scaleX * SCALE;
|
|
m.scaleY = title.matrix.scaleY * SCALE;
|
|
m.translateX = centreX - Math.round((centreX - titleX) * SCALE);
|
|
m.translateY = titleY + Math.round((respawnY - titleY) * 0.4f);
|
|
label.matrix = m;
|
|
label.setModified(true);
|
|
|
|
List<Tag> tags = swf.getTags().toArrayList();
|
|
swf.addTag(tags.indexOf(title) + 1, label);
|
|
|
|
System.out.println(inputPath + ": DeathMessage at " + m.translateX + "," + m.translateY + " depth=" + label.depth);
|
|
try (FileOutputStream fos = new FileOutputStream(outputPath)) {
|
|
swf.saveTo(fos);
|
|
}
|
|
}
|
|
}
|