Json support for UnlockableContent fields
This commit is contained in:
@@ -56,6 +56,8 @@ import static mindustry.Vars.*;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class ContentParser{
|
public class ContentParser{
|
||||||
private static final boolean ignoreUnknownFields = true;
|
private static final boolean ignoreUnknownFields = true;
|
||||||
|
private static final ContentType[] typesToSearch = {ContentType.block, ContentType.item, ContentType.unit, ContentType.liquid, ContentType.planet};
|
||||||
|
|
||||||
ObjectMap<Class<?>, ContentType> contentTypes = new ObjectMap<>();
|
ObjectMap<Class<?>, ContentType> contentTypes = new ObjectMap<>();
|
||||||
ObjectSet<Class<?>> implicitNullable = ObjectSet.with(TextureRegion.class, TextureRegion[].class, TextureRegion[][].class, TextureRegion[][][].class);
|
ObjectSet<Class<?>> implicitNullable = ObjectSet.with(TextureRegion.class, TextureRegion[].class, TextureRegion[][].class, TextureRegion[][][].class);
|
||||||
ObjectMap<String, AssetDescriptor<?>> sounds = new ObjectMap<>();
|
ObjectMap<String, AssetDescriptor<?>> sounds = new ObjectMap<>();
|
||||||
@@ -397,6 +399,17 @@ public class ContentParser{
|
|||||||
return (T)new Rect(jsonData.get(0).asFloat(), jsonData.get(1).asFloat(), jsonData.get(2).asFloat(), jsonData.get(3).asFloat());
|
return (T)new Rect(jsonData.get(0).asFloat(), jsonData.get(1).asFloat(), jsonData.get(2).asFloat(), jsonData.get(3).asFloat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//search across different content types to find one by name
|
||||||
|
if(type == UnlockableContent.class){
|
||||||
|
for(ContentType c : typesToSearch){
|
||||||
|
T found = (T)locate(c, jsonData.asString());
|
||||||
|
if(found != null){
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("\"" + jsonData.name + "\": No content found with name '" + jsonData.asString() + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
if(Content.class.isAssignableFrom(type)){
|
if(Content.class.isAssignableFrom(type)){
|
||||||
ContentType ctype = contentTypes.getThrow(type, () -> new IllegalArgumentException("No content type for class: " + type.getSimpleName()));
|
ContentType ctype = contentTypes.getThrow(type, () -> new IllegalArgumentException("No content type for class: " + type.getSimpleName()));
|
||||||
String prefix = currentMod != null ? currentMod.name + "-" : "";
|
String prefix = currentMod != null ? currentMod.name + "-" : "";
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ org.gradle.caching=true
|
|||||||
#used for slow jitpack builds; TODO see if this actually works
|
#used for slow jitpack builds; TODO see if this actually works
|
||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
archash=ea8fa3b50d
|
archash=21508dc509
|
||||||
|
|||||||
Reference in New Issue
Block a user