Selaa lähdekoodia

move to gmd instead of wsliveeditor

tbvns 6 kuukautta sitten
vanhempi
commit
47e9e80c69

+ 18 - 0
pom.xml

@@ -82,6 +82,24 @@
             <artifactId>javafx-web</artifactId>
             <version>23-ea+18</version>
         </dependency>
+        <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+            <version>1.17.1</version>
+        </dependency>
+        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.17.0</version>
+        </dependency>
+        <!-- https://mvnrepository.com/artifact/com.jcraft/jzlib -->
+        <dependency>
+            <groupId>com.jcraft</groupId>
+            <artifactId>jzlib</artifactId>
+            <version>1.1.3</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 3 - 0
src/main/java/module-info.java

@@ -6,6 +6,9 @@ module xyz.tbvns.gd3dfx {
     requires org.joml;
     requires org.java_websocket;
     requires javafx.web;
+    requires org.apache.commons.codec;
+    requires jzlib;
+    requires org.apache.commons.io;
 
     opens xyz.tbvns to javafx.fxml;
     exports xyz.tbvns;

+ 7 - 6
src/main/java/xyz/tbvns/Generate/Generate3D.java

@@ -1,5 +1,6 @@
 package xyz.tbvns.Generate;
 
+import javafx.stage.Window;
 import org.joml.Vector3d;
 import org.joml.Vector4d;
 import org.joml.Vector4f;
@@ -22,7 +23,7 @@ public class Generate3D {
         if (Constant.isReady) {
             try {
                 if (Constant.useKeyframe) {
-                    new Generate3D().GenerateAnimKeyframe();
+                    //new Generate3D().GenerateAnimKeyframe();
                 } else {
                     new Generate3D().GenerateAnimMove();
                 }
@@ -77,10 +78,10 @@ public class Generate3D {
         Constant.points3d = new ArrayList<>();
         Constant.faces = new ArrayList<>();
         Constant.points = new ArrayList<>();
-        GDObject.request = new ArrayList<>();
+        GDObject.level = new ArrayList<>();
     }
 
-    public void GenerateAnimKeyframe() {
+    public void GenerateAnimKeyframe(Window window) {
         List<File> OBJs = new ArrayList<>();
         List<File> MTLs = new ArrayList<>();
 
@@ -182,9 +183,9 @@ public class Generate3D {
                 }
             }
 
-            GDObject.send();
+            GDObject.export(window);
 
-            GDObject.request = new ArrayList<>();
+            GDObject.level = new ArrayList<>();
         }
     }
 
@@ -270,7 +271,7 @@ public class Generate3D {
 
             GDObject.send();
 
-            GDObject.request = new ArrayList<>();
+            GDObject.level = new ArrayList<>();
         }
 
     }

+ 52 - 46
src/main/java/xyz/tbvns/GeometryDash/GDObject.java

@@ -1,92 +1,98 @@
 package xyz.tbvns.GeometryDash;
 
+import javafx.stage.FileChooser;
+import javafx.stage.Window;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import xyz.tbvns.Constant;
 import xyz.tbvns.WebSocket.WSClient;
 
+import java.io.File;
 import java.net.URI;
 import java.util.ArrayList;
 
 public class GDObject {
-    public static ArrayList<String> request = new ArrayList<>();
+    private static final Logger log = LoggerFactory.getLogger(GDObject.class);
+    public static ArrayList<String> level = new ArrayList<>();
 
     public static void addBasic(Integer objID, Float posX, Float posY) {
-        String JSON =
-                "{\n" +
-                "  \"action\": \"ADD\",\n" +
-                "  \"objects\": \"1," + objID + ",2," + posX + ",3," + posY + "\"\n" +
-                "}";
-        request.add(JSON);
+        String lvlString ="1," + objID + ",2," + posX + ",3," + posY;
+        level.add(lvlString);
     }
 
     public static void addBasic(Integer objID, Float posX, Float posY, Integer groupe) {
-        String JSON =
-                "{\n" +
-                "  \"action\": \"ADD\",\n" +
-                "  \"objects\": \"1," + objID + ",2," + posX + ",3," + posY + ",57," + groupe + "\"\n" +
-                "}";
-        request.add(JSON);
+        String lvlString ="1," + objID + ",2," + posX + ",3," + posY + ",57," + groupe;
+        level.add(lvlString);
     }
 
     //public static void addGradient(Float posX, Float posY, Integer groupe) {
-    //    String JSON =
+    //    String lvlString =
     //            "{\n" +
     //                    "  \"action\": \"ADD\",\n" +
     //                    "  \"objects\": \"1," + 2903 + ",2," + posX + ",3," + posY + ",57," + groupe + "\"\n" +
     //                    "}";
-    //    new WSClient(URI.create("ws://127.0.0.1:1313"), JSON).run();
+    //    new WSClient(URI.create("ws://127.0.0.1:1313"), lvlString).run();
     //}
 
     public static void addMove(Float time, Integer Groupe, Float moveX, Float moveY, Float moveTime) {
-        String JSON =
-                "{\n" +
-                "  \"action\": \"ADD\",\n" +
-                "  \"objects\": \"1," + 901 + ",2," + time + ",3," + -1000 + ",10," + moveTime + ",28," + moveX + ",29," + moveY +",51," + Groupe + "\"\n" +
-                "}";
-        request.add(JSON);
+        String lvlString = "1," + 901 + ",2," + time + ",3," + -1000 + ",10," + moveTime + ",28," + moveX + ",29," + moveY +",51," + Groupe;
+        level.add(lvlString);
     }
 
     public static void addKeyframeTrigger() {
-        String JSON =
-                "{\n" +
-                        "  \"action\": \"ADD\",\n" +
-                        "  \"objects\": \"1," + 3033 + ",2," + 0 + ",3," + 150 + ",76," + 9999 + ",520," + 1 + ",521," + 1 + ",545," + 1 + ",522," + 1 + ",523," + 1 + ",546," + 1 + "\"\n" +
-                        "}";
-        request.add(JSON);
+        String lvlString ="1," + 3033 + ",2," + 0 + ",3," + 150 + ",76," + 9999 + ",520," + 1 + ",521," + 1 + ",545," + 1 + ",522," + 1 + ",523," + 1 + ",546," + 1;
+        level.add(lvlString);
     }
 
     public static void addGradient(Float posX, Float posY, Integer groupe, int p1, int p2 ,int p3, int p4, int id, int zorder, int colorID) {
-        String JSON =
-                "{\n" +
-                        "  \"action\": \"ADD\",\n" +
-                        "  \"objects\": \"1,2903,174,0,202,1,456,1,208,0,508,0,25," + zorder + ",209," + id + ",2," + posX + ",3," + posY + ",57," + groupe + ",203, " + p1 + ",204, " + p2 + ",205, " + p4 + ",206," + p3 + ",207,1,21," + colorID + ",22," + colorID + "\"\n" +
-                        "}";
-        request.add(JSON);
+        String lvlString = "1,2903,174,0,202,1,456,1,208,0,508,0,25," + zorder + ",209," + id + ",2," + posX + ",3," + posY + ",57," + groupe + ",203, " + p1 + ",204, " + p2 + ",205, " + p4 + ",206," + p3 + ",207,1,21," + colorID + ",22," + colorID;
+        level.add(lvlString);
     }
 
     public static void addColor(Float posX, Float posY, int r, int g, int b, int targetColor) {
-        String JSON =
-                "{\n" +
-                        "  \"action\": \"ADD\",\n" +
-                        "  \"objects\": \"1,899,2," + posX + ",3," + posY + ",7," + r + ",8," + g + ",9," + b + ",23," + targetColor + "\"\n" +
-                        "}";
-        request.add(JSON);
+        String lvlString = "1,899,2," + posX + ",3," + posY + ",7," + r + ",8," + g + ",9," + b + ",23," + targetColor;
+        level.add(lvlString);
     }
 
     public static void addKeyframe(Float posX, Float posY, int groupeID, int curve, int order, float duration) {
-        String JSON =
-                   "{\n" +
-                   "  \"action\": \"ADD\",\n" +
-                   "  \"objects\": \"1,3032,2," + posX + ",3," + posY + ",51," + groupeID + ",373," + groupeID + ",57," + 9999 + ",378, " + curve + ",374," + order + ",10," + duration + "\"\n" +
-                   "}";
-        request.add(JSON);
+        String lvlString = "1,3032,2," + posX + ",3," + posY + ",51," + groupeID + ",373," + groupeID + ",57," + 9999 + ",378, " + curve + ",374," + order + ",10," + duration;
+        level.add(lvlString);
     }
 
+
+    /**
+     * @deprecated Support for WSLiveEditor is dropped until some issues are fixed
+     */
+    @Deprecated()
     public static void send() {
-        new WSClient(URI.create("ws://127.0.0.1:1313"), request).run();
+        new WSClient(URI.create("ws://127.0.0.1:1313"), level).run();
         try {
             Thread.sleep(Constant.placeDelay);
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         }
     }
+
+    @Deprecated()
+    public static void export(Window window) {
+        FileChooser chooser = new FileChooser();
+        File file = chooser.showSaveDialog(window);
+
+        if (file == null) {
+            return;
+        }
+
+        StringBuilder stringBuilder = new StringBuilder();
+        for (String s : level) {
+            stringBuilder.append(s);
+        }
+
+        try {
+            GDUtils.exportGMD(file.getName(), stringBuilder.toString(), file.getPath());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+    }
 }

+ 52 - 0
src/main/java/xyz/tbvns/GeometryDash/GDUtils.java

@@ -0,0 +1,52 @@
+package xyz.tbvns.GeometryDash;
+
+import com.jcraft.jzlib.JZlib;
+import javafx.stage.FileChooser;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.FileUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.InflaterInputStream;
+
+public class GDUtils {
+
+    public static final String defaultLevelSettings = "kA13,0,kA15,0,kA16,0,kA14,,kA6,0,kA7,0,kA25,0,kA17,0,kA18,0,kS39,0,kA2,0,kA3,0,kA8,0,kA4,0,kA9,0,kA10,0,kA22,1,kA23,0,kA24,0,kA27,1,kA40,1,kA41,1,kA42,1,kA28,0,kA29,0,kA31,1,kA32,1,kA36,0,kA43,0,kA44,0,kA45,1,kA33,1,kA34,1,kA35,0,kA37,1,kA38,1,kA39,1,kA19,0,kA26,0,kA20,0,kA21,0,kA11,0;";
+
+    public static String decodeLevel(String levelStr) throws IOException {
+        byte[] levelData = Base64.decodeBase64(levelStr.getBytes(StandardCharsets.UTF_8));
+        ByteArrayInputStream inputStream = new ByteArrayInputStream(levelData);
+        GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream);
+
+        return new String(gzipInputStream.readAllBytes());
+    }
+
+    public static String encodeLevel(String levelStr) throws IOException {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);
+        gzipOutputStream.write(levelStr.getBytes(StandardCharsets.UTF_8));
+        gzipOutputStream.flush();
+        gzipOutputStream.finish();
+        gzipOutputStream.close();
+
+        byte[] levelData = java.util.Base64.getUrlEncoder().encode(outputStream.toByteArray());
+
+        return new String(levelData);
+    }
+
+    public static void exportGMD(String name, String data, String path) throws IOException, URISyntaxException {
+        String template = new String(GDUtils.class.getResourceAsStream("/template.gmd").readAllBytes());
+        template = template.replace("%name%", name).replace("%levelData%", data);
+        FileUtils.writeStringToFile(new File(path), template, StandardCharsets.UTF_8);
+    }
+}

+ 1 - 1
src/main/java/xyz/tbvns/JavaFX/FXui.java

@@ -529,7 +529,7 @@ public class FXui extends Application {
                 try {
                     if (Constant.isReady) {
                         if (Constant.useKeyframe) {
-                            new Generate3D().GenerateAnimKeyframe();
+                            new Generate3D().GenerateAnimKeyframe(stage.getOwner());
                         } else {
                             new Generate3D().GenerateAnimMove();
                         }

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

@@ -1,13 +1,17 @@
 package xyz.tbvns;
 
 import javafx.application.Platform;
+import xyz.tbvns.GeometryDash.GDUtils;
 import xyz.tbvns.JavaFX.FXui;
 import xyz.tbvns.WebSocket.CheckGDConnection;
 
+import java.io.IOException;
+import java.net.URISyntaxException;
+
 public class Main {
     public static FXui ui;
     public static Thread update = new Thread(new CheckGDConnection());
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException, URISyntaxException {
         update.start();
 
         ui = new FXui();

+ 76 - 0
src/main/resources/template.gmd

@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+<plist version="1.0" gjver="2.0">
+<dict>
+<k>kCEK</k>
+<i>4</i>
+<k>k18</k>
+<i>2</i>
+<k>k23</k>
+<i>5</i>
+<k>k2</k>
+<s>%name%</s>
+<k>k4</k>
+<s>%levelData%</s>
+<k>k5</k>
+<s>GD3D</s>
+<k>k101</k>
+<s>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</s>
+<k>k11</k>
+<i>4</i>
+<k>k13</k>
+<t/>
+<k>k21</k>
+<i>2</i>
+<k>k16</k>
+<i>1</i>
+<k>k80</k>
+<i>844</i>
+<k>k27</k>
+<i>4</i>
+<k>k45</k>
+<i>1167964</i>
+<k>k50</k>
+<i>42</i>
+<k>k47</k>
+<t/>
+<k>k48</k>
+<i>7</i>
+<k>kI1</k>
+<r>220</r>
+<k>kI2</k>
+<r>131.259</r>
+<k>kI3</k>
+<r>0.3</r>
+<k>kI6</k>
+<d>
+<k>0</k>
+<s>0</s>
+<k>1</k>
+<s>0</s>
+<k>2</k>
+<s>0</s>
+<k>3</k>
+<s>0</s>
+<k>4</k>
+<s>0</s>
+<k>5</k>
+<s>0</s>
+<k>6</k>
+<s>0</s>
+<k>7</k>
+<s>0</s>
+<k>8</k>
+<s>0</s>
+<k>9</k>
+<s>0</s>
+<k>10</k>
+<s>0</s>
+<k>11</k>
+<s>0</s>
+<k>12</k>
+<s>0</s>
+<k>13</k>
+<s>0</s>
+</d>
+</dict>
+</plist>