Better error messages
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user