From fe3f75f141762d1924240fe2ff11374c7c7c384f Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 28 Sep 2019 23:58:30 -0400 Subject: [PATCH] Starting work on json content parsing --- .../io/anuke/mindustry/ClientLauncher.java | 2 ++ .../io/anuke/mindustry/mod/ContentParser.java | 19 ++++++++++++++ core/src/io/anuke/mindustry/mod/Mods.java | 25 +++++++++++++++++++ .../io/anuke/mindustry/type/ContentType.java | 4 ++- gradle.properties | 2 +- 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 core/src/io/anuke/mindustry/mod/ContentParser.java diff --git a/core/src/io/anuke/mindustry/ClientLauncher.java b/core/src/io/anuke/mindustry/ClientLauncher.java index ed927b1605..58509632d5 100644 --- a/core/src/io/anuke/mindustry/ClientLauncher.java +++ b/core/src/io/anuke/mindustry/ClientLauncher.java @@ -63,6 +63,8 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform assets.loadRun("contentcreate", Content.class, () -> { content.createContent(); content.loadColors(); + + mods.loadContent(); }); add(logic = new Logic()); diff --git a/core/src/io/anuke/mindustry/mod/ContentParser.java b/core/src/io/anuke/mindustry/mod/ContentParser.java new file mode 100644 index 0000000000..e802313019 --- /dev/null +++ b/core/src/io/anuke/mindustry/mod/ContentParser.java @@ -0,0 +1,19 @@ +package io.anuke.mindustry.mod; + +import io.anuke.mindustry.game.*; +import io.anuke.mindustry.type.*; + +public class ContentParser{ + + /** + * Parses content from a json file. + * @param name the name of the file without its extension + * @param json the json to parse + * @param type the type of content this is + * @return the content that was parsed + */ + public Content parse(String name, String json, ContentType type) throws Exception{ + + return null; + } +} diff --git a/core/src/io/anuke/mindustry/mod/Mods.java b/core/src/io/anuke/mindustry/mod/Mods.java index 8f7017adf2..219914b90f 100644 --- a/core/src/io/anuke/mindustry/mod/Mods.java +++ b/core/src/io/anuke/mindustry/mod/Mods.java @@ -6,6 +6,7 @@ import io.anuke.arc.files.*; import io.anuke.arc.function.*; import io.anuke.arc.util.*; import io.anuke.arc.util.serialization.*; +import io.anuke.mindustry.type.*; import java.io.*; import java.net.*; @@ -16,6 +17,7 @@ public class Mods{ private Json json = new Json(); private Array loaded = new Array<>(); private ObjectMap, ModMeta> metas = new ObjectMap<>(); + private ContentParser parser = new ContentParser(); private boolean requiresRestart; /** Returns a file named 'config.json' in a special folder for the specified plugin. @@ -79,6 +81,29 @@ public class Mods{ filet.buildFiles(loaded); } + /** Creates all the content found in mod files. */ + public void loadContent(){ + for(LoadedMod mod : loaded){ + if(mod.root.child("content").exists()){ + FileHandle contentRoot = mod.root.child("content"); + for(ContentType type : ContentType.all){ + FileHandle folder = contentRoot.child(type.name()); + if(folder.exists()){ + for(FileHandle file : folder.list()){ + if(file.extension().equals("json")){ + try{ + parser.parse(file.nameWithoutExtension(), file.readString(), type); + }catch(Exception e){ + throw new RuntimeException("Failed to parse content file '" + file + "' for mod '" + mod.meta.name + "'.", e); + } + } + } + } + } + } + } + } + /** @return all loaded mods. */ public Array all(){ return loaded; diff --git a/core/src/io/anuke/mindustry/type/ContentType.java b/core/src/io/anuke/mindustry/type/ContentType.java index 31ddcf35d2..f6b980a5d5 100644 --- a/core/src/io/anuke/mindustry/type/ContentType.java +++ b/core/src/io/anuke/mindustry/type/ContentType.java @@ -13,5 +13,7 @@ public enum ContentType{ effect, zone, loadout, - typeid + typeid; + + public static final ContentType[] all = values(); } diff --git a/gradle.properties b/gradle.properties index 5238d2620d..678dbb3d37 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=9f30453676bf2b582c01a46a60965305321dcb9d +archash=d4519a9721927165850bfe3135ef6b095c990474