Chained PartProgress Operation in Json (#8627)
* Op parsing method * Parse multi op * Big brain * Parse operation array * Error wording * Unnecessary code
This commit is contained in:
@@ -190,32 +190,33 @@ public class ContentParser{
|
||||
data.has("operation") ? data.get("operation") :
|
||||
data.has("op") ? data.get("op") : null;
|
||||
|
||||
//no operations I guess (why would you do this?)
|
||||
//no singular operation, check for multi-operation
|
||||
if(opval == null){
|
||||
JsonValue opsVal =
|
||||
data.has("operations") ? data.get("operations") :
|
||||
data.has("ops") ? data.get("ops") : null;
|
||||
|
||||
if(opsVal != null){
|
||||
if(!opsVal.isArray()) throw new RuntimeException("Chained PartProgress operations must be an array.");
|
||||
int i = 0;
|
||||
while(true){
|
||||
JsonValue val = opsVal.get(i);
|
||||
if(val == null) break;
|
||||
JsonValue op = val.has("operation") ? val.get("operation") :
|
||||
val.has("op") ? val.get("op") : null;
|
||||
|
||||
base = parseProgressOp(base, op.asString(), val);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
//this is the name of the method to call
|
||||
String op = opval.asString();
|
||||
|
||||
//I have to hard-code this, no easy way of getting parameter names, unfortunately
|
||||
return switch(op){
|
||||
case "inv" -> base.inv();
|
||||
case "slope" -> base.slope();
|
||||
case "clamp" -> base.clamp();
|
||||
case "delay" -> base.delay(data.getFloat("amount"));
|
||||
case "sustain" -> base.sustain(data.getFloat("offset", 0f), data.getFloat("grow", 0f), data.getFloat("sustain"));
|
||||
case "shorten" -> base.shorten(data.getFloat("amount"));
|
||||
case "compress" -> base.compress(data.getFloat("start"), data.getFloat("end"));
|
||||
case "add" -> data.has("amount") ? base.add(data.getFloat("amount")) : base.add(parser.readValue(PartProgress.class, data.get("other")));
|
||||
case "blend" -> base.blend(parser.readValue(PartProgress.class, data.get("other")), data.getFloat("amount"));
|
||||
case "mul" -> data.has("amount") ? base.mul(data.getFloat("amount")) : base.mul(parser.readValue(PartProgress.class, data.get("other")));
|
||||
case "min" -> base.min(parser.readValue(PartProgress.class, data.get("other")));
|
||||
case "sin" -> base.sin(data.has("offset") ? data.getFloat("offset") : 0f, data.getFloat("scl"), data.getFloat("mag"));
|
||||
case "absin" -> base.absin(data.getFloat("scl"), data.getFloat("mag"));
|
||||
case "curve" -> data.has("interp") ? base.curve(parser.readValue(Interp.class, data.get("interp"))) : base.curve(data.getFloat("offset"), data.getFloat("duration"));
|
||||
default -> throw new RuntimeException("Unknown operation '" + op + "', check PartProgress class for a list of methods.");
|
||||
};
|
||||
return parseProgressOp(base, op, data);
|
||||
});
|
||||
put(PlanetGenerator.class, (type, data) -> {
|
||||
var result = new AsteroidGenerator(); //only one type for now
|
||||
@@ -875,6 +876,27 @@ public class ContentParser{
|
||||
};
|
||||
}
|
||||
|
||||
private PartProgress parseProgressOp(PartProgress base, String op, JsonValue data){
|
||||
//I have to hard-code this, no easy way of getting parameter names, unfortunately
|
||||
return switch(op){
|
||||
case "inv" -> base.inv();
|
||||
case "slope" -> base.slope();
|
||||
case "clamp" -> base.clamp();
|
||||
case "delay" -> base.delay(data.getFloat("amount"));
|
||||
case "sustain" -> base.sustain(data.getFloat("offset", 0f), data.getFloat("grow", 0f), data.getFloat("sustain"));
|
||||
case "shorten" -> base.shorten(data.getFloat("amount"));
|
||||
case "compress" -> base.compress(data.getFloat("start"), data.getFloat("end"));
|
||||
case "add" -> data.has("amount") ? base.add(data.getFloat("amount")) : base.add(parser.readValue(PartProgress.class, data.get("other")));
|
||||
case "blend" -> base.blend(parser.readValue(PartProgress.class, data.get("other")), data.getFloat("amount"));
|
||||
case "mul" -> data.has("amount") ? base.mul(data.getFloat("amount")) : base.mul(parser.readValue(PartProgress.class, data.get("other")));
|
||||
case "min" -> base.min(parser.readValue(PartProgress.class, data.get("other")));
|
||||
case "sin" -> base.sin(data.has("offset") ? data.getFloat("offset") : 0f, data.getFloat("scl"), data.getFloat("mag"));
|
||||
case "absin" -> base.absin(data.getFloat("scl"), data.getFloat("mag"));
|
||||
case "curve" -> data.has("interp") ? base.curve(parser.readValue(Interp.class, data.get("interp"))) : base.curve(data.getFloat("offset"), data.getFloat("duration"));
|
||||
default -> throw new RuntimeException("Unknown operation '" + op + "', check PartProgress class for a list of methods.");
|
||||
};
|
||||
}
|
||||
|
||||
<T> T make(Class<T> type){
|
||||
try{
|
||||
Constructor<T> cons = type.getDeclaredConstructor();
|
||||
|
||||
Reference in New Issue
Block a user