Merge branch 'master' into mod-dependencies

This commit is contained in:
MEEPofFaith
2024-08-19 02:09:41 -07:00
195 changed files with 6964 additions and 4228 deletions

View File

@@ -146,6 +146,11 @@ public class ContentParser{
readFields(result, data);
return result;
});
put(MassDriverBolt.class, (type, data) -> {
MassDriverBolt result = (MassDriverBolt)make(MassDriverBolt.class);
readFields(result, data);
return result;
});
put(AmmoType.class, (type, data) -> {
//string -> item
//if liquid ammo support is added, this should scan for liquids as well
@@ -322,6 +327,20 @@ public class ContentParser{
readFields(consume, data);
return consume;
});
put(Team.class, (type, data) -> {
if(data.isString()){
Team out = Structs.find(Team.baseTeams, t -> t.name.equals(data.asString()));
if(out == null) throw new IllegalArgumentException("Unknown team: " + data.asString());
return out;
}else if(data.isNumber()){
if(data.asInt() >= Team.all.length || data.asInt() < 0){
throw new IllegalArgumentException("Unknown team: " + data.asString());
}
return Team.get(data.asInt());
}else{
throw new IllegalArgumentException("Unknown team: " + data.asString() + ". Team must either be a string or a number.");
}
});
}};
/** Stores things that need to be parsed fully, e.g. reading fields of content.
* This is done to accommodate binding of content names first.*/
@@ -462,6 +481,7 @@ public class ContentParser{
case "itemFlammable" -> block.consume((Consume)parser.readValue(ConsumeItemFlammable.class, child));
case "itemRadioactive" -> block.consume((Consume)parser.readValue(ConsumeItemRadioactive.class, child));
case "itemExplosive" -> block.consume((Consume)parser.readValue(ConsumeItemExplosive.class, child));
case "itemList" -> block.consume((Consume)parser.readValue(ConsumeItemList.class, child));
case "itemExplode" -> block.consume((Consume)parser.readValue(ConsumeItemExplode.class, child));
case "items" -> block.consume(child.isArray() ?
new ConsumeItems(parser.readValue(ItemStack[].class, child)) :
@@ -668,6 +688,27 @@ public class ContentParser{
currentContent = planet;
read(() -> readFields(planet, value));
return planet;
},
ContentType.team, (TypeParser<TeamEntry>)(mod, name, value) -> {
TeamEntry entry;
Team team;
if(value.has("team")){
team = (Team)classParsers.get(Team.class).parse(Team.class, value.get("team"));
}else{
throw new RuntimeException("Team field missing.");
}
value.remove("team");
if(locate(ContentType.team, name) != null){
entry = locate(ContentType.team, name);
readBundle(ContentType.team, name, value);
}else{
readBundle(ContentType.team, name, value);
entry = new TeamEntry(mod + "-" + name, team);
}
currentContent = entry;
read(() -> readFields(entry, value));
return entry;
}
);
@@ -949,6 +990,8 @@ public class ContentParser{
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 "mod" -> base.mod(data.getFloat("amount"));
case "loop" -> base.loop(data.getFloat("time"));
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.");
};
@@ -1054,17 +1097,25 @@ public class ContentParser{
}
Field field = metadata.field;
try{
boolean mergeMap = ObjectMap.class.isAssignableFrom(field.getType()) && child.has("add") && child.get("add").isBoolean() && child.getBoolean("add", false);
boolean isMap = ObjectMap.class.isAssignableFrom(field.getType()) || ObjectIntMap.class.isAssignableFrom(field.getType()) || ObjectFloatMap.class.isAssignableFrom(field.getType());
boolean mergeMap = isMap && child.has("add") && child.get("add").isBoolean() && child.getBoolean("add", false);
if(mergeMap){
child.remove("add");
}
Object readField = parser.readValue(field.getType(), metadata.elementType, child, metadata.keyType);
Object fieldObj = field.get(object);
//if a map has add: true, add its contents to the map instead
if(mergeMap && field.get(object) instanceof ObjectMap<?,?> baseMap){
baseMap.putAll((ObjectMap)readField);
if(mergeMap && (fieldObj instanceof ObjectMap<?,?> || fieldObj instanceof ObjectIntMap<?> || fieldObj instanceof ObjectFloatMap<?>)){
if(field.get(object) instanceof ObjectMap<?,?> baseMap){
baseMap.putAll((ObjectMap)readField);
}else if(field.get(object) instanceof ObjectIntMap<?> baseMap){
baseMap.putAll((ObjectIntMap)readField);
}else if(field.get(object) instanceof ObjectFloatMap<?> baseMap){
baseMap.putAll((ObjectFloatMap)readField);
}
}else{
field.set(object, readField);
}

View File

@@ -871,6 +871,11 @@ public class Mods implements Loadable{
Seq<LoadRun> runs = new Seq<>();
for(LoadedMod mod : orderedMods()){
Seq<LoadRun> unorderedContent = new Seq<>();
ObjectMap<String, LoadRun> orderedContent = new ObjectMap<>();
String[] contentOrder = mod.meta.contentOrder;
ObjectSet<String> orderSet = contentOrder == null ? null : ObjectSet.with(contentOrder);
if(mod.root.child("content").exists()){
Fi contentRoot = mod.root.child("content");
for(ContentType type : ContentType.all){
@@ -878,15 +883,34 @@ public class Mods implements Loadable{
Fi folder = contentRoot.child(lower + (lower.endsWith("s") ? "" : "s"));
if(folder.exists()){
for(Fi file : folder.findAll(f -> f.extension().equals("json") || f.extension().equals("hjson"))){
runs.add(new LoadRun(type, file, mod));
//if this is part of the ordered content, put it aside to be dealt with later
if(orderSet != null && orderSet.contains(file.nameWithoutExtension())){
orderedContent.put(file.nameWithoutExtension(), new LoadRun(type, file, mod));
}else{
unorderedContent.add(new LoadRun(type, file, mod));
}
}
}
}
}
//ordered content will be loaded first, if it exists
if(contentOrder != null){
for(String contentName : contentOrder){
LoadRun run = orderedContent.get(contentName);
if(run != null){
runs.add(run);
}else{
Log.warn("Cannot find content defined in contentOrder: @", contentName);
}
}
}
//unordered content is sorted alphabetically per mod
runs.addAll(unorderedContent.sort());
}
//make sure mod content is in proper order
runs.sort();
for(LoadRun l : runs){
Content current = content.getLastAdded();
try{
@@ -1357,6 +1381,8 @@ public class Mods implements Loadable{
public float texturescale = 1.0f;
/** If true, bleeding is skipped and no content icons are generated. */
public boolean pregenerated;
/** If set, load the mod content in this order by content names */
public String[] contentOrder;
public String displayName(){
//useless, kept for legacy reasons