Skip to content

Commit

Permalink
JSON planet cloudMesh/HexSkyMesh support
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Apr 1, 2023
1 parent 4342454 commit 36e5522
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/src/mindustry/mod/ContentParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,21 @@ ContentType.status, parser(ContentType.status, StatusEffect::new),
};
}

if(value.has("cloudMesh")){
var mesh = value.get("cloudMesh");
if(!mesh.isObject()) throw new RuntimeException("Meshes must be objects.");
value.remove("cloudMesh");
planet.cloudMeshLoader = () -> {
//don't crash, just log an error
try{
return parseMesh(planet, mesh);
}catch(Exception e){
Log.err(e);
return null;
}
};
}

//always one sector right now...
planet.sectors.add(new Sector(planet, Ptile.empty));

Expand Down Expand Up @@ -835,6 +850,10 @@ private GenericMesh parseMesh(Planet planet, JsonValue data){
Color.valueOf(data.getString("color2", data.getString("color", "ffffff"))),
data.getInt("colorOct", 1), data.getFloat("colorPersistence", 0.5f), data.getFloat("colorScale", 1f),
data.getFloat("colorThreshold", 0.5f));
case "HexSkyMesh" -> new HexSkyMesh(planet,
data.getInt("seed", 0), data.getFloat("speed", 0), data.getFloat("radius", 1f),
data.getInt("divisions", 3), Color.valueOf(data.getString("color", "ffffff")), data.getInt("octaves", 1),
data.getFloat("persistence", 0.5f), data.getFloat("scale", 1f), data.getFloat("thresh", 0.5f));
case "MultiMesh" -> new MultiMesh(parser.readValue(GenericMesh[].class, data.get("meshes")));
case "MatMesh" -> new MatMesh(parser.readValue(GenericMesh.class, data.get("mesh")), parser.readValue(Mat3D.class, data.get("mat")));
default -> throw new RuntimeException("Unknown mesh type: " + tname);
Expand Down

0 comments on commit 36e5522

Please sign in to comment.