mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-24 06:38:10 +07:00
Starting work on json content parsing
This commit is contained in:
@ -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());
|
||||
|
19
core/src/io/anuke/mindustry/mod/ContentParser.java
Normal file
19
core/src/io/anuke/mindustry/mod/ContentParser.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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<LoadedMod> loaded = new Array<>();
|
||||
private ObjectMap<Class<?>, 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<LoadedMod> all(){
|
||||
return loaded;
|
||||
|
@ -13,5 +13,7 @@ public enum ContentType{
|
||||
effect,
|
||||
zone,
|
||||
loadout,
|
||||
typeid
|
||||
typeid;
|
||||
|
||||
public static final ContentType[] all = values();
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=9f30453676bf2b582c01a46a60965305321dcb9d
|
||||
archash=d4519a9721927165850bfe3135ef6b095c990474
|
||||
|
Reference in New Issue
Block a user