Fixed #7713
This commit is contained in:
@@ -23,6 +23,7 @@ public class SectorPresets{
|
||||
captureWave = 10;
|
||||
difficulty = 1;
|
||||
overrideLaunchDefaults = true;
|
||||
noLighting = true;
|
||||
startWaveTimeMultiplier = 3f;
|
||||
}};
|
||||
|
||||
|
||||
@@ -83,10 +83,11 @@ public class Universe{
|
||||
}
|
||||
|
||||
if(state.hasSector() && state.getSector().planet.updateLighting){
|
||||
boolean disable = state.getSector().preset != null && state.getSector().preset.noLighting;
|
||||
var planet = state.getSector().planet;
|
||||
//update sector light
|
||||
float light = state.getSector().getLight();
|
||||
float alpha = Mathf.clamp(Mathf.map(light, planet.lightSrcFrom, planet.lightSrcTo, planet.lightDstFrom, planet.lightDstTo));
|
||||
float alpha = disable ? 1f : Mathf.clamp(Mathf.map(light, planet.lightSrcFrom, planet.lightSrcTo, planet.lightDstFrom, planet.lightDstTo));
|
||||
|
||||
//assign and map so darkness is not 100% dark
|
||||
state.rules.ambientLight.a = 1f - alpha;
|
||||
|
||||
@@ -218,26 +218,6 @@ public class ContentParser{
|
||||
readFields(result, data);
|
||||
return result;
|
||||
});
|
||||
put(GenericMesh.class, (type, data) -> {
|
||||
if(!data.isObject()) throw new RuntimeException("Meshes must be objects.");
|
||||
if(!(currentContent instanceof Planet planet)) throw new RuntimeException("Meshes can only be parsed as parts of planets.");
|
||||
|
||||
String tname = Strings.capitalize(data.getString("type", "NoiseMesh"));
|
||||
|
||||
return switch(tname){
|
||||
//TODO NoiseMesh is bad
|
||||
case "NoiseMesh" -> new NoiseMesh(planet,
|
||||
data.getInt("seed", 0), data.getInt("divisions", 1), data.getFloat("radius", 1f),
|
||||
data.getInt("octaves", 1), data.getFloat("persistence", 0.5f), data.getFloat("scale", 1f), data.getFloat("mag", 0.5f),
|
||||
Color.valueOf(data.getString("color1", data.getString("color", "ffffff"))),
|
||||
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 "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);
|
||||
};
|
||||
});
|
||||
put(Mat3D.class, (type, data) -> {
|
||||
if(data == null) return new Mat3D();
|
||||
|
||||
@@ -590,7 +570,18 @@ public class ContentParser{
|
||||
Planet planet = new Planet(name, parent, value.getFloat("radius", 1f), value.getInt("sectorSize", 0));
|
||||
|
||||
if(value.has("mesh")){
|
||||
planet.meshLoader = () -> parser.readValue(GenericMesh.class, value.get("mesh"));
|
||||
var mesh = value.get("mesh");
|
||||
if(!mesh.isObject()) throw new RuntimeException("Meshes must be objects.");
|
||||
value.remove("mesh");
|
||||
planet.meshLoader = () -> {
|
||||
//don't crash, just log an error
|
||||
try{
|
||||
return parseMesh(planet, mesh);
|
||||
}catch(Exception e){
|
||||
Log.err(e);
|
||||
return new ShaderSphereMesh(planet, Shaders.unlit, 2);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//always one sector right now...
|
||||
@@ -817,6 +808,24 @@ public class ContentParser{
|
||||
return null;
|
||||
}
|
||||
|
||||
private GenericMesh parseMesh(Planet planet, JsonValue data){
|
||||
String tname = Strings.capitalize(data.getString("type", "NoiseMesh"));
|
||||
|
||||
return switch(tname){
|
||||
//TODO NoiseMesh is bad
|
||||
case "NoiseMesh" -> new NoiseMesh(planet,
|
||||
data.getInt("seed", 0), data.getInt("divisions", 1), data.getFloat("radius", 1f),
|
||||
data.getInt("octaves", 1), data.getFloat("persistence", 0.5f), data.getFloat("scale", 1f), data.getFloat("mag", 0.5f),
|
||||
Color.valueOf(data.getString("color1", data.getString("color", "ffffff"))),
|
||||
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 "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);
|
||||
};
|
||||
}
|
||||
|
||||
<T> T make(Class<T> type){
|
||||
try{
|
||||
Constructor<T> cons = type.getDeclaredConstructor();
|
||||
|
||||
@@ -17,6 +17,7 @@ public class SectorPreset extends UnlockableContent{
|
||||
public float difficulty;
|
||||
public float startWaveTimeMultiplier = 2f;
|
||||
public boolean addStartingItems = false;
|
||||
public boolean noLighting = false;
|
||||
public boolean showSectorLandInfo = true;
|
||||
/** If true, uses this sector's launch fields instead */
|
||||
public boolean overrideLaunchDefaults = false;
|
||||
|
||||
Reference in New Issue
Block a user