Bläddra i källkod

FINALLY! STUPID TEXTURES!
now i just need to change there size :(

____tbvns____ 6 månader sedan
förälder
incheckning
8f0b1286aa

+ 6 - 0
GD4J/src/main/java/xyz/tbvns/XmlUtils.java

@@ -55,6 +55,12 @@ public class XmlUtils {
                            .append(usableData.get(1))
                            .append("</" + usableData.get(2) + ">")
                            .append("\n");
+                } else if (line.equals("textureRotated")) {
+                    if (lines[i+1].equals("<true/>")) {
+                        newData.append("<textureRotated>true</textureRotated>\n");
+                    } else {
+                        newData.append("<textureRotated>false</textureRotated>\n");
+                    }
                 } else if (lines[i+1].equals("<dict>")) {
                     newData.append("<dict>\n")
                            .append("<name>" + line + "</name>\n");

+ 10 - 10
PowerGDEditor/src/main/java/xyz/tbvns/GeometryDash/LevelUtils.java

@@ -28,19 +28,19 @@ public class LevelUtils {
         for (Object object : Object.fromLevel(level)) {
             try {
                 System.out.println(object.getProperties());
-//                Model model = new ModelBuilder().createRect(
-//                        0f, 0f, 0f,
-//                        1f, 0f, 0f,
-//                        1f, 1f, 0f,
-//                        0, 1, 0f,
-//                        0, 0, 0,
-//                        TexturesManager.idMaterialMap.get(Integer.parseInt(object.getProperties().get("1"))),
-//                        VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates
-//                );
-                Model model = new ModelBuilder().createBox(1f, 1f, 0,
+                Model model = new ModelBuilder().createRect(
+                        0f, 0f, 0f,
+                        1f, 0f, 0f,
+                        1f, 1f, 0f,
+                        0, 1, 0f,
+                        0, 0, 0,
                         TexturesManager.idMaterialMap.get(Integer.parseInt(object.getProperties().get("1"))),
                         VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates
                 );
+//                Model model = new ModelBuilder().createBox(1f, 1f, 0,
+//                        TexturesManager.idMaterialMap.get(Integer.parseInt(object.getProperties().get("1"))),
+//                        VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates
+//                );
                 models.add(model);
                 modelCache.add(new ModelInstance(model, Float.parseFloat(object.getProperties().get("2")) / 30, Float.parseFloat(object.getProperties().get("3")) / 30, 0));
             } catch (Exception e){};

+ 101 - 42
PowerGDEditor/src/main/java/xyz/tbvns/GeometryDash/TextureExtractor.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.dataformat.xml.XmlFactory;
 import com.stanfy.gsonxml.GsonXml;
 import com.stanfy.gsonxml.GsonXmlBuilder;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.xml.sax.SAXException;
 import xyz.tbvns.XmlUtils;
@@ -14,67 +15,125 @@ import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import static java.lang.Math.round;
 
+@Slf4j
 public class TextureExtractor {
     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);
+        String config = XmlUtils.gamesheetToXML(removeLines(FileUtils.readFileToString(plist), 2));
+        System.out.println(config);
 
         BufferedImage image = ImageIO.read(textures);
         String[] readableConfig = config
                 .replace(" ", "")
                 .split("\n");
 
-        if (true) {
-            return;
+        List<TextureReference> textureReferences = new ArrayList<>();
+        TextureReference current = new TextureReference();
+        for (String s : readableConfig) {
+            if (s.equals("<dict>")) {
+                if (current.isValid()) textureReferences.add(current);
+                current = new TextureReference();
+            } else if (s.startsWith("<name>")) {
+                current.setName(
+                        s.replace("<name>", "")
+                         .replace("</name>", "")
+                );
+            } else if (s.startsWith("<textureRect>")) {
+                String[] usableString =
+                        s.replace("<textureRect>", "")
+                         .replace("</textureRect>", "")
+                         .replace("{", "")
+                         .replace("}", "")
+                         .split(",");
+                current.setX(Float.parseFloat(usableString[0]));
+                current.setY(Float.parseFloat(usableString[1]));
+                current.setW(Float.parseFloat(usableString[2]));
+                current.setH(Float.parseFloat(usableString[3]));
+            } else if (s.startsWith("<textureRotated>")) {
+                current.setRotated(
+                        Boolean.parseBoolean(
+                                s.replace("<textureRotated>", "")
+                                 .replace("</textureRotated>", "")
+                        )
+                );
+            }
         }
 
-        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.contains("<key>") && line.contains(".png</key>")) {
-                name = line.replace("<key>", "").replace("</key>", "");
-            }
-            else if (line.contains("<key>textureRect</key>")) {
-                String data = readableConfig[i+1];
-                String[] readableData = data
-                        .replace("<string>", "")
-                        .replace("</string>", "")
-                        .replace("}", "")
-                        .replace("{", "")
-                        .split(",");
-                x = Float.parseFloat(readableData[0]);
-                y = Float.parseFloat(readableData[1]);
-                w = Float.parseFloat(readableData[2]);
-                h = Float.parseFloat(readableData[3]);
-            } else if (line.contains("<key>textureRotated</key>")) {
-                if (readableConfig[i+1].contains("<true/>")) {
-                    rotated = true;
-                } else {
-                    rotated = false;
-                }
-            }
-            else if (line.contains("</dict>")) {
-                ready = true;
-            }
-            if (ready && !name.isBlank()) {
+        for (TextureReference reference : textureReferences) {
+            new Thread(() -> {
                 BufferedImage crop;
                 try {
-                    if (!rotated) {
-                        crop = image.getSubimage(round(x), round(y), round(w), round(h));
+                    if (!reference.isRotated()) {
+                        crop = image.getSubimage(
+                                round(reference.getX()),
+                                round(reference.getY()),
+                                round(reference.getW()),
+                                round(reference.getH())
+                        );
                     } else {
-                        crop = rotate(image.getSubimage(round(x), round(y), round(h), round(w)));
+                        crop = rotate(
+                                image.getSubimage(
+                                        round(reference.getX()),
+                                        round(reference.getY()),
+                                        round(reference.getH()),
+                                        round(reference.getW())
+                                )
+                        );
                     }
-                    File file = new File(output.getPath() + "/" + name);
+                    File file = new File(output.getPath() + "/" + reference.getName());
                     ImageIO.write(crop, "png", file);
-                } catch (Exception e) {}
-                x=0; y=0; w=0; h=0; name = "";
-            }
+                } catch (Exception e) {e.printStackTrace();}
+            }).start();
         }
+//
+//        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.contains("<key>") && line.contains(".png</key>")) {
+//                name = line.replace("<key>", "").replace("</key>", "");
+//            }
+//            else if (line.contains("<key>textureRect</key>")) {
+//                String data = readableConfig[i+1];
+//                String[] readableData = data
+//                        .replace("<string>", "")
+//                        .replace("</string>", "")
+//                        .replace("}", "")
+//                        .replace("{", "")
+//                        .split(",");
+//                x = Float.parseFloat(readableData[0]);
+//                y = Float.parseFloat(readableData[1]);
+//                w = Float.parseFloat(readableData[2]);
+//                h = Float.parseFloat(readableData[3]);
+//            } else if (line.contains("<key>textureRotated</key>")) {
+//                if (readableConfig[i+1].contains("<true/>")) {
+//                    rotated = true;
+//                } else {
+//                    rotated = false;
+//                }
+//            }
+//            else if (line.contains("</dict>")) {
+//                ready = true;
+//            }
+//            if (ready && !name.isBlank()) {
+//                BufferedImage crop;
+//                try {
+//                    if (!rotated) {
+//                        crop = image.getSubimage(round(x), round(y), round(w), round(h));
+//                    } else {
+//                        crop = rotate(image.getSubimage(round(x), round(y), round(h), round(w)));
+//                    }
+//                    File file = new File(output.getPath() + "/" + name);
+//                    ImageIO.write(crop, "png", file);
+//                } catch (Exception e) {}
+//                x=0; y=0; w=0; h=0; name = "";
+//            }
+//        }
     }
 
     public static BufferedImage rotate(BufferedImage src) {

+ 21 - 0
PowerGDEditor/src/main/java/xyz/tbvns/GeometryDash/TextureReference.java

@@ -0,0 +1,21 @@
+package xyz.tbvns.GeometryDash;
+
+import lombok.Data;
+
+@Data
+public class TextureReference {
+    private float x = -1;
+    private float y = -1;
+    private float w = -1;
+    private float h = -1;
+    private String name;
+    private boolean rotated = false;
+
+    public boolean isValid() {
+        return x!=-1 &&
+               y!=-1 &&
+               w!=-1 &&
+               h!=-1 &&
+               name!=null;
+    }
+}

+ 1 - 1
PowerGDEditor/src/main/java/xyz/tbvns/Main.java

@@ -68,7 +68,7 @@ public class Main extends ApplicationAdapter {
     public void render() {
         Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
         Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
-        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
+        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling ? GL20.GL_COVERAGE_BUFFER_BIT_NV : 0));
         Gdx.gl.glDisable(GL_CULL_FACE);
 
         viewport.setScreenPosition(200, 200);

+ 1 - 1
PowerGDEditor/src/main/java/xyz/tbvns/Managers/TexturesManager.java

@@ -31,7 +31,7 @@ public class TexturesManager {
             idFileMap.forEach((k, v) -> {
                 if (v.exists()) {
                     Texture texture = new Texture(
-                            Gdx.files.absolute(TexturesManager.idFileMap.get(k).getPath().replace("/", "\\"))
+                            Gdx.files.absolute(TexturesManager.idFileMap.get(k).getPath())
                     );
                     Material material = new Material(TextureAttribute.createDiffuse(texture), new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
                     idMaterialMap.put(k, material);

+ 4 - 4
PowerGDEditor/src/main/java/xyz/tbvns/Setup.java

@@ -20,10 +20,10 @@ public class Setup {
         if (!FilesManager.getTextureFolder().exists()) {
             try {
                 FilesManager.getTextureFolder().mkdir();
-                File plist = new File(FilesLocations.getGeometryDashResources() + "/GJ_GameSheet.plist");
-                File plist02 = new File(FilesLocations.getGeometryDashResources() + "/GJ_GameSheet02.plist");
-                File png = new File(FilesLocations.getGeometryDashResources() + "/GJ_GameSheet.png");
-                File png02 = new File(FilesLocations.getGeometryDashResources() + "/GJ_GameSheet02.png");
+                File plist = new File(FilesLocations.getGeometryDashResources() + "/GJ_GameSheet-uhd.plist");
+                File plist02 = new File(FilesLocations.getGeometryDashResources() + "/GJ_GameSheet02-uhd.plist");
+                File png = new File(FilesLocations.getGeometryDashResources() + "/GJ_GameSheet-uhd.png");
+                File png02 = new File(FilesLocations.getGeometryDashResources() + "/GJ_GameSheet02-uhd.png");
                 TextureExtractor.extract(plist, png, FilesManager.getTextureFolder());
                 TextureExtractor.extract(plist02, png02, FilesManager.getTextureFolder());
             } catch (Exception e) {