mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 11:41:37 +00:00
Keep snippets in snippet/<type> only
- Drop the snippet/iris/<group>/<type> lookup, so a type has one folder again - Replace SnippetFolders and PackSnippets with SnippetFolder, which needs no disk discovery - Restore the schema pattern, palette path and validator signatures that only served the second folder - Trim the snippet tests to the single folder
This commit is contained in:
1 parent
3ada6c2639
commit
592e93a95e
21 files changed
+181
-490
No files matched your search
+2
-1
@@ -20,6 +20,7 @@ package art.arcane.iris.modded;
|
|||||||
|
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
import art.arcane.iris.pack.loading.ResourceLoader;
|
import art.arcane.iris.pack.loading.ResourceLoader;
|
||||||
|
import art.arcane.iris.pack.loading.SnippetFolder;
|
||||||
import art.arcane.iris.pack.schema.SchemaBuilder;
|
import art.arcane.iris.pack.schema.SchemaBuilder;
|
||||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||||
import art.arcane.iris.spi.IrisLogging;
|
import art.arcane.iris.spi.IrisLogging;
|
||||||
@@ -99,7 +100,7 @@ public final class ModdedWorkspaceGenerator {
|
|||||||
try {
|
try {
|
||||||
String snipType = snippetClass.getDeclaredAnnotation(Snippet.class).value();
|
String snipType = snippetClass.getDeclaredAnnotation(Snippet.class).value();
|
||||||
JSONObject entry = new JSONObject();
|
JSONObject entry = new JSONObject();
|
||||||
List<String> fileMatch = data.getSnippetFolders(snipType).workspaceFileMatches();
|
List<String> fileMatch = new SnippetFolder(snipType).workspaceFileMatches();
|
||||||
|
|
||||||
entry.put("fileMatch", new JSONArray(fileMatch.toArray()));
|
entry.put("fileMatch", new JSONArray(fileMatch.toArray()));
|
||||||
entry.put("url", "./.iris/schema/snippet/" + snipType + "-schema.json");
|
entry.put("url", "./.iris/schema/snippet/" + snipType + "-schema.json");
|
||||||
|
|||||||
@@ -19,8 +19,7 @@
|
|||||||
package art.arcane.iris.pack;
|
package art.arcane.iris.pack;
|
||||||
|
|
||||||
import art.arcane.iris.generation.terrain.IrisDimensionType;
|
import art.arcane.iris.generation.terrain.IrisDimensionType;
|
||||||
import art.arcane.iris.pack.loading.PackSnippets;
|
import art.arcane.iris.pack.loading.SnippetFolder;
|
||||||
import art.arcane.iris.pack.loading.SnippetFolders;
|
|
||||||
import art.arcane.iris.spi.IrisPlatforms;
|
import art.arcane.iris.spi.IrisPlatforms;
|
||||||
import art.arcane.iris.structure.object.IrisObjectScale;
|
import art.arcane.iris.structure.object.IrisObjectScale;
|
||||||
import art.arcane.iris.world.IrisWorldBoundary;
|
import art.arcane.iris.world.IrisWorldBoundary;
|
||||||
@@ -48,7 +47,6 @@ final class PackDimensionValidator {
|
|||||||
File regionsFolder = new File(packFolder, "regions");
|
File regionsFolder = new File(packFolder, "regions");
|
||||||
File biomesFolder = new File(packFolder, "biomes");
|
File biomesFolder = new File(packFolder, "biomes");
|
||||||
File dimensionsFolder = new File(packFolder, PackValidator.DIMENSIONS_FOLDER);
|
File dimensionsFolder = new File(packFolder, PackValidator.DIMENSIONS_FOLDER);
|
||||||
PackSnippets snippets = new PackSnippets(packFolder);
|
|
||||||
Set<String> dimensionKeys = new LinkedHashSet<>();
|
Set<String> dimensionKeys = new LinkedHashSet<>();
|
||||||
for (File dimensionFile : dimensionFiles) {
|
for (File dimensionFile : dimensionFiles) {
|
||||||
dimensionKeys.add(PackValidationIo.deriveKey(dimensionsFolder, dimensionFile));
|
dimensionKeys.add(PackValidationIo.deriveKey(dimensionsFolder, dimensionFile));
|
||||||
@@ -65,15 +63,15 @@ final class PackDimensionValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validateImportedStructurePolicy(dimensionKey, dimJson, blockingErrors, warnings);
|
validateImportedStructurePolicy(dimensionKey, dimJson, blockingErrors, warnings);
|
||||||
validateDimensionHeights(snippets, dimensionKey, dimJson, blockingErrors);
|
validateDimensionHeights(packFolder, dimensionKey, dimJson, blockingErrors);
|
||||||
validateBorrowedDimensionType(dimensionKey, dimJson, borrowedDimensionTypesSupported(), blockingErrors);
|
validateBorrowedDimensionType(dimensionKey, dimJson, borrowedDimensionTypesSupported(), blockingErrors);
|
||||||
validateSamplingStep(dimensionKey, dimJson, "terrainSamplingStep", 1, blockingErrors);
|
validateSamplingStep(dimensionKey, dimJson, "terrainSamplingStep", 1, blockingErrors);
|
||||||
validateSamplingStep(dimensionKey, dimJson, "caveDensitySamplingStep", 1, blockingErrors);
|
validateSamplingStep(dimensionKey, dimJson, "caveDensitySamplingStep", 1, blockingErrors);
|
||||||
validateSamplingStep(dimensionKey, dimJson, "biomeBoundsSamplingStep", 4, blockingErrors);
|
validateSamplingStep(dimensionKey, dimJson, "biomeBoundsSamplingStep", 4, blockingErrors);
|
||||||
validateWorldBoundary(dimensionKey, dimJson, blockingErrors);
|
validateWorldBoundary(dimensionKey, dimJson, blockingErrors);
|
||||||
validateStaticObjects(snippets, dimensionKey, dimJson, blockingErrors);
|
validateStaticObjects(packFolder, dimensionKey, dimJson, blockingErrors);
|
||||||
validateObjectScaleFactor(dimensionKey, dimJson, blockingErrors);
|
validateObjectScaleFactor(dimensionKey, dimJson, blockingErrors);
|
||||||
validateDimensionStack(snippets, dimensionKey, dimJson, dimensionKeys, blockingErrors);
|
validateDimensionStack(packFolder, dimensionKey, dimJson, dimensionKeys, blockingErrors);
|
||||||
validateUpperDimension(dimensionKey, dimJson, dimensionKeys, blockingErrors);
|
validateUpperDimension(dimensionKey, dimJson, dimensionKeys, blockingErrors);
|
||||||
|
|
||||||
JSONArray regionsArray = dimJson.optJSONArray("regions");
|
JSONArray regionsArray = dimJson.optJSONArray("regions");
|
||||||
@@ -179,7 +177,7 @@ final class PackDimensionValidator {
|
|||||||
+ minimum * 2 + ", " + minimum * 4 + ", or " + minimum * 8 + ".");
|
+ minimum * 2 + ", " + minimum * 4 + ", or " + minimum * 8 + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validateDimensionStack(PackSnippets snippets, String dimensionKey, JSONObject dimension, Set<String> dimensionKeys,
|
static void validateDimensionStack(File packFolder, String dimensionKey, JSONObject dimension, Set<String> dimensionKeys,
|
||||||
List<String> blockingErrors) {
|
List<String> blockingErrors) {
|
||||||
if (!dimension.has("dimensionStack")) {
|
if (!dimension.has("dimensionStack")) {
|
||||||
return;
|
return;
|
||||||
@@ -233,10 +231,10 @@ final class PackDimensionValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validateInteger(stack, "spacer", 0, 256, context, blockingErrors);
|
validateInteger(stack, "spacer", 0, 256, context, blockingErrors);
|
||||||
validateDimensionStackBlend(snippets, context, stack, blockingErrors);
|
validateDimensionStackBlend(packFolder, context, stack, blockingErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateDimensionStackBlend(PackSnippets snippets, String context, JSONObject stack,
|
private static void validateDimensionStackBlend(File packFolder, String context, JSONObject stack,
|
||||||
List<String> blockingErrors) {
|
List<String> blockingErrors) {
|
||||||
if (!stack.has("blend")) {
|
if (!stack.has("blend")) {
|
||||||
return;
|
return;
|
||||||
@@ -253,23 +251,22 @@ final class PackDimensionValidator {
|
|||||||
Object rawStyle = blend.opt("style");
|
Object rawStyle = blend.opt("style");
|
||||||
boolean styleObject = rawStyle instanceof JSONObject;
|
boolean styleObject = rawStyle instanceof JSONObject;
|
||||||
boolean styleSnippet = rawStyle instanceof String reference
|
boolean styleSnippet = rawStyle instanceof String reference
|
||||||
&& snippets.folders(STYLE_SNIPPET_TYPE).folders().stream()
|
&& new SnippetFolder(STYLE_SNIPPET_TYPE).holds(reference);
|
||||||
.anyMatch(folder -> reference.startsWith(folder + "/"));
|
|
||||||
if (!styleObject && !styleSnippet) {
|
if (!styleObject && !styleSnippet) {
|
||||||
blockingErrors.add(context + ".blend.style must be an object or style snippet reference.");
|
blockingErrors.add(context + ".blend.style must be an object or style snippet reference.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (styleSnippet) {
|
if (styleSnippet) {
|
||||||
validateDimensionStackStyleSnippet(
|
validateDimensionStackStyleSnippet(
|
||||||
snippets, context + ".blend.style", (String) rawStyle, blockingErrors);
|
packFolder, context + ".blend.style", (String) rawStyle, blockingErrors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateDimensionStackStyleSnippet(PackSnippets snippets, String context, String reference,
|
private static void validateDimensionStackStyleSnippet(File packFolder, String context, String reference,
|
||||||
List<String> blockingErrors) {
|
List<String> blockingErrors) {
|
||||||
try {
|
try {
|
||||||
SnippetFolders.Lookup snippet = snippets.find(STYLE_SNIPPET_TYPE, reference);
|
SnippetFolder.Lookup snippet = new SnippetFolder(STYLE_SNIPPET_TYPE).find(packFolder, reference);
|
||||||
if (!snippet.found()) {
|
if (!snippet.found()) {
|
||||||
blockingErrors.add(context + " references missing style snippet '" + reference + "'.");
|
blockingErrors.add(context + " references missing style snippet '" + reference + "'.");
|
||||||
return;
|
return;
|
||||||
@@ -283,18 +280,13 @@ final class PackDimensionValidator {
|
|||||||
|
|
||||||
static void validateStaticObjects(File packFolder, String dimensionKey, JSONObject dimension,
|
static void validateStaticObjects(File packFolder, String dimensionKey, JSONObject dimension,
|
||||||
List<String> blockingErrors) {
|
List<String> blockingErrors) {
|
||||||
validateStaticObjects(new PackSnippets(packFolder), dimensionKey, dimension, blockingErrors);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void validateStaticObjects(PackSnippets snippets, String dimensionKey, JSONObject dimension,
|
|
||||||
List<String> blockingErrors) {
|
|
||||||
if (!dimension.has("staticObjects")) {
|
if (!dimension.has("staticObjects")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject height = resolveDimensionHeight(snippets, dimension);
|
JSONObject height = resolveDimensionHeight(packFolder, dimension);
|
||||||
int minY = height == null ? -64 : (int) height.optDouble("min", 16D);
|
int minY = height == null ? -64 : (int) height.optDouble("min", 16D);
|
||||||
int maxY = height == null ? 320 : (int) height.optDouble("max", 32D);
|
int maxY = height == null ? 320 : (int) height.optDouble("max", 32D);
|
||||||
PackStaticObjectValidator.validate(snippets, dimensionKey, dimension, minY, maxY, blockingErrors);
|
PackStaticObjectValidator.validate(packFolder, dimensionKey, dimension, minY, maxY, blockingErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validateImportedStructurePolicy(String dimensionKey, JSONObject dimension,
|
static void validateImportedStructurePolicy(String dimensionKey, JSONObject dimension,
|
||||||
@@ -441,12 +433,12 @@ final class PackDimensionValidator {
|
|||||||
* the IrisDimension field initializer (-64..320); present-but-partial means the IrisRange field
|
* the IrisDimension field initializer (-64..320); present-but-partial means the IrisRange field
|
||||||
* initializers (min 16, max 32); logicalHeight absent means 256.
|
* initializers (min 16, max 32); logicalHeight absent means 256.
|
||||||
*/
|
*/
|
||||||
static void validateDimensionHeights(PackSnippets snippets, String dimensionKey, JSONObject dimJson, List<String> blockingErrors) {
|
static void validateDimensionHeights(File packFolder, String dimensionKey, JSONObject dimJson, List<String> blockingErrors) {
|
||||||
if (dimJson.has("dimensionHeight") && dimJson.isNull("dimensionHeight")) {
|
if (dimJson.has("dimensionHeight") && dimJson.isNull("dimensionHeight")) {
|
||||||
blockingErrors.add("Dimension '" + dimensionKey + "' dimensionHeight must be an object or a range snippet reference.");
|
blockingErrors.add("Dimension '" + dimensionKey + "' dimensionHeight must be an object or a range snippet reference.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject range = resolveDimensionHeight(snippets, dimJson);
|
JSONObject range = resolveDimensionHeight(packFolder, dimJson);
|
||||||
if (range == null && dimJson.has("dimensionHeight")) {
|
if (range == null && dimJson.has("dimensionHeight")) {
|
||||||
blockingErrors.add("Dimension '" + dimensionKey + "' dimensionHeight must be an object or a resolvable range snippet reference.");
|
blockingErrors.add("Dimension '" + dimensionKey + "' dimensionHeight must be an object or a resolvable range snippet reference.");
|
||||||
return;
|
return;
|
||||||
@@ -605,7 +597,7 @@ final class PackDimensionValidator {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JSONObject resolveDimensionHeight(PackSnippets snippets, JSONObject dimJson) {
|
private static JSONObject resolveDimensionHeight(File packFolder, JSONObject dimJson) {
|
||||||
if (!dimJson.has("dimensionHeight") || dimJson.isNull("dimensionHeight")) {
|
if (!dimJson.has("dimensionHeight") || dimJson.isNull("dimensionHeight")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -619,7 +611,7 @@ final class PackDimensionValidator {
|
|||||||
if (reference == null || !reference.startsWith("snippet/")) {
|
if (reference == null || !reference.startsWith("snippet/")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SnippetFolders.Lookup snippet = snippets.find(RANGE_SNIPPET_TYPE, reference);
|
SnippetFolder.Lookup snippet = new SnippetFolder(RANGE_SNIPPET_TYPE).find(packFolder, reference);
|
||||||
if (!snippet.found()) {
|
if (!snippet.found()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
package art.arcane.iris.pack;
|
package art.arcane.iris.pack;
|
||||||
|
|
||||||
import art.arcane.iris.pack.loading.PackSnippets;
|
import art.arcane.iris.pack.loading.SnippetFolder;
|
||||||
import art.arcane.iris.pack.loading.SnippetFolders;
|
|
||||||
import art.arcane.volmlib.util.json.JSONArray;
|
import art.arcane.volmlib.util.json.JSONArray;
|
||||||
import art.arcane.volmlib.util.json.JSONObject;
|
import art.arcane.volmlib.util.json.JSONObject;
|
||||||
|
|
||||||
@@ -97,7 +96,6 @@ final class PackGeneratorDuplicateValidator {
|
|||||||
if (!biomesFolder.isDirectory()) {
|
if (!biomesFolder.isDirectory()) {
|
||||||
return referenced;
|
return referenced;
|
||||||
}
|
}
|
||||||
PackSnippets snippets = new PackSnippets(packFolder);
|
|
||||||
for (File biomeFile : PackValidationIo.listJsonRecursive(biomesFolder)) {
|
for (File biomeFile : PackValidationIo.listJsonRecursive(biomesFolder)) {
|
||||||
JSONObject biome;
|
JSONObject biome;
|
||||||
try {
|
try {
|
||||||
@@ -113,7 +111,7 @@ final class PackGeneratorDuplicateValidator {
|
|||||||
JSONObject link = links.optJSONObject(i);
|
JSONObject link = links.optJSONObject(i);
|
||||||
if (link == null) {
|
if (link == null) {
|
||||||
String reference = links.optString(i, null);
|
String reference = links.optString(i, null);
|
||||||
link = resolveGeneratorLayerSnippet(snippets, reference);
|
link = resolveGeneratorLayerSnippet(packFolder, reference);
|
||||||
if (link == null) {
|
if (link == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -124,11 +122,11 @@ final class PackGeneratorDuplicateValidator {
|
|||||||
return referenced;
|
return referenced;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JSONObject resolveGeneratorLayerSnippet(PackSnippets snippets, String reference) {
|
private static JSONObject resolveGeneratorLayerSnippet(File packFolder, String reference) {
|
||||||
if (reference == null || !reference.startsWith("snippet/")) {
|
if (reference == null || !reference.startsWith("snippet/")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SnippetFolders.Lookup snippet = snippets.find(GENERATOR_SNIPPET_TYPE, reference);
|
SnippetFolder.Lookup snippet = new SnippetFolder(GENERATOR_SNIPPET_TYPE).find(packFolder, reference);
|
||||||
if (!snippet.found()) {
|
if (!snippet.found()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ import art.arcane.iris.generation.terrain.IrisRegion;
|
|||||||
import art.arcane.iris.generation.terrain.ShoreBiomeLineages;
|
import art.arcane.iris.generation.terrain.ShoreBiomeLineages;
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
import art.arcane.iris.pack.loading.IrisRegistrant;
|
import art.arcane.iris.pack.loading.IrisRegistrant;
|
||||||
import art.arcane.iris.pack.loading.PackSnippets;
|
import art.arcane.iris.pack.loading.SnippetFolder;
|
||||||
import art.arcane.iris.pack.loading.SnippetFolders;
|
|
||||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||||
import art.arcane.iris.spi.IrisLogging;
|
import art.arcane.iris.spi.IrisLogging;
|
||||||
import art.arcane.iris.spi.IrisPlatforms;
|
import art.arcane.iris.spi.IrisPlatforms;
|
||||||
@@ -86,11 +85,10 @@ final class PackHydrologyValidator {
|
|||||||
sortedDimensions.sort(Comparator.comparing(File::getPath));
|
sortedDimensions.sort(Comparator.comparing(File::getPath));
|
||||||
File dimensionsFolder = new File(packFolder, PackValidator.DIMENSIONS_FOLDER);
|
File dimensionsFolder = new File(packFolder, PackValidator.DIMENSIONS_FOLDER);
|
||||||
Findings findings = new Findings(errors, warnings);
|
Findings findings = new Findings(errors, warnings);
|
||||||
PackSnippets snippets = new PackSnippets(packFolder);
|
|
||||||
IrisData data = null;
|
IrisData data = null;
|
||||||
try {
|
try {
|
||||||
for (File dimensionFile : sortedDimensions) {
|
for (File dimensionFile : sortedDimensions) {
|
||||||
data = validateDimension(snippets, dimensionsFolder, dimensionFile, data, findings);
|
data = validateDimension(packFolder, dimensionsFolder, dimensionFile, data, findings);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
close(packFolder, data, errors);
|
close(packFolder, data, errors);
|
||||||
@@ -98,7 +96,7 @@ final class PackHydrologyValidator {
|
|||||||
return new Validation(errors, warnings);
|
return new Validation(errors, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IrisData validateDimension(PackSnippets snippets, File dimensionsFolder, File dimensionFile, IrisData data,
|
private static IrisData validateDimension(File packFolder, File dimensionsFolder, File dimensionFile, IrisData data,
|
||||||
Findings findings) {
|
Findings findings) {
|
||||||
List<String> errors = findings.errors();
|
List<String> errors = findings.errors();
|
||||||
JSONObject dimension = PackValidationIo.readJson(dimensionFile);
|
JSONObject dimension = PackValidationIo.readJson(dimensionFile);
|
||||||
@@ -111,7 +109,7 @@ final class PackHydrologyValidator {
|
|||||||
errors.add(path + " must be an object.");
|
errors.add(path + " must be an object.");
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
warnUnknownKeys(path, hydrology, IrisHydrology.class, snippets, findings.warnings());
|
warnUnknownKeys(path, hydrology, IrisHydrology.class, packFolder, findings.warnings());
|
||||||
if (!hydrology.optBoolean("enabled", false)) {
|
if (!hydrology.optBoolean("enabled", false)) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -121,13 +119,13 @@ final class PackHydrologyValidator {
|
|||||||
Set<String> fluids = fluidNames(hydrology);
|
Set<String> fluids = fluidNames(hydrology);
|
||||||
Set<String> seams = seamNames(hydrology);
|
Set<String> seams = seamNames(hydrology);
|
||||||
validateFluidReferences(path, hydrology, fluids, errors);
|
validateFluidReferences(path, hydrology, fluids, errors);
|
||||||
IrisData loaded = data == null ? IrisData.openDatapackCompiler(snippets.packFolder()) : data;
|
IrisData loaded = data == null ? IrisData.openDatapackCompiler(packFolder) : data;
|
||||||
IrisDimension loadedDimension = loaded.getDimensionLoader().load(dimensionKey, false);
|
IrisDimension loadedDimension = loaded.getDimensionLoader().load(dimensionKey, false);
|
||||||
if (loadedDimension == null) {
|
if (loadedDimension == null) {
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
warnMantleOff("Dimension '" + dimensionKey + "'", loadedDimension, findings.warnings());
|
warnMantleOff("Dimension '" + dimensionKey + "'", loadedDimension, findings.warnings());
|
||||||
validatePolicies(path, dimensionKey, loaded, loadedDimension, new PolicyFluids(fluids, seams), snippets, findings);
|
validatePolicies(path, dimensionKey, loaded, loadedDimension, new PolicyFluids(fluids, seams), errors, findings.warnings());
|
||||||
warnShoreBiomesWithoutWidth(dimensionKey, loaded, loadedDimension, findings.warnings());
|
warnShoreBiomesWithoutWidth(dimensionKey, loaded, loadedDimension, findings.warnings());
|
||||||
if (errors.size() == reported && validateCompile(path, loadedDimension, errors)) {
|
if (errors.size() == reported && validateCompile(path, loadedDimension, errors)) {
|
||||||
validateDecoratorBlocks(path, loaded, loadedDimension.getHydrology(), errors);
|
validateDecoratorBlocks(path, loaded, loadedDimension.getHydrology(), errors);
|
||||||
@@ -136,8 +134,8 @@ final class PackHydrologyValidator {
|
|||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void warnUnknownKeys(String field, Object value, Type type, PackSnippets snippets, List<String> warnings) {
|
static void warnUnknownKeys(String field, Object value, Type type, File packFolder, List<String> warnings) {
|
||||||
warnUnknownKeys(field, value, type, new KeyScan(snippets, warnings, new HashSet<>()));
|
warnUnknownKeys(field, value, type, new KeyScan(packFolder, warnings, new HashSet<>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void warnUnknownKeys(String field, Object value, Type type, KeyScan scan) {
|
private static void warnUnknownKeys(String field, Object value, Type type, KeyScan scan) {
|
||||||
@@ -175,8 +173,9 @@ final class PackHydrologyValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void warnUnknownSnippetKeys(String field, String reference, Class<?> type, KeyScan scan) {
|
private static void warnUnknownSnippetKeys(String field, String reference, Class<?> type, KeyScan scan) {
|
||||||
SnippetFolders.Lookup lookup = scan.snippets().find(type.getDeclaredAnnotation(Snippet.class).value(), reference);
|
SnippetFolder.Lookup lookup = new SnippetFolder(type.getDeclaredAnnotation(Snippet.class).value())
|
||||||
String snippet = lookup.found() ? lookup.key() : lookup.triedKeys().get(0);
|
.find(scan.packFolder(), reference);
|
||||||
|
String snippet = lookup.key();
|
||||||
if (!scan.activeSnippets().add(snippet)) {
|
if (!scan.activeSnippets().add(snippet)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -392,16 +391,14 @@ final class PackHydrologyValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void validatePolicies(String path, String dimensionKey, IrisData data, IrisDimension dimension, PolicyFluids fluids,
|
private static void validatePolicies(String path, String dimensionKey, IrisData data, IrisDimension dimension, PolicyFluids fluids,
|
||||||
PackSnippets snippets, Findings findings) {
|
List<String> errors, List<String> warnings) {
|
||||||
List<String> errors = findings.errors();
|
warnUnknownPolicyKeys("Dimension '" + dimensionKey + "'." + POLICY, dimension, data, warnings);
|
||||||
List<String> warnings = findings.warnings();
|
|
||||||
warnUnknownPolicyKeys("Dimension '" + dimensionKey + "'." + POLICY, dimension, snippets, warnings);
|
|
||||||
validatePolicy("Dimension '" + dimensionKey + "'." + POLICY, dimension.getHydrologyPolicy(), data, fluids, path, errors);
|
validatePolicy("Dimension '" + dimensionKey + "'." + POLICY, dimension.getHydrologyPolicy(), data, fluids, path, errors);
|
||||||
List<IrisRegion> regions = new ArrayList<>(dimension.getAllRegions(() -> data));
|
List<IrisRegion> regions = new ArrayList<>(dimension.getAllRegions(() -> data));
|
||||||
regions.sort(Comparator.comparing(IrisRegion::getLoadKey, Comparator.nullsFirst(Comparator.naturalOrder())));
|
regions.sort(Comparator.comparing(IrisRegion::getLoadKey, Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||||
for (IrisRegion region : regions) {
|
for (IrisRegion region : regions) {
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
warnUnknownPolicyKeys("Region '" + region.getLoadKey() + "'." + POLICY, region, snippets, warnings);
|
warnUnknownPolicyKeys("Region '" + region.getLoadKey() + "'." + POLICY, region, data, warnings);
|
||||||
validatePolicy("Region '" + region.getLoadKey() + "'." + POLICY, region.getHydrologyPolicy(), data, fluids, path, errors);
|
validatePolicy("Region '" + region.getLoadKey() + "'." + POLICY, region.getHydrologyPolicy(), data, fluids, path, errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,17 +406,17 @@ final class PackHydrologyValidator {
|
|||||||
biomes.sort(Comparator.comparing(IrisBiome::getLoadKey, Comparator.nullsFirst(Comparator.naturalOrder())));
|
biomes.sort(Comparator.comparing(IrisBiome::getLoadKey, Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||||
for (IrisBiome biome : biomes) {
|
for (IrisBiome biome : biomes) {
|
||||||
if (biome != null) {
|
if (biome != null) {
|
||||||
warnUnknownPolicyKeys("Biome '" + biome.getLoadKey() + "'." + POLICY, biome, snippets, warnings);
|
warnUnknownPolicyKeys("Biome '" + biome.getLoadKey() + "'." + POLICY, biome, data, warnings);
|
||||||
validatePolicy("Biome '" + biome.getLoadKey() + "'." + POLICY, biome.getHydrologyPolicy(), data, fluids, path, errors);
|
validatePolicy("Biome '" + biome.getLoadKey() + "'." + POLICY, biome.getHydrologyPolicy(), data, fluids, path, errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void warnUnknownPolicyKeys(String field, IrisRegistrant owner, PackSnippets snippets, List<String> warnings) {
|
private static void warnUnknownPolicyKeys(String field, IrisRegistrant owner, IrisData data, List<String> warnings) {
|
||||||
File file = owner.getLoadFile();
|
File file = owner.getLoadFile();
|
||||||
JSONObject json = file == null ? null : PackValidationIo.readJson(file);
|
JSONObject json = file == null ? null : PackValidationIo.readJson(file);
|
||||||
if (json != null) {
|
if (json != null) {
|
||||||
warnUnknownKeys(field, json.opt(POLICY), IrisHydrologyPolicy.class, snippets, warnings);
|
warnUnknownKeys(field, json.opt(POLICY), IrisHydrologyPolicy.class, data.getDataFolder(), warnings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,6 +623,6 @@ final class PackHydrologyValidator {
|
|||||||
private record Findings(List<String> errors, List<String> warnings) {
|
private record Findings(List<String> errors, List<String> warnings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private record KeyScan(PackSnippets snippets, List<String> warnings, Set<String> activeSnippets) {
|
private record KeyScan(File packFolder, List<String> warnings, Set<String> activeSnippets) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package art.arcane.iris.pack;
|
package art.arcane.iris.pack;
|
||||||
|
|
||||||
import art.arcane.iris.pack.loading.PackSnippets;
|
import art.arcane.iris.pack.loading.SnippetFolder;
|
||||||
import art.arcane.iris.pack.loading.SnippetFolders;
|
|
||||||
import art.arcane.iris.structure.object.IrisObjectPlacementScaleInterpolator;
|
import art.arcane.iris.structure.object.IrisObjectPlacementScaleInterpolator;
|
||||||
import art.arcane.iris.structure.object.IrisStaticObject;
|
import art.arcane.iris.structure.object.IrisStaticObject;
|
||||||
import art.arcane.volmlib.util.json.JSONArray;
|
import art.arcane.volmlib.util.json.JSONArray;
|
||||||
import art.arcane.volmlib.util.json.JSONObject;
|
import art.arcane.volmlib.util.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -19,7 +19,7 @@ final class PackStaticObjectValidator {
|
|||||||
private PackStaticObjectValidator() {
|
private PackStaticObjectValidator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validate(PackSnippets snippets, String dimensionKey, JSONObject dimension,
|
static void validate(File packFolder, String dimensionKey, JSONObject dimension,
|
||||||
int minY, int maxY, List<String> errors) {
|
int minY, int maxY, List<String> errors) {
|
||||||
if (!dimension.has("staticObjects")) {
|
if (!dimension.has("staticObjects")) {
|
||||||
return;
|
return;
|
||||||
@@ -30,7 +30,7 @@ final class PackStaticObjectValidator {
|
|||||||
errors.add(path + " must be an array.");
|
errors.add(path + " must be an array.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Path objectsRoot = snippets.packFolder().toPath().toAbsolutePath().normalize().resolve("objects");
|
Path objectsRoot = packFolder.toPath().toAbsolutePath().normalize().resolve("objects");
|
||||||
for (int index = 0; index < entries.length(); index++) {
|
for (int index = 0; index < entries.length(); index++) {
|
||||||
String entryPath = path + "[" + index + "]";
|
String entryPath = path + "[" + index + "]";
|
||||||
JSONObject entry = entries.optJSONObject(index);
|
JSONObject entry = entries.optJSONObject(index);
|
||||||
@@ -39,7 +39,7 @@ final class PackStaticObjectValidator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
validateObjectKey(entryPath, entry, objectsRoot, errors);
|
validateObjectKey(entryPath, entry, objectsRoot, errors);
|
||||||
validatePosition(snippets, entryPath, entry, minY, maxY, errors);
|
validatePosition(packFolder, entryPath, entry, minY, maxY, errors);
|
||||||
validateRotation(entryPath, entry, errors);
|
validateRotation(entryPath, entry, errors);
|
||||||
validateNumber(entryPath, entry, "scale", IrisStaticObject.MINIMUM_SCALE,
|
validateNumber(entryPath, entry, "scale", IrisStaticObject.MINIMUM_SCALE,
|
||||||
IrisStaticObject.MAXIMUM_SCALE, errors);
|
IrisStaticObject.MAXIMUM_SCALE, errors);
|
||||||
@@ -47,7 +47,7 @@ final class PackStaticObjectValidator {
|
|||||||
validateBoolean(entryPath, entry, "bore", errors);
|
validateBoolean(entryPath, entry, "bore", errors);
|
||||||
validateBoolean(entryPath, entry, "smartBore", errors);
|
validateBoolean(entryPath, entry, "smartBore", errors);
|
||||||
validateSeed(entryPath, entry, errors);
|
validateSeed(entryPath, entry, errors);
|
||||||
validateEdits(snippets, entryPath, entry, errors);
|
validateEdits(packFolder, entryPath, entry, errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,9 +64,9 @@ final class PackStaticObjectValidator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validatePosition(PackSnippets snippets, String path, JSONObject entry,
|
private static void validatePosition(File packFolder, String path, JSONObject entry,
|
||||||
int minY, int maxY, List<String> errors) {
|
int minY, int maxY, List<String> errors) {
|
||||||
JSONObject position = resolveObject(snippets, entry.opt("position"), "position-3d",
|
JSONObject position = resolveObject(packFolder, entry.opt("position"), "position-3d",
|
||||||
path + ".position", errors);
|
path + ".position", errors);
|
||||||
if (position == null) {
|
if (position == null) {
|
||||||
return;
|
return;
|
||||||
@@ -121,7 +121,7 @@ final class PackStaticObjectValidator {
|
|||||||
errors.add(path + ".seed must be an integer between " + Long.MIN_VALUE + " and " + Long.MAX_VALUE + ".");
|
errors.add(path + ".seed must be an integer between " + Long.MIN_VALUE + " and " + Long.MAX_VALUE + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateEdits(PackSnippets snippets, String path, JSONObject entry, List<String> errors) {
|
private static void validateEdits(File packFolder, String path, JSONObject entry, List<String> errors) {
|
||||||
if (!entry.has("edit")) {
|
if (!entry.has("edit")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -132,12 +132,12 @@ final class PackStaticObjectValidator {
|
|||||||
}
|
}
|
||||||
for (int index = 0; index < edits.length(); index++) {
|
for (int index = 0; index < edits.length(); index++) {
|
||||||
String editPath = path + ".edit[" + index + "]";
|
String editPath = path + ".edit[" + index + "]";
|
||||||
JSONObject edit = resolveObject(snippets, edits.opt(index), "object-block-replacer", editPath, errors);
|
JSONObject edit = resolveObject(packFolder, edits.opt(index), "object-block-replacer", editPath, errors);
|
||||||
if (edit == null) {
|
if (edit == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
validateBlockList(editPath + ".find", edit.optJSONArray("find"), errors);
|
validateBlockList(editPath + ".find", edit.optJSONArray("find"), errors);
|
||||||
JSONObject replacement = resolveObject(snippets, edit.opt("replace"), "palette",
|
JSONObject replacement = resolveObject(packFolder, edit.opt("replace"), "palette",
|
||||||
editPath + ".replace", errors);
|
editPath + ".replace", errors);
|
||||||
if (replacement != null) {
|
if (replacement != null) {
|
||||||
validateBlockList(editPath + ".replace.palette", replacement.optJSONArray("palette"), errors);
|
validateBlockList(editPath + ".replace.palette", replacement.optJSONArray("palette"), errors);
|
||||||
@@ -160,13 +160,13 @@ final class PackStaticObjectValidator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JSONObject resolveObject(PackSnippets snippets, Object value, String snippetType,
|
private static JSONObject resolveObject(File packFolder, Object value, String snippetType,
|
||||||
String path, List<String> errors) {
|
String path, List<String> errors) {
|
||||||
if (value instanceof JSONObject object) {
|
if (value instanceof JSONObject object) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
if (value instanceof String reference && reference.startsWith("snippet/")) {
|
if (value instanceof String reference && reference.startsWith("snippet/")) {
|
||||||
SnippetFolders.Lookup snippet = snippets.find(snippetType, reference);
|
SnippetFolder.Lookup snippet = new SnippetFolder(snippetType).find(packFolder, reference);
|
||||||
if (!snippet.found()) {
|
if (!snippet.found()) {
|
||||||
errors.add(path + " references missing " + snippetType + " snippet '" + reference + "'.");
|
errors.add(path + " references missing " + snippetType + " snippet '" + reference + "'.");
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
package art.arcane.iris.pack;
|
package art.arcane.iris.pack;
|
||||||
|
|
||||||
import art.arcane.iris.pack.loading.PackSnippets;
|
import art.arcane.iris.pack.loading.SnippetFolder;
|
||||||
import art.arcane.iris.pack.loading.SnippetFolders;
|
|
||||||
import art.arcane.volmlib.util.json.JSONArray;
|
import art.arcane.volmlib.util.json.JSONArray;
|
||||||
import art.arcane.volmlib.util.json.JSONObject;
|
import art.arcane.volmlib.util.json.JSONObject;
|
||||||
|
|
||||||
@@ -57,7 +56,6 @@ final class PackStyledRangeDefaultValidator {
|
|||||||
return new Validation(errors, warnings);
|
return new Validation(errors, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
PackSnippets snippets = new PackSnippets(packFolder);
|
|
||||||
for (String folderName : PackValidator.STRUCTURE_HOST_FOLDERS) {
|
for (String folderName : PackValidator.STRUCTURE_HOST_FOLDERS) {
|
||||||
File resourceFolder = new File(packFolder, folderName);
|
File resourceFolder = new File(packFolder, folderName);
|
||||||
if (!resourceFolder.isDirectory()) {
|
if (!resourceFolder.isDirectory()) {
|
||||||
@@ -75,14 +73,14 @@ final class PackStyledRangeDefaultValidator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
validateObjectPlacements(snippets, type, key, json, errors, warnings);
|
validateObjectPlacements(packFolder, type, key, json, errors, warnings);
|
||||||
validateCaveProfileThreshold(snippets, type, key, json.optJSONObject("caveProfile"), errors, warnings);
|
validateCaveProfileThreshold(packFolder, type, key, json.optJSONObject("caveProfile"), errors, warnings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Validation(errors, warnings);
|
return new Validation(errors, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateObjectPlacements(PackSnippets snippets, String type, String key, JSONObject json,
|
private static void validateObjectPlacements(File packFolder, String type, String key, JSONObject json,
|
||||||
List<String> errors, List<String> warnings) {
|
List<String> errors, List<String> warnings) {
|
||||||
JSONArray objects = json.optJSONArray("objects");
|
JSONArray objects = json.optJSONArray("objects");
|
||||||
if (objects == null) {
|
if (objects == null) {
|
||||||
@@ -93,33 +91,33 @@ final class PackStyledRangeDefaultValidator {
|
|||||||
if (placement == null || !placement.has("densityStyle") || placement.isNull("densityStyle")) {
|
if (placement == null || !placement.has("densityStyle") || placement.isNull("densityStyle")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
checkRange(snippets, placement.opt("densityStyle"),
|
checkRange(packFolder, placement.opt("densityStyle"),
|
||||||
type + " '" + key + "' objects[" + i + "].densityStyle",
|
type + " '" + key + "' objects[" + i + "].densityStyle",
|
||||||
"16-32 objects per chunk", "remove densityStyle to use the scalar density field",
|
"16-32 objects per chunk", "remove densityStyle to use the scalar density field",
|
||||||
errors, warnings);
|
errors, warnings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateCaveProfileThreshold(PackSnippets snippets, String type, String key, JSONObject caveProfile,
|
private static void validateCaveProfileThreshold(File packFolder, String type, String key, JSONObject caveProfile,
|
||||||
List<String> errors, List<String> warnings) {
|
List<String> errors, List<String> warnings) {
|
||||||
if (caveProfile == null || !caveProfile.has("densityThreshold") || caveProfile.isNull("densityThreshold")) {
|
if (caveProfile == null || !caveProfile.has("densityThreshold") || caveProfile.isNull("densityThreshold")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkRange(snippets, caveProfile.opt("densityThreshold"),
|
checkRange(packFolder, caveProfile.opt("densityThreshold"),
|
||||||
type + " '" + key + "' caveProfile.densityThreshold",
|
type + " '" + key + "' caveProfile.densityThreshold",
|
||||||
"a carve threshold of 16-32, hollowing the entire vertical range",
|
"a carve threshold of 16-32, hollowing the entire vertical range",
|
||||||
"remove densityThreshold to keep the cave profile default",
|
"remove densityThreshold to keep the cave profile default",
|
||||||
errors, warnings);
|
errors, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkRange(PackSnippets snippets, Object raw, String path, String consequence, String removal,
|
private static void checkRange(File packFolder, Object raw, String path, String consequence, String removal,
|
||||||
List<String> errors, List<String> warnings) {
|
List<String> errors, List<String> warnings) {
|
||||||
JSONObject range = null;
|
JSONObject range = null;
|
||||||
String via = "";
|
String via = "";
|
||||||
if (raw instanceof JSONObject inline) {
|
if (raw instanceof JSONObject inline) {
|
||||||
range = inline;
|
range = inline;
|
||||||
} else if (raw instanceof String reference && reference.startsWith("snippet/")) {
|
} else if (raw instanceof String reference && reference.startsWith("snippet/")) {
|
||||||
SnippetFolders.Lookup snippet = snippets.find(STYLE_RANGE_SNIPPET_TYPE, reference);
|
SnippetFolder.Lookup snippet = new SnippetFolder(STYLE_RANGE_SNIPPET_TYPE).find(packFolder, reference);
|
||||||
if (!snippet.found()) {
|
if (!snippet.found()) {
|
||||||
return; // Missing snippets are reported by the content-key machinery.
|
return; // Missing snippets are reported by the content-key machinery.
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package art.arcane.iris.pack;
|
package art.arcane.iris.pack;
|
||||||
|
|
||||||
import art.arcane.iris.pack.loading.PackSnippets;
|
import art.arcane.iris.pack.loading.SnippetFolder;
|
||||||
import art.arcane.iris.pack.loading.SnippetFolders;
|
|
||||||
import art.arcane.iris.generation.terrain.IrisTerrain3D;
|
import art.arcane.iris.generation.terrain.IrisTerrain3D;
|
||||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -36,13 +35,12 @@ final class PackTerrain3DValidator {
|
|||||||
if (packFolder == null || !packFolder.isDirectory()) {
|
if (packFolder == null || !packFolder.isDirectory()) {
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
PackSnippets snippets = new PackSnippets(packFolder);
|
|
||||||
File biomeFolder = new File(packFolder, "biomes");
|
File biomeFolder = new File(packFolder, "biomes");
|
||||||
for (File biomeFile : files(biomeFolder)) {
|
for (File biomeFile : files(biomeFolder)) {
|
||||||
JsonObject biome = readObject(biomeFile, "Biome '" + PackValidationIo.deriveKey(biomeFolder, biomeFile)
|
JsonObject biome = readObject(biomeFile, "Biome '" + PackValidationIo.deriveKey(biomeFolder, biomeFile)
|
||||||
+ "'", errors);
|
+ "'", errors);
|
||||||
if (biome != null && biome.has("terrain3D") && !biome.get("terrain3D").isJsonNull()) {
|
if (biome != null && biome.has("terrain3D") && !biome.get("terrain3D").isJsonNull()) {
|
||||||
validateProfile(snippets, biome.get("terrain3D"),
|
validateProfile(packFolder, biome.get("terrain3D"),
|
||||||
"Biome '" + PackValidationIo.deriveKey(biomeFolder, biomeFile) + "' terrain3D", errors);
|
"Biome '" + PackValidationIo.deriveKey(biomeFolder, biomeFile) + "' terrain3D", errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +49,7 @@ final class PackTerrain3DValidator {
|
|||||||
String location = "Terrain3D snippet '" + PackValidationIo.deriveKey(snippetFolder, snippetFile) + "'";
|
String location = "Terrain3D snippet '" + PackValidationIo.deriveKey(snippetFolder, snippetFile) + "'";
|
||||||
JsonObject profile = readObject(snippetFile, location, errors);
|
JsonObject profile = readObject(snippetFile, location, errors);
|
||||||
if (profile != null) {
|
if (profile != null) {
|
||||||
validateProfile(snippets, profile, location, errors);
|
validateProfile(packFolder, profile, location, errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors;
|
return errors;
|
||||||
@@ -66,8 +64,8 @@ final class PackTerrain3DValidator {
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateProfile(PackSnippets snippets, JsonElement raw, String location, List<String> errors) {
|
private static void validateProfile(File packFolder, JsonElement raw, String location, List<String> errors) {
|
||||||
JsonObject object = resolveObject(snippets, raw, "terrain-3d", location, errors);
|
JsonObject object = resolveObject(packFolder, raw, "terrain-3d", location, errors);
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -90,7 +88,7 @@ final class PackTerrain3DValidator {
|
|||||||
}
|
}
|
||||||
case "seed" -> requireInteger(value, path, errors);
|
case "seed" -> requireInteger(value, path, errors);
|
||||||
case "densityStyle", "crackStyle" -> {
|
case "densityStyle", "crackStyle" -> {
|
||||||
JsonObject style = validateStyle(snippets, value, path, 0, errors);
|
JsonObject style = validateStyle(packFolder, value, path, 0, errors);
|
||||||
if (style != null) {
|
if (style != null) {
|
||||||
normalized.add(field, style);
|
normalized.add(field, style);
|
||||||
}
|
}
|
||||||
@@ -108,13 +106,13 @@ final class PackTerrain3DValidator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonObject validateStyle(PackSnippets snippets, JsonElement raw, String location,
|
private static JsonObject validateStyle(File packFolder, JsonElement raw, String location,
|
||||||
int depth, List<String> errors) {
|
int depth, List<String> errors) {
|
||||||
if (depth > 32) {
|
if (depth > 32) {
|
||||||
errors.add(location + " exceeds the maximum style nesting depth of 32.");
|
errors.add(location + " exceeds the maximum style nesting depth of 32.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JsonObject object = resolveObject(snippets, raw, "style", location, errors);
|
JsonObject object = resolveObject(packFolder, raw, "style", location, errors);
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -141,7 +139,7 @@ final class PackTerrain3DValidator {
|
|||||||
}
|
}
|
||||||
case "fracture" -> {
|
case "fracture" -> {
|
||||||
if (!value.isJsonNull()) {
|
if (!value.isJsonNull()) {
|
||||||
JsonObject fracture = validateStyle(snippets, value, path, depth + 1, errors);
|
JsonObject fracture = validateStyle(packFolder, value, path, depth + 1, errors);
|
||||||
if (fracture != null) {
|
if (fracture != null) {
|
||||||
normalized.add(field, fracture);
|
normalized.add(field, fracture);
|
||||||
}
|
}
|
||||||
@@ -160,7 +158,7 @@ final class PackTerrain3DValidator {
|
|||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonObject resolveObject(PackSnippets snippets, JsonElement raw, String snippetType,
|
private static JsonObject resolveObject(File packFolder, JsonElement raw, String snippetType,
|
||||||
String location, List<String> errors) {
|
String location, List<String> errors) {
|
||||||
if (raw.isJsonObject()) {
|
if (raw.isJsonObject()) {
|
||||||
return raw.getAsJsonObject();
|
return raw.getAsJsonObject();
|
||||||
@@ -171,7 +169,7 @@ final class PackTerrain3DValidator {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String reference = raw.getAsString();
|
String reference = raw.getAsString();
|
||||||
SnippetFolders.Lookup snippet = snippets.find(snippetType, reference);
|
SnippetFolder.Lookup snippet = new SnippetFolder(snippetType).find(packFolder, reference);
|
||||||
if (!snippet.found()) {
|
if (!snippet.found()) {
|
||||||
errors.add(location + " references an unavailable " + snippetType + " snippet '" + reference + "'.");
|
errors.add(location + " references an unavailable " + snippetType + " snippet '" + reference + "'.");
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
package art.arcane.iris.pack.ingest;
|
package art.arcane.iris.pack.ingest;
|
||||||
|
|
||||||
import art.arcane.iris.pack.loading.PackSnippets;
|
import art.arcane.iris.pack.loading.SnippetFolder;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
@@ -40,14 +40,12 @@ final class IngestPack {
|
|||||||
private static final String SNIPPET_PREFIX = "snippet/";
|
private static final String SNIPPET_PREFIX = "snippet/";
|
||||||
|
|
||||||
private final Path root;
|
private final Path root;
|
||||||
private final PackSnippets snippets;
|
|
||||||
private final Map<String, JsonObject> loaded = new HashMap<>();
|
private final Map<String, JsonObject> loaded = new HashMap<>();
|
||||||
private final Map<String, JsonObject> pending = new TreeMap<>();
|
private final Map<String, JsonObject> pending = new TreeMap<>();
|
||||||
private final Set<String> generated = new TreeSet<>();
|
private final Set<String> generated = new TreeSet<>();
|
||||||
|
|
||||||
IngestPack(Path root) {
|
IngestPack(Path root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
this.snippets = new PackSnippets(root.toFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path root() {
|
Path root() {
|
||||||
@@ -117,13 +115,8 @@ final class IngestPack {
|
|||||||
if (!reference.startsWith(SNIPPET_PREFIX)) {
|
if (!reference.startsWith(SNIPPET_PREFIX)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (String key : snippets.folders(snippetType).candidateKeys(reference)) {
|
String key = new SnippetFolder(snippetType).keyOf(reference);
|
||||||
Optional<JsonObject> snippet = find(key + ".json");
|
return find(key + ".json").map(JsonObject::deepCopy).orElse(null);
|
||||||
if (snippet.isPresent()) {
|
|
||||||
return snippet.get().deepCopy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> generatedFiles() {
|
List<String> generatedFiles() {
|
||||||
|
|||||||
@@ -151,7 +151,6 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
private ResourceLoader<IrisJigsawPool> jigsawPoolLoader;
|
private ResourceLoader<IrisJigsawPool> jigsawPoolLoader;
|
||||||
private ResourceLoader<IrisJigsawPiece> jigsawPieceLoader;
|
private ResourceLoader<IrisJigsawPiece> jigsawPieceLoader;
|
||||||
private KMap<String, KList<String>> possibleSnippets;
|
private KMap<String, KList<String>> possibleSnippets;
|
||||||
private KMap<String, SnippetFolders> snippetFolders;
|
|
||||||
private Gson gson;
|
private Gson gson;
|
||||||
private Gson snippetLoader;
|
private Gson snippetLoader;
|
||||||
private GsonBuilder builder;
|
private GsonBuilder builder;
|
||||||
@@ -713,7 +712,6 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
compatReport.clear();
|
compatReport.clear();
|
||||||
closed = false;
|
closed = false;
|
||||||
possibleSnippets = new KMap<>();
|
possibleSnippets = new KMap<>();
|
||||||
snippetFolders = new KMap<>();
|
|
||||||
builder = new GsonBuilder()
|
builder = new GsonBuilder()
|
||||||
.addDeserializationExclusionStrategy(this)
|
.addDeserializationExclusionStrategy(this)
|
||||||
.addSerializationExclusionStrategy(this)
|
.addSerializationExclusionStrategy(this)
|
||||||
@@ -756,7 +754,6 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
private void hotloadedDatapackCompiler() {
|
private void hotloadedDatapackCompiler() {
|
||||||
closed = false;
|
closed = false;
|
||||||
possibleSnippets = new KMap<>();
|
possibleSnippets = new KMap<>();
|
||||||
snippetFolders = new KMap<>();
|
|
||||||
builder = new GsonBuilder()
|
builder = new GsonBuilder()
|
||||||
.addDeserializationExclusionStrategy(this)
|
.addDeserializationExclusionStrategy(this)
|
||||||
.addSerializationExclusionStrategy(this)
|
.addSerializationExclusionStrategy(this)
|
||||||
@@ -831,7 +828,6 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
i.clearList();
|
i.clearList();
|
||||||
}
|
}
|
||||||
possibleSnippets.clear();
|
possibleSnippets.clear();
|
||||||
snippetFolders.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBlockDropRules(String material) {
|
public boolean hasBlockDropRules(String material) {
|
||||||
@@ -1028,16 +1024,6 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
return snippetTypeOf(elementType);
|
return snippetTypeOf(elementType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The folders the named snippet type keeps its files in, including the namespaced ones this pack has. */
|
|
||||||
public SnippetFolders getSnippetFolders(String snippetType) {
|
|
||||||
return snippetFolders.computeIfAbsent(snippetType, type -> SnippetFolders.discover(getDataFolder(), type));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The "snippet/<namespace>/<group>/<type>" folders of the named snippet type, empty in a legacy-only pack. */
|
|
||||||
public List<String> getNamespacedSnippetFolders(String snippetType) {
|
|
||||||
return getSnippetFolders(snippetType).namespaced();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A snippet file holding a JSON array stands for all of its entries, so inside a list it becomes that many items. */
|
/** A snippet file holding a JSON array stands for all of its entries, so inside a list it becomes that many items. */
|
||||||
private <T> TypeAdapter<T> snippetListAdapter(Gson gson, TypeToken<T> listType, String snippetType) {
|
private <T> TypeAdapter<T> snippetListAdapter(Gson gson, TypeToken<T> listType, String snippetType) {
|
||||||
TypeAdapter<T> listAdapter = gson.getDelegateAdapter(this, listType);
|
TypeAdapter<T> listAdapter = gson.getDelegateAdapter(this, listType);
|
||||||
@@ -1092,18 +1078,18 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
private static boolean isSnippetReference(JsonElement entry) {
|
private static boolean isSnippetReference(JsonElement entry) {
|
||||||
return entry.isJsonPrimitive()
|
return entry.isJsonPrimitive()
|
||||||
&& entry.getAsJsonPrimitive().isString()
|
&& entry.getAsJsonPrimitive().isString()
|
||||||
&& entry.getAsString().startsWith(SnippetFolders.PREFIX);
|
&& entry.getAsString().startsWith(SnippetFolder.PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The parsed snippet file, or null when the reference isn't a snippet or the file can't be read. */
|
/** The parsed snippet file, or null when the reference isn't a snippet or the file can't be read. */
|
||||||
private @Nullable JsonElement readSnippetFile(String snippetType, String reference, String path) {
|
private @Nullable JsonElement readSnippetFile(String snippetType, String reference, String path) {
|
||||||
if (!reference.startsWith(SnippetFolders.PREFIX)) {
|
if (!reference.startsWith(SnippetFolder.PREFIX)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
SnippetFolders.Lookup lookup = getSnippetFolders(snippetType).find(getDataFolder(), reference);
|
SnippetFolder.Lookup lookup = new SnippetFolder(snippetType).find(getDataFolder(), reference);
|
||||||
if (!lookup.found()) {
|
if (!lookup.found()) {
|
||||||
IrisLogging.error("Couldn't find snippet " + reference + " in " + path + " (tried " + lookup.triedDescription() + ")");
|
IrisLogging.error("Couldn't find snippet " + lookup.key() + " in " + path);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1116,16 +1102,11 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Every snippet of the type, as "snippet/<path inside its folder>", from the legacy and the namespaced folder. */
|
/** Every snippet of the type, as "snippet/<path inside its folder>". */
|
||||||
public KList<String> getPossibleSnippets(String snippetType) {
|
public KList<String> getPossibleSnippets(String snippetType) {
|
||||||
return possibleSnippets.computeIfAbsent(snippetType, (k) -> {
|
return possibleSnippets.computeIfAbsent(snippetType, (k) -> {
|
||||||
KList<String> references = new KList<>();
|
File snippetFolder = new File(getDataFolder(), new SnippetFolder(snippetType).path());
|
||||||
for (String folder : getSnippetFolders(snippetType).folders()) {
|
return new KList<>(listSnippetReferences(snippetFolder));
|
||||||
listSnippetReferences(new File(getDataFolder(), folder)).stream()
|
|
||||||
.filter(reference -> !references.contains(reference))
|
|
||||||
.forEach(references::add);
|
|
||||||
}
|
|
||||||
return references;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1143,7 +1124,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
.map(s -> s.substring(absPath.length() + 1))
|
.map(s -> s.substring(absPath.length() + 1))
|
||||||
.map(s -> s.replace("\\", "/"))
|
.map(s -> s.replace("\\", "/"))
|
||||||
.map(s -> s.substring(0, s.length() - ".json".length()))
|
.map(s -> s.substring(0, s.length() - ".json".length()))
|
||||||
.map(s -> SnippetFolders.PREFIX + s)
|
.map(s -> SnippetFolder.PREFIX + s)
|
||||||
.toList();
|
.toList();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
IrisLogging.reportError("Failed to scan Iris snippets in " + snippetFolder + ".", e);
|
IrisLogging.reportError("Failed to scan Iris snippets in " + snippetFolder + ".", e);
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package art.arcane.iris.pack.loading;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* One pack's snippet folders, discovered at most once per snippet type. Create one per validation run rather than
|
|
||||||
* sharing it, since pack files change between runs during hotload.
|
|
||||||
*/
|
|
||||||
public final class PackSnippets {
|
|
||||||
private final File packFolder;
|
|
||||||
private final Map<String, SnippetFolders> foldersByType = new HashMap<>();
|
|
||||||
|
|
||||||
public PackSnippets(File packFolder) {
|
|
||||||
this.packFolder = packFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File packFolder() {
|
|
||||||
return packFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SnippetFolders folders(String snippetType) {
|
|
||||||
return foldersByType.computeIfAbsent(snippetType, type -> SnippetFolders.discover(packFolder, type));
|
|
||||||
}
|
|
||||||
|
|
||||||
public SnippetFolders.Lookup find(String snippetType, String reference) {
|
|
||||||
return folders(snippetType).find(packFolder, reference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package art.arcane.iris.pack.loading;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.InvalidPathException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pack folder "snippet/<type>" one snippet type keeps its files in. This is the one place a
|
||||||
|
* "snippet/..." reference turns into a file.
|
||||||
|
*/
|
||||||
|
public record SnippetFolder(String snippetType) {
|
||||||
|
public static final String PREFIX = "snippet/";
|
||||||
|
private static final String FILE_SUFFIX = ".json";
|
||||||
|
private static final int WORKSPACE_MATCH_DEPTH = 8;
|
||||||
|
|
||||||
|
public String path() {
|
||||||
|
return PREFIX + snippetType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean holds(String reference) {
|
||||||
|
return reference.startsWith(path() + "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The file key, without ".json", a reference means: "snippet/name" is short for "snippet/<type>/name". */
|
||||||
|
public String keyOf(String reference) {
|
||||||
|
return holds(reference) ? reference : path() + "/" + reference.substring(PREFIX.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Lookup find(File packFolder, String reference) {
|
||||||
|
String key = keyOf(reference);
|
||||||
|
return new Lookup(existingFileInsideFolder(packFolder, key), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The IDE file patterns the snippet schema applies to. */
|
||||||
|
public List<String> workspaceFileMatches() {
|
||||||
|
List<String> matches = new ArrayList<>();
|
||||||
|
for (int depth = 1; depth < WORKSPACE_MATCH_DEPTH; depth++) {
|
||||||
|
matches.add("/" + path() + "/*".repeat(depth) + FILE_SUFFIX);
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable File existingFileInsideFolder(File packFolder, String key) {
|
||||||
|
try {
|
||||||
|
Path root = packFolder.toPath().toAbsolutePath().normalize();
|
||||||
|
Path folder = root.resolve(path()).normalize();
|
||||||
|
Path file = root.resolve(key + FILE_SUFFIX).normalize();
|
||||||
|
if (!file.startsWith(folder) || !Files.isRegularFile(file)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return file.toRealPath().startsWith(folder.toRealPath()) ? file.toFile() : null;
|
||||||
|
} catch (InvalidPathException | IOException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The snippet file a reference names, absent when the pack has no such file. */
|
||||||
|
public record Lookup(@Nullable File file, String key) {
|
||||||
|
public boolean found() {
|
||||||
|
return file != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
package art.arcane.iris.pack.loading;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.InvalidPathException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The pack folders one snippet type keeps its files in: the flat legacy folder "snippet/<type>", plus every
|
|
||||||
* namespaced folder "snippet/iris/<group>/<type>" that exists in the pack. This is the one
|
|
||||||
* place a "snippet/..." reference turns into a file.
|
|
||||||
*/
|
|
||||||
public record SnippetFolders(String legacy, List<String> namespaced) {
|
|
||||||
public static final String PREFIX = "snippet/";
|
|
||||||
/** Only the "iris" namespace counts, so a legacy pack's nested folders such as "snippet/procedural/objects/coral" stay legacy. */
|
|
||||||
private static final String NAMESPACE = "iris";
|
|
||||||
private static final String FILE_SUFFIX = ".json";
|
|
||||||
private static final int WORKSPACE_MATCH_DEPTH = 8;
|
|
||||||
|
|
||||||
public static SnippetFolders discover(File packFolder, String legacy) {
|
|
||||||
List<String> namespaced = new ArrayList<>();
|
|
||||||
for (File group : subfolders(new File(packFolder, PREFIX + NAMESPACE))) {
|
|
||||||
if (new File(group, legacy).isDirectory()) {
|
|
||||||
namespaced.add(PREFIX + NAMESPACE + "/" + group.getName() + "/" + legacy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new SnippetFolders(legacy, List.copyOf(namespaced));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The folders as "snippet/<folder>", legacy first, then the namespaced ones in sorted order. */
|
|
||||||
public List<String> folders() {
|
|
||||||
List<String> folders = new ArrayList<>(namespaced.size() + 1);
|
|
||||||
folders.add(PREFIX + legacy);
|
|
||||||
folders.addAll(namespaced);
|
|
||||||
return folders;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The file keys, without ".json", a reference can mean. A reference already inside one of the folders names that
|
|
||||||
* file; a short one is tried in the legacy folder first, then each namespaced one.
|
|
||||||
*/
|
|
||||||
public List<String> candidateKeys(String reference) {
|
|
||||||
List<String> folders = folders();
|
|
||||||
for (String folder : folders) {
|
|
||||||
if (reference.startsWith(folder + "/")) {
|
|
||||||
return List.of(reference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String shortName = reference.substring(PREFIX.length());
|
|
||||||
return folders.stream().map(folder -> folder + "/" + shortName).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lookup find(File packFolder, String reference) {
|
|
||||||
List<String> candidates = candidateKeys(reference);
|
|
||||||
Path root = packFolder.toPath().toAbsolutePath().normalize();
|
|
||||||
for (String key : candidates) {
|
|
||||||
Path file = existingFileInsideFolder(root, key);
|
|
||||||
if (file != null) {
|
|
||||||
return new Lookup(file.toFile(), key, candidates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Lookup(null, null, candidates);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The IDE file patterns the snippet schema applies to, covering every folder of this type. */
|
|
||||||
public List<String> workspaceFileMatches() {
|
|
||||||
List<String> matches = new ArrayList<>();
|
|
||||||
for (String folder : folders()) {
|
|
||||||
for (int depth = 1; depth < WORKSPACE_MATCH_DEPTH; depth++) {
|
|
||||||
matches.add("/" + folder + "/*".repeat(depth) + FILE_SUFFIX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return matches;
|
|
||||||
}
|
|
||||||
|
|
||||||
private @Nullable Path existingFileInsideFolder(Path root, String key) {
|
|
||||||
String folder = folders().stream().filter(candidate -> key.startsWith(candidate + "/")).findFirst().orElse(null);
|
|
||||||
if (folder == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Path file = root.resolve(key + FILE_SUFFIX).normalize();
|
|
||||||
Path folderPath = root.resolve(folder).normalize();
|
|
||||||
if (!file.startsWith(folderPath) || !Files.isRegularFile(file)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return file.toRealPath().startsWith(folderPath.toRealPath()) ? file : null;
|
|
||||||
} catch (InvalidPathException | IOException ignored) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File[] subfolders(File folder) {
|
|
||||||
File[] children = folder.listFiles(File::isDirectory);
|
|
||||||
if (children == null) {
|
|
||||||
return new File[0];
|
|
||||||
}
|
|
||||||
Arrays.sort(children);
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The existing snippet file a reference names, or the keys that were tried when there is none. */
|
|
||||||
public record Lookup(@Nullable File file, @Nullable String key, List<String> triedKeys) {
|
|
||||||
public boolean found() {
|
|
||||||
return file != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String triedDescription() {
|
|
||||||
return String.join(", ", triedKeys);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -32,14 +32,11 @@ import art.arcane.volmlib.util.json.JSONObject;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InaccessibleObjectException;
|
import java.lang.reflect.InaccessibleObjectException;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class SchemaBuilder {
|
public class SchemaBuilder {
|
||||||
static final String SYMBOL_LIMIT__N = "*";
|
static final String SYMBOL_LIMIT__N = "*";
|
||||||
static final String SYMBOL_TYPE__N = "";
|
static final String SYMBOL_TYPE__N = "";
|
||||||
private static final String REGEX_SYNTAX_CHARACTERS = "\\^$.*+?()[]{}|";
|
|
||||||
final KMap<String, JSONObject> definitions;
|
final KMap<String, JSONObject> definitions;
|
||||||
final KList<String> warnings;
|
final KList<String> warnings;
|
||||||
final IrisData data;
|
final IrisData data;
|
||||||
@@ -140,29 +137,6 @@ public class SchemaBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String snippetPattern(String snippetType, List<String> namespacedFolders) {
|
|
||||||
String legacyFolder = escapeRegex("snippet/" + snippetType);
|
|
||||||
if (namespacedFolders.isEmpty()) {
|
|
||||||
return "^" + legacyFolder + "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> folders = new ArrayList<>();
|
|
||||||
folders.add(legacyFolder);
|
|
||||||
namespacedFolders.stream().map(SchemaBuilder::escapeRegex).forEach(folders::add);
|
|
||||||
return "^(?:" + String.join("|", folders) + ")/";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String escapeRegex(String literal) {
|
|
||||||
StringBuilder escaped = new StringBuilder(literal.length());
|
|
||||||
for (char character : literal.toCharArray()) {
|
|
||||||
if (REGEX_SYNTAX_CHARACTERS.indexOf(character) >= 0) {
|
|
||||||
escaped.append('\\');
|
|
||||||
}
|
|
||||||
escaped.append(character);
|
|
||||||
}
|
|
||||||
return escaped.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject buildSnippet(JSONObject prop, Class<?> type) {
|
JSONObject buildSnippet(JSONObject prop, Class<?> type) {
|
||||||
Snippet snippet = type.getDeclaredAnnotation(Snippet.class);
|
Snippet snippet = type.getDeclaredAnnotation(Snippet.class);
|
||||||
if (snippet == null) return prop;
|
if (snippet == null) return prop;
|
||||||
@@ -181,7 +155,7 @@ public class SchemaBuilder {
|
|||||||
enumObj.put("enum", snl);
|
enumObj.put("enum", snl);
|
||||||
JSONObject patternObj = new JSONObject();
|
JSONObject patternObj = new JSONObject();
|
||||||
patternObj.put("type", "string");
|
patternObj.put("type", "string");
|
||||||
patternObj.put("pattern", snippetPattern(snippet.value(), data.getNamespacedSnippetFolders(snippet.value())));
|
patternObj.put("pattern", "^snippet/" + snippet.value() + "/");
|
||||||
JSONArray snippetAlt = new JSONArray();
|
JSONArray snippetAlt = new JSONArray();
|
||||||
snippetAlt.put(enumObj);
|
snippetAlt.put(enumObj);
|
||||||
snippetAlt.put(patternObj);
|
snippetAlt.put(patternObj);
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import art.arcane.volmlib.util.collection.KList;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One of the block palettes a biome places: a surface, sea or cave ceiling layer, its wall or slab blocks, or a
|
* One of the block palettes a biome places: a surface, sea or cave ceiling layer, its wall or slab blocks, or a
|
||||||
@@ -129,10 +128,7 @@ record BiomePalette(String biomeKey, Kind kind, int index) {
|
|||||||
*/
|
*/
|
||||||
String pathOf(String reference) {
|
String pathOf(String reference) {
|
||||||
String path = reference.startsWith(SNIPPET_PREFIX) ? reference.substring(SNIPPET_PREFIX.length()) : reference;
|
String path = reference.startsWith(SNIPPET_PREFIX) ? reference.substring(SNIPPET_PREFIX.length()) : reference;
|
||||||
if (path.startsWith(folder + "/")) {
|
return path.startsWith(folder + "/") ? path.substring(folder.length() + 1) : path;
|
||||||
return path.substring(folder.length() + 1);
|
|
||||||
}
|
|
||||||
return path.replaceFirst("^iris/[^/]+/" + Pattern.quote(folder) + "/", "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import art.arcane.iris.pack.schema.SchemaBuilder;
|
|||||||
import art.arcane.iris.configuration.IrisSettings;
|
import art.arcane.iris.configuration.IrisSettings;
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
import art.arcane.iris.pack.loading.ResourceLoader;
|
import art.arcane.iris.pack.loading.ResourceLoader;
|
||||||
|
import art.arcane.iris.pack.loading.SnippetFolder;
|
||||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||||
import art.arcane.iris.spi.IrisLogging;
|
import art.arcane.iris.spi.IrisLogging;
|
||||||
import art.arcane.iris.platform.bukkit.plugin.VolmitSender;
|
import art.arcane.iris.platform.bukkit.plugin.VolmitSender;
|
||||||
@@ -181,7 +182,7 @@ public class IrisCodeWorkspace {
|
|||||||
try {
|
try {
|
||||||
String snipType = snippetClass.getDeclaredAnnotation(Snippet.class).value();
|
String snipType = snippetClass.getDeclaredAnnotation(Snippet.class).value();
|
||||||
JSONObject schemaEntry = new JSONObject();
|
JSONObject schemaEntry = new JSONObject();
|
||||||
List<String> fileMatches = dm.getSnippetFolders(snipType).workspaceFileMatches();
|
List<String> fileMatches = new SnippetFolder(snipType).workspaceFileMatches();
|
||||||
|
|
||||||
schemaEntry.put("fileMatch", new JSONArray(fileMatches.toArray()));
|
schemaEntry.put("fileMatch", new JSONArray(fileMatches.toArray()));
|
||||||
schemaEntry.put("url", "./.iris/schema/snippet/" + snipType + "-schema.json");
|
schemaEntry.put("url", "./.iris/schema/snippet/" + snipType + "-schema.json");
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
|||||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
import art.arcane.iris.pack.loading.PackSnippets;
|
|
||||||
import art.arcane.iris.testsupport.CompatTestPlatform;
|
import art.arcane.iris.testsupport.CompatTestPlatform;
|
||||||
import art.arcane.volmlib.util.json.JSONObject;
|
import art.arcane.volmlib.util.json.JSONObject;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -363,7 +362,7 @@ public class PackHydrologyValidatorTest {
|
|||||||
{"zones": {"swamp": {"min": 0.7, "max": 1}, "desert": {"minimum": 0.1}}}
|
{"zones": {"swamp": {"min": 0.7, "max": 1}, "desert": {"minimum": 0.1}}}
|
||||||
""");
|
""");
|
||||||
|
|
||||||
PackHydrologyValidator.warnUnknownKeys("root", written, NamedZones.class, new PackSnippets(temporaryFolder.getRoot()), warnings);
|
PackHydrologyValidator.warnUnknownKeys("root", written, NamedZones.class, temporaryFolder.getRoot(), warnings);
|
||||||
|
|
||||||
assertContains(warnings, "root.zones.desert.minimum is not a known key");
|
assertContains(warnings, "root.zones.desert.minimum is not a known key");
|
||||||
assertEquals(warnings.toString(), 1, warnings.size());
|
assertEquals(warnings.toString(), 1, warnings.size());
|
||||||
@@ -468,7 +467,7 @@ public class PackHydrologyValidatorTest {
|
|||||||
""");
|
""");
|
||||||
List<String> warnings = new ArrayList<>();
|
List<String> warnings = new ArrayList<>();
|
||||||
|
|
||||||
PackHydrologyValidator.warnUnknownKeys("style", "snippet/style/loop", IrisGeneratorStyle.class, new PackSnippets(pack), warnings);
|
PackHydrologyValidator.warnUnknownKeys("style", "snippet/style/loop", IrisGeneratorStyle.class, pack, warnings);
|
||||||
|
|
||||||
assertContains(warnings, "style (snippet/style/loop).fractures is not a known key");
|
assertContains(warnings, "style (snippet/style/loop).fractures is not a known key");
|
||||||
assertEquals(warnings.toString(), 1, warnings.size());
|
assertEquals(warnings.toString(), 1, warnings.size());
|
||||||
@@ -499,7 +498,7 @@ public class PackHydrologyValidatorTest {
|
|||||||
List<String> warnings = new ArrayList<>();
|
List<String> warnings = new ArrayList<>();
|
||||||
JSONObject written = new JSONObject("{\"tiers\": {\"name\": \"stream\"}, \"fluids\": {\"elementData\": 1}}");
|
JSONObject written = new JSONObject("{\"tiers\": {\"name\": \"stream\"}, \"fluids\": {\"elementData\": 1}}");
|
||||||
|
|
||||||
PackHydrologyValidator.warnUnknownKeys("root", written, IrisHydrology.class, new PackSnippets(temporaryFolder.getRoot()), warnings);
|
PackHydrologyValidator.warnUnknownKeys("root", written, IrisHydrology.class, temporaryFolder.getRoot(), warnings);
|
||||||
|
|
||||||
assertEquals(List.of(), warnings);
|
assertEquals(List.of(), warnings);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ public class IrisDataSnippetPackWalkTest {
|
|||||||
|
|
||||||
private File pack;
|
private File pack;
|
||||||
private final Map<String, Class<?>> snippetTypesByFolder = new HashMap<>();
|
private final Map<String, Class<?>> snippetTypesByFolder = new HashMap<>();
|
||||||
private final Map<Class<?>, SnippetFolders> foldersByType = new HashMap<>();
|
|
||||||
private final List<String> unresolved = new ArrayList<>();
|
private final List<String> unresolved = new ArrayList<>();
|
||||||
private int resolved;
|
private int resolved;
|
||||||
private int outsideSnippetFields;
|
private int outsideSnippetFields;
|
||||||
@@ -108,11 +107,7 @@ public class IrisDataSnippetPackWalkTest {
|
|||||||
|
|
||||||
private Class<?> typeOfSnippetFile(File file) {
|
private Class<?> typeOfSnippetFile(File file) {
|
||||||
String[] segments = relative(file).split("/");
|
String[] segments = relative(file).split("/");
|
||||||
Class<?> legacyType = snippetTypesByFolder.get(segments[1]);
|
return snippetTypesByFolder.get(segments[1]);
|
||||||
if (legacyType != null) {
|
|
||||||
return legacyType;
|
|
||||||
}
|
|
||||||
return segments.length > 4 ? snippetTypesByFolder.get(segments[3]) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void walk(JsonElement value, Type type, String path) {
|
private void walk(JsonElement value, Type type, String path) {
|
||||||
@@ -156,28 +151,25 @@ public class IrisDataSnippetPackWalkTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkReference(JsonElement value, Class<?> raw, String path) {
|
private void checkReference(JsonElement value, Class<?> raw, String path) {
|
||||||
if (!value.getAsJsonPrimitive().isString() || !value.getAsString().startsWith(SnippetFolders.PREFIX)) {
|
if (!value.getAsJsonPrimitive().isString() || !value.getAsString().startsWith(SnippetFolder.PREFIX)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String reference = value.getAsString();
|
String reference = value.getAsString();
|
||||||
SnippetFolders folders = raw == null ? null : foldersOf(raw);
|
SnippetFolder folder = raw == null ? null : folderOf(raw);
|
||||||
if (folders == null) {
|
if (folder == null) {
|
||||||
outsideSnippetFields++;
|
outsideSnippetFields++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (folders.find(pack, reference).found()) {
|
if (folder.find(pack, reference).found()) {
|
||||||
resolved++;
|
resolved++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unresolved.add(path + " -> " + reference + " (tried " + folders.candidateKeys(reference) + ")");
|
unresolved.add(path + " -> " + reference + " (tried " + folder.keyOf(reference) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
private SnippetFolders foldersOf(Class<?> type) {
|
private SnippetFolder folderOf(Class<?> type) {
|
||||||
Snippet snippet = type.getDeclaredAnnotation(Snippet.class);
|
Snippet snippet = type.getDeclaredAnnotation(Snippet.class);
|
||||||
if (snippet == null) {
|
return snippet == null ? null : new SnippetFolder(snippet.value());
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return foldersByType.computeIfAbsent(type, ignored -> SnippetFolders.discover(pack, snippet.value()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectSnippetTypes(Type type, Set<Class<?>> visited) {
|
private void collectSnippetTypes(Type type, Set<Class<?>> visited) {
|
||||||
|
|||||||
@@ -63,56 +63,24 @@ public class IrisDataSnippetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shortReferenceResolvesInTheNamespacedFolder() throws IOException {
|
public void nestedPathResolves() throws IOException {
|
||||||
write("snippet/iris/spawn/rate/fast.json", "{\"amount\":7}");
|
write("snippet/rate/groups/fast.json", "{\"amount\":8}");
|
||||||
|
|
||||||
assertEquals(7, rateOf("\"snippet/fast\"").getAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fullReferenceResolvesInTheNamespacedFolder() throws IOException {
|
|
||||||
write("snippet/iris/spawn/rate/fast.json", "{\"amount\":7}");
|
|
||||||
|
|
||||||
assertEquals(7, rateOf("\"snippet/iris/spawn/rate/fast\"").getAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void nestedNamespacedPathResolves() throws IOException {
|
|
||||||
write("snippet/iris/spawn/rate/groups/fast.json", "{\"amount\":8}");
|
|
||||||
|
|
||||||
assertEquals(8, rateOf("\"snippet/groups/fast\"").getAmount());
|
assertEquals(8, rateOf("\"snippet/groups/fast\"").getAmount());
|
||||||
assertEquals(8, rateOf("\"snippet/iris/spawn/rate/groups/fast\"").getAmount());
|
assertEquals(8, rateOf("\"snippet/rate/groups/fast\"").getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void legacyLayoutStillResolves() throws IOException {
|
public void shortAndFullReferencesResolve() throws IOException {
|
||||||
write("snippet/rate/slow.json", "{\"amount\":3}");
|
write("snippet/rate/slow.json", "{\"amount\":3}");
|
||||||
|
|
||||||
assertEquals(3, rateOf("\"snippet/slow\"").getAmount());
|
assertEquals(3, rateOf("\"snippet/slow\"").getAmount());
|
||||||
assertEquals(3, rateOf("\"snippet/rate/slow\"").getAmount());
|
assertEquals(3, rateOf("\"snippet/rate/slow\"").getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void legacyFolderWinsAShortReferenceWhenBothLayoutsHoldTheFile() throws IOException {
|
|
||||||
write("snippet/rate/both.json", "{\"amount\":1}");
|
|
||||||
write("snippet/iris/spawn/rate/both.json", "{\"amount\":2}");
|
|
||||||
|
|
||||||
assertEquals(1, rateOf("\"snippet/both\"").getAmount());
|
|
||||||
assertEquals(1, rateOf("\"snippet/rate/both\"").getAmount());
|
|
||||||
assertEquals(2, rateOf("\"snippet/iris/spawn/rate/both\"").getAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void namespacedFolderIsTriedWhenTheLegacyFileIsMissing() throws IOException {
|
|
||||||
write("snippet/rate/other.json", "{\"amount\":1}");
|
|
||||||
write("snippet/iris/spawn/rate/only-here.json", "{\"amount\":2}");
|
|
||||||
|
|
||||||
assertEquals(2, rateOf("\"snippet/only-here\"").getAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void snippetsOfAnotherTypeAreNotUsed() throws IOException {
|
public void snippetsOfAnotherTypeAreNotUsed() throws IOException {
|
||||||
write("snippet/iris/spawn/duration/fast.json", "{\"amount\":7}");
|
write("snippet/duration/fast.json", "{\"amount\":7}");
|
||||||
|
|
||||||
assertNull(rateOf("\"snippet/fast\""));
|
assertNull(rateOf("\"snippet/fast\""));
|
||||||
}
|
}
|
||||||
@@ -148,17 +116,10 @@ public class IrisDataSnippetTest {
|
|||||||
assertNull(rateOf("\"snippet/absent\""));
|
assertNull(rateOf("\"snippet/absent\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void namespaceDeeperThanTwoSegmentsIsNotAFolderOfTheType() throws IOException {
|
|
||||||
write("snippet/one/two/three/rate/deep.json", "{\"amount\":7}");
|
|
||||||
|
|
||||||
assertNull(rateOf("\"snippet/deep\""));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void arraySnippetInAListStandsForAllItsEntries() throws IOException {
|
public void arraySnippetInAListStandsForAllItsEntries() throws IOException {
|
||||||
write("snippet/iris/spawn/rate/many.json", "[{\"amount\":1},{\"amount\":2},]");
|
write("snippet/rate/many.json", "[{\"amount\":1},{\"amount\":2},]");
|
||||||
write("snippet/iris/spawn/rate/one.json", "{\"amount\":5}");
|
write("snippet/rate/one.json", "{\"amount\":5}");
|
||||||
|
|
||||||
RateListHolder holder = data().getGson().fromJson(
|
RateListHolder holder = data().getGson().fromJson(
|
||||||
"{\"rates\":[\"snippet/many\",\"snippet/one\",{\"amount\":9}],"
|
"{\"rates\":[\"snippet/many\",\"snippet/one\",{\"amount\":9}],"
|
||||||
@@ -197,46 +158,13 @@ public class IrisDataSnippetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void possibleSnippetsCoverBothFoldersWithoutDuplicates() throws IOException {
|
public void possibleSnippetsListTheTypeFolderAsShortReferences() throws IOException {
|
||||||
write("snippet/rate/a.json", "{}");
|
write("snippet/rate/a.json", "{}");
|
||||||
write("snippet/rate/shared.json", "{}");
|
write("snippet/rate/nested/c.json", "{}");
|
||||||
write("snippet/iris/spawn/rate/b.json", "{}");
|
write("snippet/duration/other.json", "{}");
|
||||||
write("snippet/iris/spawn/rate/shared.json", "{}");
|
|
||||||
write("snippet/iris/spawn/rate/nested/c.json", "{}");
|
|
||||||
|
|
||||||
assertEquals(List.of("snippet/a", "snippet/shared", "snippet/b", "snippet/nested/c"),
|
assertEquals(List.of("snippet/a", "snippet/nested/c"),
|
||||||
new ArrayList<>(data().getPossibleSnippets("rate")));
|
data().getPossibleSnippets("rate").stream().sorted().toList());
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onlyTheIrisNamespaceHoldsNamespacedFoldersListedInSortedOrder() throws IOException {
|
|
||||||
write("snippet/zeta/spawn/rate/x.json", "{}");
|
|
||||||
write("snippet/iris/spawn/rate/x.json", "{}");
|
|
||||||
write("snippet/iris/creatures/rate/x.json", "{}");
|
|
||||||
write("snippet/iris/spawn/duration/x.json", "{}");
|
|
||||||
|
|
||||||
assertEquals(List.of("snippet/iris/creatures/rate", "snippet/iris/spawn/rate"),
|
|
||||||
data().getNamespacedSnippetFolders("rate"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void nestedLegacyFolderNamedLikeATypeStaysLegacy() throws IOException {
|
|
||||||
write("snippet/procedural/objects/rate/nested.json", "{\"amount\":7}");
|
|
||||||
|
|
||||||
assertNull(rateOf("\"snippet/nested\""));
|
|
||||||
assertEquals(List.of(), data().getNamespacedSnippetFolders("rate"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void folderListingRefreshesAfterTheListsAreCleared() throws IOException {
|
|
||||||
IrisData loaded = data();
|
|
||||||
assertEquals(List.of(), loaded.getNamespacedSnippetFolders("rate"));
|
|
||||||
|
|
||||||
write("snippet/iris/spawn/rate/x.json", "{\"amount\":2}");
|
|
||||||
loaded.clearLists();
|
|
||||||
|
|
||||||
assertEquals(List.of("snippet/iris/spawn/rate"), loaded.getNamespacedSnippetFolders("rate"));
|
|
||||||
assertEquals(2, rateOf("\"snippet/x\"").getAmount());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IrisRate rateOf(String jsonValue) {
|
private IrisRate rateOf(String jsonValue) {
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package art.arcane.iris.pack.loading;
|
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class PackSnippetsTest {
|
|
||||||
@Rule
|
|
||||||
public final TemporaryFolder temporary = new TemporaryFolder();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void foldersOfATypeAreDiscoveredOncePerInstance() throws IOException {
|
|
||||||
File pack = temporary.newFolder("pack");
|
|
||||||
createFolder(pack, "snippet/iris/spawn/rate");
|
|
||||||
PackSnippets snippets = new PackSnippets(pack);
|
|
||||||
assertEquals(List.of("snippet/iris/spawn/rate"), snippets.folders("rate").namespaced());
|
|
||||||
|
|
||||||
createFolder(pack, "snippet/iris/creatures/rate");
|
|
||||||
|
|
||||||
assertEquals(List.of("snippet/iris/spawn/rate"), snippets.folders("rate").namespaced());
|
|
||||||
assertEquals(List.of("snippet/iris/creatures/rate", "snippet/iris/spawn/rate"),
|
|
||||||
new PackSnippets(pack).folders("rate").namespaced());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void createFolder(File pack, String relative) throws IOException {
|
|
||||||
Files.createDirectories(pack.toPath().resolve(relative));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package art.arcane.iris.pack.schema;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class SchemaBuilderSnippetPatternTest {
|
|
||||||
@Test
|
|
||||||
public void legacyOnlyPatternKeepsItsPlainForm() {
|
|
||||||
assertEquals("^snippet/rate/", SchemaBuilder.snippetPattern("rate", List.of()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dotInAGroupFolderMatchesOnlyADot() {
|
|
||||||
String pattern = SchemaBuilder.snippetPattern("rate", List.of("snippet/iris/my.group/rate"));
|
|
||||||
|
|
||||||
assertEquals("^(?:snippet/rate|snippet/iris/my\\.group/rate)/", pattern);
|
|
||||||
assertTrue(Pattern.compile(pattern).matcher("snippet/iris/my.group/rate/fast").find());
|
|
||||||
assertFalse(Pattern.compile(pattern).matcher("snippet/iris/myXgroup/rate/fast").find());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void everyRegexSyntaxCharacterIsEscapedOnItsOwn() {
|
|
||||||
String folder = "snippet/iris/a^$\\.*+?()[]{}|b/rate";
|
|
||||||
|
|
||||||
String pattern = SchemaBuilder.snippetPattern("rate", List.of(folder));
|
|
||||||
|
|
||||||
assertEquals("^(?:snippet/rate|snippet/iris/a\\^\\$\\\\\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|b/rate)/", pattern);
|
|
||||||
assertTrue(Pattern.compile(pattern).matcher(folder + "/fast").find());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ package art.arcane.iris.structure.object;
|
|||||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||||
|
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
import art.arcane.iris.pack.loading.SnippetFolders;
|
|
||||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||||
import art.arcane.volmlib.util.math.RNG;
|
import art.arcane.volmlib.util.math.RNG;
|
||||||
@@ -25,9 +24,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -131,8 +128,6 @@ public class IrisObjectGlobalScaleTest {
|
|||||||
Files.writeString(snippets.resolve("half.json"), "{\"size\":0.5}");
|
Files.writeString(snippets.resolve("half.json"), "{\"size\":0.5}");
|
||||||
IrisData data = mock(IrisData.class, CALLS_REAL_METHODS);
|
IrisData data = mock(IrisData.class, CALLS_REAL_METHODS);
|
||||||
when(data.getDataFolder()).thenReturn(root.toFile());
|
when(data.getDataFolder()).thenReturn(root.toFile());
|
||||||
doAnswer(lookup -> SnippetFolders.discover(root.toFile(), lookup.getArgument(0)))
|
|
||||||
.when(data).getSnippetFolders(anyString());
|
|
||||||
Gson loaderGson = new GsonBuilder().registerTypeAdapterFactory(data).create();
|
Gson loaderGson = new GsonBuilder().registerTypeAdapterFactory(data).create();
|
||||||
IrisDimension dimension = new IrisDimension().setAllObjectScaleFactor(2D);
|
IrisDimension dimension = new IrisDimension().setAllObjectScaleFactor(2D);
|
||||||
IrisObject origin = new IrisObject(4, 4, 4);
|
IrisObject origin = new IrisObject(4, 4, 4);
|
||||||
|
|||||||
Reference in new issue
Block a user