Better error messages

This commit is contained in:
Anuken 2019-10-24 18:11:18 -04:00
parent 955dc5f48d
commit 5d7f14c21f
2 changed files with 16 additions and 4 deletions

View File

@ -128,11 +128,11 @@ public class ContentParser{
block = Vars.content.getByName(ContentType.block, name);
if(value.has("type")){
throw new IllegalArgumentException("When overwriting an existing block, you must not re-declared its type. The original type will be used. Block: " + name);
throw new IllegalArgumentException("When overwriting an existing block, you must not re-declare its type. The original type will be used. Block: " + name);
}
}else{
//TODO generate dynamically instead of doing.. this
Class<? extends Block> type = resolve(value.getString("type"),
Class<? extends Block> type = resolve(getType(value),
"io.anuke.mindustry.world",
"io.anuke.mindustry.world.blocks",
"io.anuke.mindustry.world.blocks.defense",
@ -209,7 +209,7 @@ public class ContentParser{
ContentType.unit, (TypeParser<UnitType>)(mod, name, value) -> {
readBundle(ContentType.unit, name, value);
Class<BaseUnit> type = resolve(value.getString("type"), "io.anuke.mindustry.entities.type.base");
Class<BaseUnit> type = resolve(getType(value), "io.anuke.mindustry.entities.type.base");
UnitType unit = new UnitType(mod + "-" + name, supply(type));
currentContent = unit;
read(() -> readFields(unit, value, true));
@ -222,6 +222,18 @@ public class ContentParser{
ContentType.zone, parser(ContentType.zone, Zone::new)
);
private String getString(JsonValue value, String key){
if(value.has(key)){
return value.getString(key);
}else{
throw new IllegalArgumentException((currentContent == null ? "" : currentContent.sourceFile + ": ") + "You are missing a \"" + key + "\". It must be added before the file can be parsed.");
}
}
private String getType(JsonValue value){
return getString(value, "type");
}
private <T extends Content> T find(ContentType type, String name){
Content c = Vars.content.getByName(type, name);
if(c == null) c = Vars.content.getByName(type, currentMod.name + "-" + name);

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=411d2784f538dfc10db2962a62833938029dafdd
archash=6ca636f2f51352022b2c770deafc3b549eb0421c