mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
Merge branch 'wave2/e2' into feat/irisapi-host
# Conflicts: # core/src/test/java/art/arcane/iris/core/project/SchemaBuilderParityTest.java
This commit is contained in:
commit
9e69f0666d
40 files changed
+1421
-477
No files matched your search
@@ -698,11 +698,11 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
|
||||
if (!typeToken.getRawType().isAnnotationPresent(Snippet.class)) {
|
||||
String snippetType = snippetFolder(typeToken.getRawType());
|
||||
if (snippetType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String snippetType = typeToken.getRawType().getDeclaredAnnotation(Snippet.class).value();
|
||||
String snippedBase = "snippet/" + snippetType + "/";
|
||||
|
||||
return new TypeAdapter<>() {
|
||||
@@ -752,6 +752,17 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
};
|
||||
}
|
||||
|
||||
/** The snippet folder of a class Iris's or a built-in module's {@code @Snippet} names, or null. */
|
||||
private static String snippetFolder(Class<?> type) {
|
||||
if (type.isAnnotationPresent(Snippet.class)) {
|
||||
return type.getDeclaredAnnotation(Snippet.class).value();
|
||||
}
|
||||
if (type.isAnnotationPresent(com.volmit.config.Snippet.class)) {
|
||||
return type.getDeclaredAnnotation(com.volmit.config.Snippet.class).value();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public KList<String> getPossibleSnippets(String f) {
|
||||
return possibleSnippets.computeIfAbsent(f, (k) -> {
|
||||
KList<String> l = new KList<>();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.data.cache.LazyBoundedCache;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
@@ -51,9 +52,12 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* the seed the palette's old {@code RNG} had.
|
||||
*/
|
||||
final class IrisBlockRegistry implements BlockRegistry {
|
||||
/** Enough for the palettes of a pack with their world seeds; seeds that differ per call (a placement's) wear out the oldest. */
|
||||
private static final int PALETTE_CACHE_SIZE = 256;
|
||||
|
||||
private final IrisData data;
|
||||
private final Map<BlockSpec, IrisBlockData> specs = new ConcurrentHashMap<>();
|
||||
private final Map<SeededPalette, PaletteSampler> palettes = new ConcurrentHashMap<>();
|
||||
private final LazyBoundedCache<SeededPalette, PaletteSampler> palettes = new LazyBoundedCache<>(PALETTE_CACHE_SIZE);
|
||||
|
||||
/** @param data the pack whose {@code blocks} folder custom blocks come from */
|
||||
IrisBlockRegistry(IrisData data) {
|
||||
|
||||
@@ -129,8 +129,11 @@ public final class IrisValues {
|
||||
return map;
|
||||
}
|
||||
|
||||
/** {@code style} as the generator style Iris builds noise from; a style name Iris does not know is flat. */
|
||||
static IrisGeneratorStyle generatorStyle(com.volmit.noise.NoiseStyle style) {
|
||||
/**
|
||||
* {@code style} as the generator style Iris builds noise from; a style name Iris does not know is flat. For behaviour that
|
||||
* reads Iris's generator itself, such as the cave carvers' signed 3D reads, which {@code PackResources.noise()} does not offer.
|
||||
*/
|
||||
public static IrisGeneratorStyle generatorStyle(com.volmit.noise.NoiseStyle style) {
|
||||
IrisGeneratorStyle iris = new IrisGeneratorStyle(irisStyle(style.style()));
|
||||
iris.setCellularFrequency(style.cellularFrequency());
|
||||
iris.setCellularZoom(style.cellularZoom());
|
||||
@@ -144,6 +147,16 @@ public final class IrisValues {
|
||||
return iris;
|
||||
}
|
||||
|
||||
/** {@code range} as the range Iris reads the same JSON into. */
|
||||
public static IrisRange range(Range range) {
|
||||
return new IrisRange(range.min(), range.max());
|
||||
}
|
||||
|
||||
/** {@code range} as the styled range Iris reads the same JSON into. */
|
||||
public static IrisStyledRange styledRange(StyledRange range) {
|
||||
return new IrisStyledRange(range.min(), range.max(), generatorStyle(range.style()));
|
||||
}
|
||||
|
||||
private static NoiseStyle irisStyle(String name) {
|
||||
try {
|
||||
return NoiseStyle.valueOf(name);
|
||||
|
||||
@@ -115,8 +115,13 @@ final class ModuleSchemaRenderer {
|
||||
return property;
|
||||
}
|
||||
|
||||
/** Whether the pack's modules describe the class {@code typeName}. */
|
||||
boolean describes(String typeName) {
|
||||
return schema.types().stream().anyMatch(type -> type.name().equals(typeName));
|
||||
}
|
||||
|
||||
/** The definition key of a settings class, built the first time a property names it. */
|
||||
private String definition(String typeName) {
|
||||
String definition(String typeName) {
|
||||
String key = DEFINITION_PREFIX + typeName.replace('.', '-').replace('$', '-').toLowerCase(Locale.ROOT);
|
||||
if (definitions.containsKey(key)) {
|
||||
return key;
|
||||
|
||||
@@ -81,6 +81,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -394,13 +395,7 @@ public class SchemaBuilder {
|
||||
|
||||
/** Iris's own definition of one of its classes that a built-in module's settings hold, as Iris's fields describe it. */
|
||||
private String hostDefinition(String typeName) {
|
||||
Class<?> type = hostType(typeName);
|
||||
String key = objectDefinitionKey(type);
|
||||
if (!definitions.containsKey(key)) {
|
||||
definitions.put(key, new JSONObject());
|
||||
definitions.put(key, buildProperties(type));
|
||||
}
|
||||
return key;
|
||||
return objectDefinition(hostType(typeName));
|
||||
}
|
||||
|
||||
private static Class<?> hostType(String typeName) {
|
||||
@@ -411,6 +406,24 @@ public class SchemaBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/** The definition key of a class an Iris field holds: the module's own description of a held type, else Iris's. */
|
||||
private String objectDefinition(Class<?> type) {
|
||||
if (isHeldType(type)) {
|
||||
return moduleSchemas().definition(type.getName());
|
||||
}
|
||||
String key = objectDefinitionKey(type);
|
||||
if (!definitions.containsKey(key)) {
|
||||
definitions.put(key, new JSONObject());
|
||||
definitions.put(key, buildProperties(type));
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
/** Whether a built-in module registered {@code type} because Iris's classes hold it, so its fields are the module's. */
|
||||
private boolean isHeldType(Class<?> type) {
|
||||
return type.isAnnotationPresent(com.volmit.config.Desc.class) && moduleSchemas().describes(type.getName());
|
||||
}
|
||||
|
||||
private static String objectDefinitionKey(Class<?> type) {
|
||||
return "obj-" + type.getCanonicalName().replaceAll("\\Q.\\E", "-").toLowerCase();
|
||||
}
|
||||
@@ -721,12 +734,7 @@ public class SchemaBuilder {
|
||||
}
|
||||
} else {
|
||||
fancyType = k.getType().getSimpleName().replaceAll("\\QIris\\E", "") + " (Object)";
|
||||
String key = objectDefinitionKey(k.getType());
|
||||
if (!definitions.containsKey(key)) {
|
||||
definitions.put(key, new JSONObject());
|
||||
definitions.put(key, buildProperties(k.getType()));
|
||||
}
|
||||
prop.put("$ref", "#/definitions/" + key);
|
||||
prop.put("$ref", "#/definitions/" + objectDefinition(k.getType()));
|
||||
}
|
||||
}
|
||||
case "array" -> {
|
||||
@@ -749,13 +757,8 @@ public class SchemaBuilder {
|
||||
case "number" -> fancyType = "List of Numbers";
|
||||
case "object" -> {
|
||||
fancyType = "List of " + t.type().getSimpleName().replaceAll("\\QIris\\E", "") + "s (Objects)";
|
||||
String key = objectDefinitionKey(t.type());
|
||||
if (!definitions.containsKey(key)) {
|
||||
definitions.put(key, new JSONObject());
|
||||
definitions.put(key, buildProperties(t.type()));
|
||||
}
|
||||
JSONObject items = new JSONObject();
|
||||
items.put("$ref", "#/definitions/" + key);
|
||||
items.put("$ref", "#/definitions/" + objectDefinition(t.type()));
|
||||
prop.put("items", items);
|
||||
}
|
||||
case "string" -> {
|
||||
@@ -868,16 +871,16 @@ public class SchemaBuilder {
|
||||
boolean present = !typeDesc.isBlank();
|
||||
if (present) d.add(typeDesc);
|
||||
|
||||
Snippet snippet = k.getType().getDeclaredAnnotation(Snippet.class);
|
||||
if (snippet == null) {
|
||||
Optional<String> snippetFolder = snippetFolder(k.getType());
|
||||
if (snippetFolder.isEmpty()) {
|
||||
ArrayType array = k.getType().getDeclaredAnnotation(ArrayType.class);
|
||||
if (array != null) {
|
||||
snippet = array.type().getDeclaredAnnotation(Snippet.class);
|
||||
snippetFolder = snippetFolder(array.type());
|
||||
}
|
||||
}
|
||||
|
||||
if (snippet != null) {
|
||||
String sm = snippet.value();
|
||||
if (snippetFolder.isPresent()) {
|
||||
String sm = snippetFolder.get();
|
||||
if (present) d.add(" ");
|
||||
d.add("You can instead specify \"snippet/" + sm + "/some-name.json\" to use a snippet file instead of specifying it here.");
|
||||
present = false;
|
||||
@@ -913,6 +916,16 @@ public class SchemaBuilder {
|
||||
return buildSnippet(prop, k.getType());
|
||||
}
|
||||
|
||||
/** The snippet folder of a class, as Iris's or the module's {@code @Snippet} names it. */
|
||||
private static Optional<String> snippetFolder(Class<?> type) {
|
||||
Snippet snippet = type.getDeclaredAnnotation(Snippet.class);
|
||||
if (snippet != null) {
|
||||
return Optional.of(snippet.value());
|
||||
}
|
||||
com.volmit.config.Snippet moduleSnippet = type.getDeclaredAnnotation(com.volmit.config.Snippet.class);
|
||||
return moduleSnippet == null ? Optional.empty() : Optional.of(moduleSnippet.value());
|
||||
}
|
||||
|
||||
private JSONObject buildSnippet(JSONObject prop, Class<?> type) {
|
||||
Snippet snippet = type.getDeclaredAnnotation(Snippet.class);
|
||||
if (snippet == null) return prop;
|
||||
@@ -980,15 +993,14 @@ public class SchemaBuilder {
|
||||
@NotNull
|
||||
private <T> String addEnum(Class<?> type, JSONObject prop, KList<String> description, T[] values, Function<T, String> function) {
|
||||
JSONArray a = new JSONArray();
|
||||
boolean advanced = type.isAnnotationPresent(Desc.class);
|
||||
boolean advanced = type.isAnnotationPresent(Desc.class) || type.isAnnotationPresent(com.volmit.config.Desc.class);
|
||||
for (T gg : values) {
|
||||
if (advanced) {
|
||||
try {
|
||||
JSONObject j = new JSONObject();
|
||||
String name = function.apply(gg);
|
||||
j.put("const", name);
|
||||
Desc dd = type.getField(name).getAnnotation(Desc.class);
|
||||
String desc = dd == null ? ("No Description for " + name) : dd.value();
|
||||
String desc = constantDescription(type, name);
|
||||
j.put("description", desc);
|
||||
j.put("x-intellij-html-description", desc.replace("\n", "<br>"));
|
||||
a.put(j);
|
||||
@@ -1013,6 +1025,16 @@ public class SchemaBuilder {
|
||||
return type.getSimpleName().replaceAll("\\QIris\\E", "");
|
||||
}
|
||||
|
||||
private static String constantDescription(Class<?> enumType, String name) throws NoSuchFieldException {
|
||||
Field constant = enumType.getField(name);
|
||||
Desc described = constant.getAnnotation(Desc.class);
|
||||
if (described != null) {
|
||||
return described.value();
|
||||
}
|
||||
com.volmit.config.Desc moduleDescribed = constant.getAnnotation(com.volmit.config.Desc.class);
|
||||
return moduleDescribed == null ? "No Description for " + name : moduleDescribed.value();
|
||||
}
|
||||
|
||||
private JSONObject buildBlockPropertyJson(PlatformBlockProperty property) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("type", property.jsonType());
|
||||
@@ -1087,7 +1109,8 @@ public class SchemaBuilder {
|
||||
return "object";
|
||||
}
|
||||
|
||||
if (!c.isAnnotationPresent(Desc.class) && c.getCanonicalName().startsWith("art.arcane.iris.")) {
|
||||
if (!c.isAnnotationPresent(Desc.class) && !c.isAnnotationPresent(com.volmit.config.Desc.class)
|
||||
&& c.getCanonicalName().startsWith("art.arcane.iris.")) {
|
||||
warnings.addIfMissing("Unsupported Type: " + c.getCanonicalName() + " Did you forget @Desc?");
|
||||
}
|
||||
|
||||
@@ -1109,6 +1132,10 @@ public class SchemaBuilder {
|
||||
return r.getDeclaredAnnotation(Desc.class).value();
|
||||
}
|
||||
|
||||
if (r.isAnnotationPresent(com.volmit.config.Desc.class)) {
|
||||
return r.getDeclaredAnnotation(com.volmit.config.Desc.class).value();
|
||||
}
|
||||
|
||||
if (!r.isPrimitive() && !r.equals(KList.class) && !r.equals(KMap.class) && r.getCanonicalName().startsWith("art.arcane.")) {
|
||||
warnings.addIfMissing("Missing @Desc on " + r.getSimpleName() + " in " + (r.getDeclaringClass() != null ? r.getDeclaringClass().getCanonicalName() : " NOSRC"));
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.core.structure.export;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.engine.framework.structure.CompiledStructureGraph;
|
||||
import art.arcane.iris.engine.framework.structure.PlanarJigsawWorkcellResolver;
|
||||
import art.arcane.iris.engine.framework.structure.StructureGraphCompilation;
|
||||
@@ -16,7 +17,6 @@ import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawWorkcellArchetyp
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlaceMode;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.math.IrisBlockVector;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
Reference in new issue
Block a user