Updated AddonscriptJSON format

This commit is contained in:
Timo Ley 2020-05-18 11:51:42 +02:00
parent 8e16457e6c
commit 067994b705
3 changed files with 21 additions and 38 deletions

View file

@ -9,12 +9,13 @@ sourceCompatibility = 1.8
repositories { repositories {
mavenCentral() mavenCentral()
maven { url 'https://jitpack.io' }
} }
dependencies { dependencies {
compile 'com.google.code.gson:gson:+' compile 'com.google.code.gson:gson:+'
compile 'org.apache.maven:maven-core:+' compile 'org.apache.maven:maven-core:+'
compile 'org.python:jython:2.7.0' compile 'org.python:jython:2.7.0'
compile "com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"
testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'junit', name: 'junit', version: '4.12'
} }

View file

@ -3,13 +3,12 @@ package ley.anvil.addonscript.util;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import java.util.ArrayList; import java.io.Reader;
import java.util.List; import java.io.Writer;
import java.util.stream.Collectors;
public abstract class JSON { public abstract class JSON {
public static Gson gson = new GsonBuilder().create(); public static Gson gson = new GsonBuilder().setPrettyPrinting().create();
public String toJSON() { public String toJSON() {
return gson.toJson(this); return gson.toJson(this);
@ -20,14 +19,16 @@ public abstract class JSON {
return toJSON(); return toJSON();
} }
public String toFormattedJSON() { public void write(Writer writer) {
return formatJSON(toJSON()); gson.toJson(this, writer);
} }
public static <T> T read(Reader reader, Class<T> type) {
return gson.fromJson(reader, type);
}
public static String formatJSON(String json) { public static <T> T fromJSON(String json, Class<T> type) {
//TODO JSON formatting return gson.fromJson(json, type);
return json;
} }
} }

View file

@ -7,7 +7,7 @@ import java.util.List;
public class AddonscriptJSON extends JSON { public class AddonscriptJSON extends JSON {
public static AddonscriptJSON fromJSON(String json) { public static AddonscriptJSON fromJSON(String json) {
return gson.fromJson(json, AddonscriptJSON.class); return fromJSON(json, AddonscriptJSON.class);
} }
public static AddonscriptJSON create() { public static AddonscriptJSON create() {
@ -176,6 +176,14 @@ public class AddonscriptJSON extends JSON {
} }
public static class File { public static class File {
/**
* The ID of this file.
* If multiple files have the same ID,
* Addonscript will interpret this files as identical.
* Addonscript will then try to install the first of them
* and only if this fails, it will try the next.
*/
public String id;
/** /**
* The installer for this file * The installer for this file
* Format: <installerid>:<param 1>:<param 2>... * Format: <installerid>:<param 1>:<param 2>...
@ -219,12 +227,6 @@ public class AddonscriptJSON extends JSON {
* Supported type: included, required, recommended, optional or incompatible * Supported type: included, required, recommended, optional or incompatible
*/ */
public String type = "included"; public String type = "included";
/**
* Informations about the version of the addons
* Only useable when using a link to a Addonscript JSON file
*/
public VersionData version;
/** /**
* Meta information for this relation * Meta information for this relation
* This is not always useful, because some repositories, like curseforge, are * This is not always useful, because some repositories, like curseforge, are
@ -247,25 +249,4 @@ public class AddonscriptJSON extends JSON {
} }
/**
* Currently useless
*/
public static class VersionData {
public String version;
public int versionID;
public int minVersion;
public int maxVersion;
public boolean openUp;
public boolean openDown;
}
} }