|
@@ -1,8 +1,15 @@
|
|
|
package xyz.tbvns.GeometryDash;
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.dataformat.xml.XmlFactory;
|
|
|
+import com.stanfy.gsonxml.GsonXml;
|
|
|
+import com.stanfy.gsonxml.GsonXmlBuilder;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
+import org.xml.sax.SAXException;
|
|
|
+import xyz.tbvns.XmlUtils;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
+import javax.xml.parsers.ParserConfigurationException;
|
|
|
import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
@@ -11,22 +18,28 @@ import java.io.IOException;
|
|
|
import static java.lang.Math.round;
|
|
|
|
|
|
public class TextureExtractor {
|
|
|
- public static void extract(File plist, File textures, File output) throws IOException {
|
|
|
- String config = FileUtils.readFileToString(plist);
|
|
|
+ public static void extract(File plist, File textures, File output) throws IOException, ParserConfigurationException, SAXException {
|
|
|
+ String config = removeLines(FileUtils.readFileToString(plist), 2);
|
|
|
+ config = XmlUtils.gamesheetToXML(config);
|
|
|
+
|
|
|
BufferedImage image = ImageIO.read(textures);
|
|
|
String[] readableConfig = config
|
|
|
.replace(" ", "")
|
|
|
.split("\n");
|
|
|
|
|
|
+ if (true) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
String name = "";
|
|
|
float x = 0, y = 0, w = 0, h = 0;
|
|
|
boolean rotated = false, ready = false;
|
|
|
for (int i = 0; i < readableConfig.length; i++) {
|
|
|
String line = readableConfig[i];
|
|
|
- if (line.startsWith("<key>") && line.endsWith(".png</key>")) {
|
|
|
+ if (line.contains("<key>") && line.contains(".png</key>")) {
|
|
|
name = line.replace("<key>", "").replace("</key>", "");
|
|
|
}
|
|
|
- else if (line.equals("<key>textureRect</key>")) {
|
|
|
+ else if (line.contains("<key>textureRect</key>")) {
|
|
|
String data = readableConfig[i+1];
|
|
|
String[] readableData = data
|
|
|
.replace("<string>", "")
|
|
@@ -38,17 +51,17 @@ public class TextureExtractor {
|
|
|
y = Float.parseFloat(readableData[1]);
|
|
|
w = Float.parseFloat(readableData[2]);
|
|
|
h = Float.parseFloat(readableData[3]);
|
|
|
- } else if (line.equals("<key>textureRotated</key>")) {
|
|
|
- if (readableConfig[i+1].equals("<true/>")) {
|
|
|
+ } else if (line.contains("<key>textureRotated</key>")) {
|
|
|
+ if (readableConfig[i+1].contains("<true/>")) {
|
|
|
rotated = true;
|
|
|
} else {
|
|
|
rotated = false;
|
|
|
}
|
|
|
}
|
|
|
- else if (line.equals("</dict>")) {
|
|
|
+ else if (line.contains("</dict>")) {
|
|
|
ready = true;
|
|
|
}
|
|
|
- if (ready && !name.isBlank() && !new File(output.getPath() + "/" + name).exists()) {
|
|
|
+ if (ready && !name.isBlank()) {
|
|
|
BufferedImage crop;
|
|
|
try {
|
|
|
if (!rotated) {
|
|
@@ -56,7 +69,8 @@ public class TextureExtractor {
|
|
|
} else {
|
|
|
crop = rotate(image.getSubimage(round(x), round(y), round(h), round(w)));
|
|
|
}
|
|
|
- ImageIO.write(crop, "png", new File(output.getPath() + "/" + name));
|
|
|
+ File file = new File(output.getPath() + "/" + name);
|
|
|
+ ImageIO.write(crop, "png", file);
|
|
|
} catch (Exception e) {}
|
|
|
x=0; y=0; w=0; h=0; name = "";
|
|
|
}
|
|
@@ -76,4 +90,16 @@ public class TextureExtractor {
|
|
|
|
|
|
return output;
|
|
|
}
|
|
|
+
|
|
|
+ public static String removeLines(String s, int nb) {
|
|
|
+ String[] data = s.split("\n");
|
|
|
+ String newData = "";
|
|
|
+ for (int i = 0; i < data.length; i++) {
|
|
|
+ String st = data[i];
|
|
|
+ if (i >= nb) {
|
|
|
+ newData += st + "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return newData;
|
|
|
+ }
|
|
|
}
|