Less hacky support for atrocious json

This commit is contained in:
Anuken
2019-11-22 15:33:01 -05:00
parent 2c61fcdfa6
commit 6d6fac00d7
6 changed files with 14 additions and 27 deletions

View File

@@ -365,22 +365,13 @@ public class ContentParser{
init();
}
JsonValue value;
try{
//try to read hjson, bail out if it doesn't work
value = parser.fromJson(null, Jval.read(json).toString(Jformat.plain));
}catch(Throwable t){
try{
value = parser.fromJson(null, json);
}catch(Throwable extra){
if(t instanceof RuntimeException){
throw t;
}else{
throw new RuntimeException(t);
}
}
//remove extra # characters to make it valid json... apparently some people have *unquoted* # characters in their json
if(file.extension().equals("json")){
json = json.replace("#", "\\#");
}
JsonValue value = parser.fromJson(null, Jval.read(json).toString(Jformat.plain));
if(!parsers.containsKey(type)){
throw new SerializationException("No parsers for content type '" + type + "'");
}

View File

@@ -493,16 +493,7 @@ public class Mods implements Loadable{
throw new IllegalArgumentException("No mod.json found.");
}
//try to read as hjson if possible
String readString = metaf.readString();
try{
readString = Jval.read(readString).toString(Jformat.plain);
}catch(Throwable e){
e.printStackTrace();
readString = metaf.readString();
}
ModMeta meta = json.fromJson(ModMeta.class, readString);
ModMeta meta = json.fromJson(ModMeta.class, Jval.read(metaf.readString()).toString(Jformat.plain));
String camelized = meta.name.replace(" ", "");
String mainClass = meta.main == null ? camelized.toLowerCase() + "." + camelized + "Mod" : meta.main;
String baseName = meta.name.toLowerCase().replace(" ", "-");

View File

@@ -345,7 +345,7 @@ public class HudFragment extends Fragment{
@Remote(targets = Loc.both, forward = true, called = Loc.both)
public static void setPlayerTeamEditor(Player player, Team team){
if(state.isEditor()){
if(state.isEditor() && player != null){
player.setTeam(team);
}
}