mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Serve module resource kinds through IrisPackResources, run module validators wherever packs are validated, and drop the structure, jigsaw pool and piece loaders and validators from core
This commit is contained in:
1 parent
12c315bb52
commit
2f3ba3cebe
55 files changed
+1770
-1060
No files matched your search
@@ -89,7 +89,7 @@ public class IrisPackResourcesTest {
|
||||
when(regionLoader.getPossibleKeys()).thenReturn(new String[]{"desert"});
|
||||
when(regionLoader.load("desert")).thenReturn(desert);
|
||||
|
||||
resources = new IrisPackResources(data);
|
||||
resources = new IrisPackResources(data, List::of);
|
||||
}
|
||||
|
||||
private ResourceId id(String path) {
|
||||
@@ -103,7 +103,7 @@ public class IrisPackResourcesTest {
|
||||
|
||||
@Test
|
||||
public void everySnapshotHasItsOwnId() {
|
||||
assertNotEquals(resources.snapshotId(), new IrisPackResources(data).snapshotId());
|
||||
assertNotEquals(resources.snapshotId(), new IrisPackResources(data, List::of).snapshotId());
|
||||
assertEquals(resources.snapshotId(), resources.snapshotId());
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class IrisPackResourcesTest {
|
||||
@Test
|
||||
public void aResourceThatExistsButFailsToLoadIsAnErrorNotAbsent() {
|
||||
when(objectLoader.getPossibleKeys()).thenReturn(new String[]{"trees/broken"});
|
||||
IrisPackResources fresh = new IrisPackResources(data);
|
||||
IrisPackResources fresh = new IrisPackResources(data, List::of);
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> fresh.find(new ResourceKey<>(id("trees/broken"), GeneratedObject.class)));
|
||||
}
|
||||
@@ -180,7 +180,7 @@ public class IrisPackResourcesTest {
|
||||
IrisObject object = mock(IrisObject.class);
|
||||
when(object.getGeometry()).thenReturn(tree);
|
||||
when(objectLoader.load("Trees/Oak")).thenReturn(object);
|
||||
IrisPackResources fresh = new IrisPackResources(data);
|
||||
IrisPackResources fresh = new IrisPackResources(data, List::of);
|
||||
|
||||
assertSame(tree, fresh.require(new ResourceKey<>(id("trees/oak"), GeneratedObject.class)));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.host.DiscoveredModule;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.ModuleRegistry;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* A pack whose module resources (structures, jigsaw pools, pieces or any other kind) a test sets by key, served by a
|
||||
* mocked {@link IrisPackResources} the way lookups by pack key find them, such as
|
||||
* {@code StructureResources.structure(data, key)}: ids in namespace {@code test}, a key absent unless set.
|
||||
*/
|
||||
public final class ModuleResourceFixture {
|
||||
private static final String NAMESPACE = "test";
|
||||
private static final Map<IrisPackResources, ModuleResourceFixture> SERVED = new IdentityHashMap<>();
|
||||
|
||||
private final IrisPackResources resources;
|
||||
private final Map<Class<?>, List<ResourceId>> ids = new HashMap<>();
|
||||
|
||||
private ModuleResourceFixture(IrisPackResources resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
/** Makes {@code data} (a mock) serve the structures, pools and pieces set on the returned fixture, none at first. */
|
||||
public static synchronized ModuleResourceFixture serve(IrisData data) {
|
||||
IrisPackResources resources = mock(IrisPackResources.class);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
when(resources.idOf(anyString())).thenAnswer(invocation -> idOf(invocation.getArgument(0)));
|
||||
ModuleResourceFixture fixture = new ModuleResourceFixture(resources);
|
||||
SERVED.put(resources, fixture);
|
||||
return fixture;
|
||||
}
|
||||
|
||||
/** The fixture {@code data} (a mock) already serves from, or a new one. */
|
||||
public static synchronized ModuleResourceFixture of(IrisData data) {
|
||||
ModuleResourceFixture served = SERVED.get(data.getPackResources());
|
||||
return served != null ? served : serve(data);
|
||||
}
|
||||
|
||||
/** The catalog of a pack with only {@code modules}, as built-ins: their resource kinds, validators and other registrations. */
|
||||
public static FeatureCatalog catalogOf(IrisModule... modules) {
|
||||
ModuleRegistry registry = new ModuleRegistry();
|
||||
for (IrisModule module : modules) {
|
||||
registry.register(DiscoveredModule.builtIn(module));
|
||||
}
|
||||
return registry.freeze();
|
||||
}
|
||||
|
||||
/** Serves {@code resource} as the resource of {@code kind} the pack names by {@code key}. */
|
||||
public <T> ModuleResourceFixture resource(ResourceKind<T> kind, String key, T resource) {
|
||||
ResourceId id = idOf(key);
|
||||
when(resources.find(kind.key(id))).thenReturn(Optional.of(resource));
|
||||
List<ResourceId> kindIds = ids.computeIfAbsent(kind.type(), ignored -> new ArrayList<>());
|
||||
kindIds.add(id);
|
||||
when(resources.ids(kind.type())).thenReturn(kindIds.stream().sorted().toList());
|
||||
return this;
|
||||
}
|
||||
|
||||
private static ResourceId idOf(String key) {
|
||||
return new ResourceId(NAMESPACE, key.toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9_./-]", "_"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import javax.tools.DiagnosticCollector;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.ToolProvider;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/** Compiles a pack module's sources against the Iris API on the test classpath into {@code <pack>/modules/<jar>}. */
|
||||
public final class PackModuleJar {
|
||||
private static final String SERVICE_ENTRY = "META-INF/services/com.volmit.IrisModule";
|
||||
|
||||
private PackModuleJar() {
|
||||
}
|
||||
|
||||
/** @param sources Java sources by binary class name; {@code entryClass} is the module's entry point */
|
||||
public static void write(Path pack, String jarName, String entryClass, Map<String, String> sources) throws IOException {
|
||||
Path work = Files.createTempDirectory("iris-pack-module-src");
|
||||
Path classes = Files.createDirectories(work.resolve("classes"));
|
||||
compile(work, classes, sources);
|
||||
Path jar = Files.createDirectories(pack.resolve("modules")).resolve(jarName);
|
||||
try (JarOutputStream output = new JarOutputStream(Files.newOutputStream(jar))) {
|
||||
addClasses(output, classes);
|
||||
output.putNextEntry(new JarEntry(SERVICE_ENTRY));
|
||||
output.write((entryClass + "\n").getBytes(StandardCharsets.UTF_8));
|
||||
output.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
private static void compile(Path work, Path classes, Map<String, String> sources) throws IOException {
|
||||
List<Path> files = new ArrayList<>();
|
||||
for (Map.Entry<String, String> source : sources.entrySet()) {
|
||||
Path file = work.resolve("src").resolve(source.getKey().replace('.', '/') + ".java");
|
||||
Files.createDirectories(file.getParent());
|
||||
Files.writeString(file, source.getValue(), StandardCharsets.UTF_8);
|
||||
files.add(file);
|
||||
}
|
||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
|
||||
try (StandardJavaFileManager manager = compiler.getStandardFileManager(diagnostics, null, StandardCharsets.UTF_8)) {
|
||||
List<String> options = List.of("-classpath", System.getProperty("java.class.path"), "-d", classes.toString());
|
||||
boolean compiled = compiler.getTask(null, manager, diagnostics, options, null, manager.getJavaFileObjectsFromPaths(files)).call();
|
||||
if (!compiled) {
|
||||
throw new IllegalStateException("Module sources do not compile: " + diagnostics.getDiagnostics());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addClasses(JarOutputStream output, Path classes) throws IOException {
|
||||
try (Stream<Path> files = Files.walk(classes)) {
|
||||
for (Path file : files.filter(Files::isRegularFile).sorted().toList()) {
|
||||
output.putNextEntry(new JarEntry(classes.relativize(file).toString().replace('\\', '/')));
|
||||
output.write(Files.readAllBytes(file));
|
||||
output.closeEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.pack.PackValidationResult;
|
||||
import art.arcane.iris.core.pack.PackValidator;
|
||||
import art.arcane.iris.core.project.ModuleResourceSchemas;
|
||||
import art.arcane.iris.core.project.SchemaTestPlatform;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.volmit.host.ResourceKindRegistration;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* A pack module that declares a resource kind of its own class and a validator, loaded from a real jar in the
|
||||
* pack's {@code modules} folder: Iris reads the kind's folder generically, serves it through PackResources, describes
|
||||
* it for studio and runs the validator wherever it validates the pack.
|
||||
*/
|
||||
public class PackModuleResourceKindTest {
|
||||
private static final String MODULE = """
|
||||
package pack.castle;
|
||||
|
||||
import com.volmit.*;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.stage.StageGraph;
|
||||
|
||||
public final class CastleModule implements IrisModule {
|
||||
public static final ResourceKind<Keep> KEEPS = ResourceKind.of("example:castle/keep", "keeps", Keep.class);
|
||||
|
||||
public ModuleInfo info() { return ModuleInfo.of("example:castle", "Castles", "1"); }
|
||||
public void install(StageGraph graph) {}
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerResourceKind(KEEPS);
|
||||
registry.registerValidator(new KeepValidator());
|
||||
}
|
||||
}
|
||||
""";
|
||||
private static final String KEEP = """
|
||||
package pack.castle;
|
||||
|
||||
import com.volmit.config.*;
|
||||
|
||||
@Desc("A keep of a castle")
|
||||
public final class Keep {
|
||||
@Desc("Towers on the walls") @MinNumber(1)
|
||||
private int towers = 4;
|
||||
@ResourceRef(Keep.class)
|
||||
private String next = "";
|
||||
|
||||
public int towers() { return towers; }
|
||||
public String next() { return next; }
|
||||
}
|
||||
""";
|
||||
private static final String VALIDATOR = """
|
||||
package pack.castle;
|
||||
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.validation.*;
|
||||
|
||||
public final class KeepValidator implements Validator {
|
||||
public void validate(ValidationContext pack) {
|
||||
for (ResourceId id : pack.resources().ids(Keep.class)) {
|
||||
Keep keep = pack.resources().require(CastleModule.KEEPS.key(id));
|
||||
if (keep.towers() > 8) {
|
||||
pack.report(Problem.error(Subject.file("keeps/" + id.path() + ".json"), "Keep has " + keep.towers() + " towers; at most 8 fit."));
|
||||
}
|
||||
ResourceId next = new ResourceId(id.namespace(), keep.next().isEmpty() ? id.path() : keep.next());
|
||||
if (pack.resources().find(CastleModule.KEEPS.key(next)).isEmpty()) {
|
||||
pack.report(Problem.warning(Subject.resource(id), "Keep leads to missing keep " + keep.next() + "."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
private static final String HOST_FOLDER_MODULE = """
|
||||
package pack.greedy;
|
||||
|
||||
import com.volmit.*;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.stage.StageGraph;
|
||||
|
||||
public final class GreedyModule implements IrisModule {
|
||||
public ModuleInfo info() { return ModuleInfo.of("example:greedy", "Greedy", "1"); }
|
||||
public void install(StageGraph graph) {}
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerResourceKind(ResourceKind.of("example:greedy/biome", "biomes", Grab.class));
|
||||
}
|
||||
}
|
||||
""";
|
||||
private static final String GRAB = """
|
||||
package pack.greedy;
|
||||
|
||||
public final class Grab {
|
||||
}
|
||||
""";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void aPackModulesKindIsReadFromItsFolderAndServedByType() throws Exception {
|
||||
Path pack = castlePack("castles");
|
||||
write(pack, "keeps/main.json", "{\"towers\":6,\"next\":\"towers/north\"}");
|
||||
write(pack, "keeps/towers/north.json", "{}");
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try {
|
||||
ResourceKind<?> keeps = keepKind(data);
|
||||
ResourceId main = new ResourceId("castles", "main");
|
||||
|
||||
assertEquals(List.of(main, new ResourceId("castles", "towers/north")), data.getPackResources().ids(keeps.type()));
|
||||
Object keep = data.getPackResources().find(keeps.key(main)).orElseThrow();
|
||||
assertEquals(6, keep.getClass().getMethod("towers").invoke(keep));
|
||||
assertEquals("towers/north", keep.getClass().getMethod("next").invoke(keep));
|
||||
Object north = data.getPackResources().find(keeps.key(new ResourceId("castles", "towers/north"))).orElseThrow();
|
||||
assertEquals("an omitted field keeps its default", 4, north.getClass().getMethod("towers").invoke(north));
|
||||
assertSame("read once per pack load", keep, data.getPackResources().find(keeps.key(main)).orElseThrow());
|
||||
assertTrue(data.getPackResources().find(keeps.key(new ResourceId("castles", "missing"))).isEmpty());
|
||||
assertTrue(data.getPackResources().moduleFolderNames().containsAll(List.of("keeps", "structures")));
|
||||
assertTrue(data.resourceFolderNames().contains("keeps"));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aModuleResourceThatFailsToReadIsAnErrorNotAbsent() throws Exception {
|
||||
Path pack = castlePack("broken-castles");
|
||||
write(pack, "keeps/main.json", "{\"towers\":\"many\"}");
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try {
|
||||
ResourceKind<?> keeps = keepKind(data);
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> data.getPackResources().find(keeps.key(new ResourceId("broken-castles", "main"))));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packValidationRunsThePackModulesValidatorWithItsSeverities() throws Exception {
|
||||
Path pack = castlePack("validated-castles");
|
||||
write(pack, "keeps/main.json", "{\"towers\":12,\"next\":\"gone\"}");
|
||||
|
||||
PackValidationResult result = PackValidator.validate(pack.toFile());
|
||||
|
||||
assertTrue(result.getBlockingErrors().toString(),
|
||||
result.getBlockingErrors().contains("keeps/main.json: Keep has 12 towers; at most 8 fit."));
|
||||
assertTrue(result.getWarnings().toString(),
|
||||
result.getWarnings().contains("validated-castles:main: Keep leads to missing keep gone."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioDescribesTheKindFromItsClassAndCompletesReferencesWithItsKeys() throws Exception {
|
||||
Path pack = castlePack("studio-castles");
|
||||
write(pack, "keeps/main.json", "{}");
|
||||
write(pack, "keeps/towers/north.json", "{}");
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try (SchemaTestPlatform ignored = SchemaTestPlatform.bind(temporaryFolder.getRoot())) {
|
||||
JSONObject entry = ModuleResourceSchemas.entries(data, true).stream()
|
||||
.filter(candidate -> candidate.getString("url").equals("./.iris/schema/keeps-schema.json"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
assertEquals("/keeps/*.json", entry.getJSONArray("fileMatch").getString(0));
|
||||
JSONObject schema = new JSONObject(Files.readString(pack.resolve(".iris/schema/keeps-schema.json")));
|
||||
JSONObject properties = schema.getJSONObject("properties");
|
||||
assertEquals("A keep of a castle", schema.getString("description"));
|
||||
assertEquals(1, properties.getJSONObject("towers").getInt("minimum"));
|
||||
assertEquals("#/definitions/erzkeeps", properties.getJSONObject("next").getString("$ref"));
|
||||
assertEquals("[\"main\",\"towers/north\"]",
|
||||
schema.getJSONObject("definitions").getJSONObject("erzkeeps").getJSONArray("enum").toString());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aKindMayNotReadAFolderIrisReadsItself() throws Exception {
|
||||
Path pack = temporaryFolder.newFolder("greedy").toPath();
|
||||
PackModuleJar.write(pack, "greedy.jar", "pack.greedy.GreedyModule",
|
||||
Map.of("pack.greedy.GreedyModule", HOST_FOLDER_MODULE, "pack.greedy.Grab", GRAB));
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try {
|
||||
PackModulesException failure = assertThrows(PackModulesException.class, () -> data.getModules().pack());
|
||||
|
||||
assertEquals("Pack greedy cannot load its modules: Resource kind example:greedy/biome of module example:greedy"
|
||||
+ " from modules/greedy.jar reads folder 'biomes', which the host reads itself; give the kind a folder of"
|
||||
+ " its own", failure.getMessage());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Path castlePack(String name) throws Exception {
|
||||
File pack = temporaryFolder.newFolder(name);
|
||||
write(pack.toPath(), "dimensions/main.json", "{\"regions\":[\"region\"]}");
|
||||
write(pack.toPath(), "regions/region.json", "{\"landBiomes\":[\"biome\"]}");
|
||||
write(pack.toPath(), "biomes/biome.json", "{\"name\":\"Biome\"}");
|
||||
PackModuleJar.write(pack.toPath(), "castle.jar", "pack.castle.CastleModule",
|
||||
Map.of("pack.castle.CastleModule", MODULE, "pack.castle.Keep", KEEP, "pack.castle.KeepValidator", VALIDATOR));
|
||||
return pack.toPath();
|
||||
}
|
||||
|
||||
private static ResourceKind<?> keepKind(IrisData data) {
|
||||
return data.getModules().pack().catalog().resourceKinds().stream()
|
||||
.map(ResourceKindRegistration::kind)
|
||||
.filter(kind -> kind.id().toString().equals("example:castle/keep"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
private static void write(Path root, String relative, String content) throws Exception {
|
||||
Path path = root.resolve(relative);
|
||||
Files.createDirectories(path.getParent());
|
||||
Files.writeString(path, content, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package art.arcane.iris.core.pack;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.core.modules.IrisValidationContext;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.host.DiscoveredModule;
|
||||
import com.volmit.host.ValidatorRegistration;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.validation.Problem;
|
||||
import com.volmit.validation.Subject;
|
||||
import com.volmit.validation.Validator;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Module validators run where Iris validates packs, and what they report keeps its severity. */
|
||||
public class ModulePackValidationTest {
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void errorsBlockAndWarningsOnlyShowEachWithItsSubject() {
|
||||
IrisData data = packData();
|
||||
Validator validator = pack -> {
|
||||
pack.report(Problem.error(Subject.file("keeps/main.json"), "Keep main has no walls."));
|
||||
pack.report(Problem.warning(Subject.resource(ResourceId.parse("castles:main")), "Keep main is very tall."));
|
||||
};
|
||||
|
||||
ModulePackValidation.Findings findings = ModulePackValidation.validate(data, List.of(registration("example:keeps", validator)));
|
||||
|
||||
assertEquals(List.of("keeps/main.json: Keep main has no walls."), findings.errors());
|
||||
assertEquals(List.of("castles:main: Keep main is very tall."), findings.warnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aValidatorThatThrowsFailsValidationNamingItsModuleAndTheOthersStillRun() {
|
||||
IrisData data = packData();
|
||||
Validator broken = pack -> {
|
||||
pack.report(Problem.warning(Subject.file("keeps/main.json"), "Reported before failing."));
|
||||
throw new IllegalStateException("no walls to count");
|
||||
};
|
||||
Validator healthy = pack -> pack.report(Problem.error(Subject.file("keeps/other.json"), "Still checked."));
|
||||
|
||||
ModulePackValidation.Findings findings = ModulePackValidation.validate(data,
|
||||
List.of(registration("example:broken", broken), registration("example:healthy", healthy)));
|
||||
|
||||
assertEquals(List.of("Module example:broken from host classpath failed while validating the pack:"
|
||||
+ " java.lang.IllegalStateException: no walls to count", "keeps/other.json: Still checked."), findings.errors());
|
||||
assertEquals(List.of("keeps/main.json: Reported before failing."), findings.warnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validatorsSeeThePacksResourcesAndIrisSeesItsOwnData() {
|
||||
IrisData data = packData();
|
||||
IrisPackResources resources = mock(IrisPackResources.class);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
List<Object> seen = new ArrayList<>();
|
||||
Validator validator = pack -> {
|
||||
seen.add(pack.resources());
|
||||
seen.add(IrisValidationContext.of(pack).data());
|
||||
};
|
||||
|
||||
ModulePackValidation.validate(data, List.of(registration("example:keeps", validator)));
|
||||
|
||||
assertSame(resources, seen.get(0));
|
||||
assertSame(data, seen.get(1));
|
||||
assertThrows(IllegalArgumentException.class, () -> IrisValidationContext.of(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packValidationRunsTheValidatorsOfThePacksModulesAndReportsModulesThatFailToLoad() throws Exception {
|
||||
File pack = minimalPack("broken-modules");
|
||||
Files.createDirectories(pack.toPath().resolve("modules"));
|
||||
Files.writeString(pack.toPath().resolve("modules/broken.jar"), "not a jar", StandardCharsets.UTF_8);
|
||||
|
||||
PackValidationResult result = PackValidator.validate(pack);
|
||||
|
||||
assertTrue(result.getBlockingErrors().toString(), result.getBlockingErrors().stream()
|
||||
.anyMatch(error -> error.startsWith("Pack broken-modules cannot load its modules: ")));
|
||||
}
|
||||
|
||||
private IrisData packData() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getDataFolder()).thenReturn(temporaryFolder.getRoot());
|
||||
return data;
|
||||
}
|
||||
|
||||
private File minimalPack(String name) throws Exception {
|
||||
File pack = temporaryFolder.newFolder(name);
|
||||
write(pack, "dimensions/main.json", "{\"regions\":[\"region\"]}");
|
||||
write(pack, "regions/region.json", "{\"landBiomes\":[\"biome\"]}");
|
||||
write(pack, "biomes/biome.json", "{\"name\":\"Biome\"}");
|
||||
return pack;
|
||||
}
|
||||
|
||||
private static ValidatorRegistration registration(String moduleId, Validator validator) {
|
||||
IrisModule module = new IrisModule() {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of(moduleId, "Test", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
}
|
||||
};
|
||||
return new ValidatorRegistration(validator, DiscoveredModule.builtIn(module));
|
||||
}
|
||||
|
||||
private static void write(File root, String relative, String content) throws Exception {
|
||||
Path path = root.toPath().resolve(relative);
|
||||
Files.createDirectories(path.getParent());
|
||||
Files.writeString(path, content, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package art.arcane.iris.core.pack;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.NativeReplacementValidation;
|
||||
import art.arcane.iris.engine.framework.structure.StructureGraphValidation;
|
||||
import art.arcane.iris.engine.framework.structure.StructureValidator;
|
||||
import com.volmit.validation.Problem;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformStructureHooks;
|
||||
@@ -53,7 +57,7 @@ public class PackValidatorStructureGraphTest {
|
||||
write(pack, "structures/regional.json", "{}");
|
||||
write(pack, "structures/library.json", "{}");
|
||||
|
||||
assertEquals(Set.of("active", "regional"), PackObjectSurfaceValidator.collectPlacedStructureKeys(pack));
|
||||
assertEquals(Set.of("active", "regional"), StructureValidator.placedStructureKeys(pack));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +73,7 @@ public class PackValidatorStructureGraphTest {
|
||||
+ "\"lobeFrequency\":0.02,\"lobeStrength\":0.85}}]}");
|
||||
|
||||
assertTrue(PackObjectSurfaceValidator.validateStructureGraph(pack).isEmpty());
|
||||
assertTrue(PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
assertTrue(nativeReplacementErrors(
|
||||
pack, Set.of(), Map.of()).isEmpty());
|
||||
}
|
||||
|
||||
@@ -584,7 +588,7 @@ public class PackValidatorStructureGraphTest {
|
||||
+ "\"nativeSuppression\":\"REPLACE_SOURCE\"}]}");
|
||||
write(pack, "structures/city.json", "{\"vanillaSource\":\"minecraft:ancient_city\"}");
|
||||
|
||||
assertTrue(PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
assertTrue(nativeReplacementErrors(
|
||||
pack, Set.of("city"), sampledEnvelope("city", 1, 0, 0)).isEmpty());
|
||||
}
|
||||
|
||||
@@ -595,7 +599,7 @@ public class PackValidatorStructureGraphTest {
|
||||
+ "\"nativeStructures\":[{\"structure\":\"minecraft:ancient_city\"}],"
|
||||
+ "\"nativeSuppression\":\"REPLACE_SOURCE\"}]}");
|
||||
|
||||
assertTrue(PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
assertTrue(nativeReplacementErrors(
|
||||
pack, Set.of(), Map.of()).isEmpty());
|
||||
}
|
||||
|
||||
@@ -606,7 +610,7 @@ public class PackValidatorStructureGraphTest {
|
||||
+ "\"nativeSuppression\":\"REPLACE_SOURCE\"}]}");
|
||||
write(pack, "structures/city.json", "{\"vanillaSource\":\"minecraft:ancient_city\"}");
|
||||
|
||||
List<String> errors = PackNativeStructureValidator.validateNativeStructureReplacements(pack, Set.of(), Map.of());
|
||||
List<String> errors = nativeReplacementErrors(pack, Set.of(), Map.of());
|
||||
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(message -> message.contains("not runtime-viable")));
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(message -> message.contains("will not be used as a fallback")));
|
||||
@@ -619,7 +623,7 @@ public class PackValidatorStructureGraphTest {
|
||||
+ "\"nativeSuppression\":\"REPLACE_SOURCE\"}]}");
|
||||
write(pack, "structures/city.json", "{\"vanillaSource\":\"\"}");
|
||||
|
||||
List<String> errors = PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
List<String> errors = nativeReplacementErrors(
|
||||
pack, Set.of("city"), sampledEnvelope("city", 1, -1, 1));
|
||||
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(
|
||||
@@ -633,7 +637,7 @@ public class PackValidatorStructureGraphTest {
|
||||
+ "\"nativeSuppression\":\"REPLACE_SOURCE\"}]}");
|
||||
write(pack, "structures/city.json", "{\"vanillaSource\":\"minecraft:ancient_city\"}");
|
||||
|
||||
List<String> errors = PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
List<String> errors = nativeReplacementErrors(
|
||||
pack, Set.of("city"), sampledEnvelope("city", 1, -1, 1));
|
||||
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(
|
||||
@@ -644,7 +648,7 @@ public class PackValidatorStructureGraphTest {
|
||||
public void rejectsUndergroundReplacementBelowDimensionWritableRange() throws Exception {
|
||||
File pack = replacementPack("below", "STRUCTURE_PIECE", true, -80, -80);
|
||||
|
||||
List<String> errors = PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
List<String> errors = nativeReplacementErrors(
|
||||
pack, Set.of("city"), sampledEnvelope("city", 1, -5, 4));
|
||||
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(message -> message.contains("sampled seed 0")
|
||||
@@ -658,7 +662,7 @@ public class PackValidatorStructureGraphTest {
|
||||
public void rejectsUndergroundReplacementAboveDimensionWritableRange() throws Exception {
|
||||
File pack = replacementPack("above", "STRUCTURE_PIECE", true, 318, 318);
|
||||
|
||||
List<String> errors = PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
List<String> errors = nativeReplacementErrors(
|
||||
pack, Set.of("city"), sampledEnvelope("city", 1, -5, 4));
|
||||
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(message -> message.contains("sampled seed 0")
|
||||
@@ -671,7 +675,7 @@ public class PackValidatorStructureGraphTest {
|
||||
public void surfaceAlignsMultiPieceEnvelopeBeforeCheckingWorldBounds() throws Exception {
|
||||
File pack = replacementPack("surface-aligned", "CENTER_HEIGHT", false, 290, 290);
|
||||
|
||||
List<String> errors = PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
List<String> errors = nativeReplacementErrors(
|
||||
pack, Set.of("city"), sampledEnvelope("city", 2, -30, 10));
|
||||
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(message -> message.contains("surface-aligned")
|
||||
@@ -683,7 +687,7 @@ public class PackValidatorStructureGraphTest {
|
||||
public void doesNotApplyExactYEnvelopeGateToSingleSurfacePiece() throws Exception {
|
||||
File pack = replacementPack("surface-single", "CENTER_HEIGHT", false, -63, 319);
|
||||
|
||||
List<String> errors = PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
List<String> errors = nativeReplacementErrors(
|
||||
pack, Set.of("city"), sampledEnvelope("city", 1, -500, 500));
|
||||
|
||||
assertTrue(errors.toString(), errors.isEmpty());
|
||||
@@ -693,7 +697,7 @@ public class PackValidatorStructureGraphTest {
|
||||
public void validatesEverySurfaceExactYAnchorAgainstWritableWorldBounds() throws Exception {
|
||||
File pack = replacementPack("surface-exact-range", "STRUCTURE_PIECE", false, -63, 319);
|
||||
|
||||
List<String> errors = PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
List<String> errors = nativeReplacementErrors(
|
||||
pack, Set.of("city"), sampledEnvelope("city", 1, -5, 4));
|
||||
|
||||
assertTrue(errors.toString(), errors.stream().anyMatch(message -> message.contains("sampled seed 0")
|
||||
@@ -706,7 +710,7 @@ public class PackValidatorStructureGraphTest {
|
||||
public void acceptsSurfaceExactYWhenEveryConfiguredAnchorFits() throws Exception {
|
||||
File pack = replacementPack("surface-exact-safe", "STRUCTURE_PIECE", false, -58, 315);
|
||||
|
||||
List<String> errors = PackNativeStructureValidator.validateNativeStructureReplacements(
|
||||
List<String> errors = nativeReplacementErrors(
|
||||
pack, Set.of("city"), sampledEnvelope("city", 1, -5, 4));
|
||||
|
||||
assertTrue(errors.toString(), errors.isEmpty());
|
||||
@@ -756,7 +760,7 @@ public class PackValidatorStructureGraphTest {
|
||||
}
|
||||
|
||||
PackValidationResult result = PackValidator.validate(pack);
|
||||
String expected = "Malformed Iris object resource " + object + ": EOFException";
|
||||
String expected = "structures/castle.json: Malformed Iris object resource " + object + ": EOFException";
|
||||
|
||||
assertTrue(result.getBlockingErrors().toString(), result.getBlockingErrors().contains(expected));
|
||||
assertFalse(result.getBlockingErrors().toString(), result.getBlockingErrors().stream().anyMatch(
|
||||
@@ -930,14 +934,24 @@ public class PackValidatorStructureGraphTest {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, List<StructureGraphPackValidator.SampledVerticalEnvelope>> sampledEnvelope(
|
||||
private static List<String> nativeReplacementErrors(
|
||||
File pack,
|
||||
Set<String> replacementOutputStructures,
|
||||
Map<String, List<StructureGraphValidation.SampledVerticalEnvelope>> sampledVerticalEnvelopes
|
||||
) {
|
||||
return NativeReplacementValidation.validate(pack, replacementOutputStructures, sampledVerticalEnvelopes).stream()
|
||||
.map(Problem::message)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Map<String, List<StructureGraphValidation.SampledVerticalEnvelope>> sampledEnvelope(
|
||||
String structureKey,
|
||||
int pieceCount,
|
||||
int minimumYOffset,
|
||||
int maximumYOffset
|
||||
) {
|
||||
return Map.of(structureKey, List.of(
|
||||
new StructureGraphPackValidator.SampledVerticalEnvelope(
|
||||
new StructureGraphValidation.SampledVerticalEnvelope(
|
||||
0L, pieceCount, minimumYOffset, maximumYOffset)));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package art.arcane.iris.core.project;
|
||||
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.PackModuleSet;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
@@ -64,6 +68,12 @@ public class IrisImageMapSchemaTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static IrisData schemaData() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
LoadedPack pack = mock(LoadedPack.class);
|
||||
PackModuleSet modules = mock(PackModuleSet.class);
|
||||
when(pack.catalog()).thenReturn(ModuleResourceFixture.catalogOf(new StructureModule()));
|
||||
when(modules.pack()).thenReturn(pack);
|
||||
when(data.getModules()).thenReturn(modules);
|
||||
ModuleResourceFixture.serve(data);
|
||||
KMap<Class<? extends IrisRegistrant>, ResourceLoader<? extends IrisRegistrant>> loaders = new KMap<>();
|
||||
when(data.getLoaders()).thenReturn(loaders);
|
||||
when(data.getPossibleSnippets(anyString())).thenReturn(new KList<>());
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.project;
|
||||
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
@@ -25,7 +26,6 @@ import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.noise.expression.IrisExpression;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisVanillaStructureAdjustment;
|
||||
@@ -60,6 +60,7 @@ import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import art.arcane.iris.core.modules.PackModuleSet;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -318,7 +319,7 @@ public class SchemaBuilderParityTest {
|
||||
}
|
||||
|
||||
private static IrisData structureSchemaData() {
|
||||
return structureSchemaData(new PackSchema(List.of(), List.of()));
|
||||
return structureSchemaData(new PackSchema(List.of(), List.of(), List.of()));
|
||||
}
|
||||
|
||||
/** {@code modules} is what the pack's modules add to its JSON. */
|
||||
@@ -327,21 +328,17 @@ public class SchemaBuilderParityTest {
|
||||
LoadedPack pack = mock(LoadedPack.class);
|
||||
PackModuleSet moduleSet = mock(PackModuleSet.class);
|
||||
when(pack.schema()).thenReturn(modules);
|
||||
when(pack.catalog()).thenReturn(ModuleResourceFixture.catalogOf(new StructureModule()));
|
||||
when(moduleSet.pack()).thenReturn(pack);
|
||||
when(data.getModules()).thenReturn(moduleSet);
|
||||
ResourceLoader<IrisStructure> structureLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
ModuleResourceFixture.serve(data);
|
||||
ResourceLoader<IrisExpression> expressionLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisBlockData> blockLoader = mock(ResourceLoader.class);
|
||||
KMap<Class<? extends IrisRegistrant>, ResourceLoader<? extends IrisRegistrant>> loaders = new KMap<>();
|
||||
loaders.put(IrisExpression.class, expressionLoader);
|
||||
when(data.getStructureLoader()).thenReturn(structureLoader);
|
||||
when(data.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
when(data.getBlockLoader()).thenReturn(blockLoader);
|
||||
when(data.getLoaders()).thenReturn(loaders);
|
||||
when(data.getPossibleSnippets(anyString())).thenReturn(new KList<>());
|
||||
when(structureLoader.getPossibleKeys()).thenReturn(new String[0]);
|
||||
when(pieceLoader.getPossibleKeys()).thenReturn(new String[0]);
|
||||
when(blockLoader.getPossibleKeys()).thenReturn(new String[0]);
|
||||
when(expressionLoader.getPossibleKeys()).thenReturn(new String[0]);
|
||||
when(expressionLoader.getFolderName()).thenReturn("expressions");
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package art.arcane.iris.core.project;
|
||||
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import org.mockito.Answers;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Binds a platform whose registries list nothing, so studio schemas can be built in a test; closing restores the previous one. */
|
||||
public final class SchemaTestPlatform implements AutoCloseable {
|
||||
private final IrisPlatform previous;
|
||||
|
||||
private SchemaTestPlatform(File dataFolder) {
|
||||
previous = IrisPlatforms.isBound() ? IrisPlatforms.get() : null;
|
||||
IrisPlatforms.unbind();
|
||||
IrisPlatform platform = mock(IrisPlatform.class, Answers.CALLS_REAL_METHODS);
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
when(platform.dataFolder()).thenReturn(dataFolder);
|
||||
when(platform.registries()).thenReturn(registries);
|
||||
IrisPlatforms.bind(platform);
|
||||
}
|
||||
|
||||
public static SchemaTestPlatform bind(File dataFolder) {
|
||||
return new SchemaTestPlatform(dataFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
IrisPlatforms.unbind();
|
||||
if (previous != null) {
|
||||
IrisPlatforms.bind(previous);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-28
@@ -1,7 +1,9 @@
|
||||
package art.arcane.iris.core.runtime.jigsaw;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.core.structure.authoring.StructureBackend;
|
||||
import art.arcane.iris.core.structure.authoring.StructureKey;
|
||||
import art.arcane.iris.core.structure.authoring.StructureOwnershipManifest;
|
||||
@@ -63,16 +65,13 @@ public class JigsawStudioGraphMapperTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void catalogPreservesDuplicateWeightedPoolEntries() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
ResourceLoader<IrisJigsawPool> poolLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
when(data.getJigsawPoolLoader()).thenReturn(poolLoader);
|
||||
when(data.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(data);
|
||||
|
||||
IrisJigsawPool start = new IrisJigsawPool().setPieces(new KList<>());
|
||||
start.getPieces().add(new IrisJigsawPieceEntry("village/end", 2).setChance(0.25D));
|
||||
start.getPieces().add(new IrisJigsawPieceEntry("village/end", 7));
|
||||
start.getPieces().add(new IrisJigsawPieceEntry("village/east", 5));
|
||||
when(poolLoader.load("village/start")).thenReturn(start);
|
||||
resources.resource(StructureResources.POOLS, "village/start", start);
|
||||
IrisJigsawPiece endPiece = planarPiece("village/end", IrisDirection.NORTH_NEGATIVE_Z)
|
||||
.setRules(new IrisJigsawPieceRules()
|
||||
.setMinimumDepth(1)
|
||||
@@ -81,8 +80,8 @@ public class JigsawStudioGraphMapperTest {
|
||||
.setMaximumPlacements(2)
|
||||
.setTerminal(true));
|
||||
endPiece.getThemes().add("spruce");
|
||||
when(pieceLoader.load("village/end")).thenReturn(endPiece);
|
||||
when(pieceLoader.load("village/east")).thenReturn(planarPiece(
|
||||
resources.resource(StructureResources.PIECES, "village/end", endPiece);
|
||||
resources.resource(StructureResources.PIECES, "village/east", planarPiece(
|
||||
"village/east", IrisDirection.EAST_POSITIVE_X));
|
||||
IrisStructure structure = new IrisStructure()
|
||||
.setStartPool("village/start")
|
||||
@@ -108,14 +107,11 @@ public class JigsawStudioGraphMapperTest {
|
||||
public void ownedUnassignedPiecesRequireOwnedObjectForEditing() throws Exception {
|
||||
Path root = temporaryFolder.newFolder("pack").toPath();
|
||||
IrisData data = mock(IrisData.class);
|
||||
ResourceLoader<IrisJigsawPool> poolLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
when(data.getDataFolder()).thenReturn(root.toFile());
|
||||
when(data.getJigsawPoolLoader()).thenReturn(poolLoader);
|
||||
when(data.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
when(pieceLoader.load("village/orphan")).thenReturn(planarPiece(
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(data);
|
||||
resources.resource(StructureResources.PIECES, "village/orphan", planarPiece(
|
||||
"village/orphan", IrisDirection.NORTH_NEGATIVE_Z));
|
||||
when(pieceLoader.load("village/incomplete")).thenReturn(planarPiece(
|
||||
resources.resource(StructureResources.PIECES, "village/incomplete", planarPiece(
|
||||
"village/incomplete", IrisDirection.EAST_POSITIVE_X));
|
||||
|
||||
IrisStructure structure = new IrisStructure()
|
||||
@@ -156,12 +152,9 @@ public class JigsawStudioGraphMapperTest {
|
||||
public void managedDatapackManifestResourcesRemainReadOnly() throws Exception {
|
||||
Path root = temporaryFolder.newFolder("managed-pack").toPath();
|
||||
IrisData data = mock(IrisData.class);
|
||||
ResourceLoader<IrisJigsawPool> poolLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
when(data.getDataFolder()).thenReturn(root.toFile());
|
||||
when(data.getJigsawPoolLoader()).thenReturn(poolLoader);
|
||||
when(data.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
when(pieceLoader.load("village/managed")).thenReturn(planarPiece(
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(data);
|
||||
resources.resource(StructureResources.PIECES, "village/managed", planarPiece(
|
||||
"village/managed", IrisDirection.NORTH_NEGATIVE_Z));
|
||||
|
||||
IrisStructure structure = new IrisStructure()
|
||||
@@ -238,18 +231,15 @@ public class JigsawStudioGraphMapperTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void mapsAuthorLabelsAndCanonicalPerVariantDimensionsIndependently() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
ResourceLoader<IrisJigsawPool> poolLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisObject> objectLoader = mock(ResourceLoader.class);
|
||||
when(data.getJigsawPoolLoader()).thenReturn(poolLoader);
|
||||
when(data.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(data);
|
||||
when(data.getObjectLoader()).thenReturn(objectLoader);
|
||||
IrisJigsawPool start = new IrisJigsawPool().setPieces(new KList<>());
|
||||
start.getPieces().add(new IrisJigsawPieceEntry("village/east-gate", 1));
|
||||
when(poolLoader.load("village/start")).thenReturn(start);
|
||||
resources.resource(StructureResources.POOLS, "village/start", start);
|
||||
IrisJigsawPiece gate = planarPiece("village/east-gate", IrisDirection.EAST_POSITIVE_X)
|
||||
.setDisplayName("East Gatehouse");
|
||||
when(pieceLoader.load("village/east-gate")).thenReturn(gate);
|
||||
resources.resource(StructureResources.PIECES, "village/east-gate", gate);
|
||||
when(objectLoader.load("village/east-gate")).thenReturn(new IrisObject(7, 3, 5));
|
||||
IrisStructure structure = new IrisStructure()
|
||||
.setStartPool("village/start")
|
||||
@@ -280,8 +270,7 @@ public class JigsawStudioGraphMapperTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void mapsSpatialWorkcellLabelWithoutChangingItsCanonicalRole() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getJigsawPoolLoader()).thenReturn(mock(ResourceLoader.class));
|
||||
when(data.getJigsawPieceLoader()).thenReturn(mock(ResourceLoader.class));
|
||||
ModuleResourceFixture.serve(data);
|
||||
IrisStructure structure = new IrisStructure()
|
||||
.setStartPool("stronghold/missing")
|
||||
.setMode(IrisJigsawMode.SPATIAL_JIGSAW)
|
||||
@@ -298,8 +287,7 @@ public class JigsawStudioGraphMapperTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void planarMapPreservesIndependentEmptyAndDisabledWorkcellBounds() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getJigsawPoolLoader()).thenReturn(mock(ResourceLoader.class));
|
||||
when(data.getJigsawPieceLoader()).thenReturn(mock(ResourceLoader.class));
|
||||
ModuleResourceFixture.serve(data);
|
||||
IrisStructure structure = new IrisStructure()
|
||||
.setStartPool("village/missing")
|
||||
.setMode(IrisJigsawMode.PLANAR_JIGSAW);
|
||||
|
||||
+7
-11
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.core.service;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioBounds;
|
||||
@@ -522,16 +524,12 @@ public class JigsawStudioServiceCaptureTest {
|
||||
when(request.structureKey()).thenReturn("qa/profile_final");
|
||||
IrisData source = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisObject> objectLoader = mock(ResourceLoader.class);
|
||||
when(request.source()).thenReturn(source);
|
||||
when(source.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(source);
|
||||
when(source.getObjectLoader()).thenReturn(objectLoader);
|
||||
when(pieceLoader.load("test/end", false))
|
||||
.thenReturn(new IrisJigsawPiece().setObject("test/end"));
|
||||
when(pieceLoader.load("test/straight", false))
|
||||
.thenReturn(new IrisJigsawPiece().setObject("test/straight"));
|
||||
resources.resource(StructureResources.PIECES, "test/end", new IrisJigsawPiece().setObject("test/end"));
|
||||
resources.resource(StructureResources.PIECES, "test/straight", new IrisJigsawPiece().setObject("test/straight"));
|
||||
when(objectLoader.load("test/end", false)).thenReturn(new IrisObject(16, 16, 16));
|
||||
when(objectLoader.load("test/straight", false)).thenReturn(new IrisObject(16, 16, 16));
|
||||
JigsawStudioGenerator generator = mock(JigsawStudioGenerator.class);
|
||||
@@ -648,15 +646,13 @@ public class JigsawStudioServiceCaptureTest {
|
||||
when(request.ownerId()).thenReturn(ownerId);
|
||||
IrisData source = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisObject> objectLoader = mock(ResourceLoader.class);
|
||||
IrisJigsawPiece piece = new IrisJigsawPiece().setObject("test/end");
|
||||
IrisObject object = new IrisObject(16, 16, 16);
|
||||
when(request.source()).thenReturn(source);
|
||||
when(source.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(source);
|
||||
when(source.getObjectLoader()).thenReturn(objectLoader);
|
||||
when(pieceLoader.load("test/end", false)).thenReturn(piece);
|
||||
resources.resource(StructureResources.PIECES, "test/end", piece);
|
||||
when(objectLoader.load("test/end", false)).thenReturn(object);
|
||||
JigsawStudioGenerator generator = mock(JigsawStudioGenerator.class);
|
||||
when(generator.getRequest()).thenReturn(request);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package art.arcane.iris.core.structure;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformStructureHooks;
|
||||
import art.arcane.volmlib.util.data.KCache;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -75,19 +76,23 @@ public class StructureIndexServiceTest {
|
||||
Files.createDirectories(legacyIndex.toPath().getParent());
|
||||
Files.writeString(legacyIndex.toPath(), "{}", StandardCharsets.UTF_8);
|
||||
IrisData data = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisStructure> structureLoader = mock(ResourceLoader.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
KCache<String, IrisStructure> loadCache = mock(KCache.class);
|
||||
when(data.getDataFolder()).thenReturn(pack);
|
||||
when(data.getStructureLoader()).thenReturn(structureLoader);
|
||||
when(structureLoader.getLoadCache()).thenReturn(loadCache);
|
||||
|
||||
StructureIndexService.removeLegacyIndex(data);
|
||||
|
||||
assertFalse(legacyIndex.exists());
|
||||
verify(loadCache).invalidate("structure-index");
|
||||
verify(structureLoader).clearList();
|
||||
verify(data).invalidateStructureResources();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structureResourcesStayUntouchedWithoutALegacyIndex() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getDataFolder()).thenReturn(pack);
|
||||
|
||||
StructureIndexService.removeLegacyIndex(data);
|
||||
|
||||
verify(data, never()).invalidateStructureResources();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,16 +102,12 @@ public class StructureIndexServiceTest {
|
||||
Files.createDirectories(legacyIndex.toPath().getParent());
|
||||
Files.writeString(legacyIndex.toPath(), "{}", StandardCharsets.UTF_8);
|
||||
IrisData data = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisStructure> structureLoader = mock(ResourceLoader.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
KCache<String, IrisStructure> loadCache = mock(KCache.class);
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
PlatformStructureHooks structureHooks = mock(PlatformStructureHooks.class);
|
||||
when(data.getDataFolder()).thenReturn(pack);
|
||||
when(data.getStructureLoader()).thenReturn(structureLoader);
|
||||
when(structureLoader.getLoadCache()).thenReturn(loadCache);
|
||||
when(structureLoader.getPossibleKeys()).thenReturn(new String[]{"castle", "structure-index"});
|
||||
ModuleResourceFixture.serve(data)
|
||||
.resource(StructureResources.STRUCTURES, "castle", new IrisStructure())
|
||||
.resource(StructureResources.STRUCTURES, "structure-index", new IrisStructure());
|
||||
when(structureHooks.structureKeys()).thenReturn(List.of("minecraft:village", "example:castle"));
|
||||
when(structureHooks.structureSetKeys()).thenReturn(List.of("minecraft:villages"));
|
||||
|
||||
@@ -123,9 +124,8 @@ public class StructureIndexServiceTest {
|
||||
assertEquals(StructureIndexService.indexFile(pack), index);
|
||||
assertTrue(index.isFile());
|
||||
assertFalse(legacyIndex.exists());
|
||||
InOrder order = inOrder(loadCache, structureLoader, structureHooks);
|
||||
order.verify(loadCache).invalidate("structure-index");
|
||||
order.verify(structureLoader).clearList();
|
||||
InOrder order = inOrder(data, structureHooks);
|
||||
order.verify(data).invalidateStructureResources();
|
||||
order.verify(structureHooks).structureKeys();
|
||||
order.verify(structureHooks).structureSetKeys();
|
||||
assertNull(StructureIndexService.writeOnce(data));
|
||||
|
||||
+15
-12
@@ -18,6 +18,8 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.structure.StructureGraphCatalog;
|
||||
import art.arcane.iris.engine.object.value.IrisDirection;
|
||||
@@ -111,7 +113,7 @@ public class IrisStructureLocatorContractTest {
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:city");
|
||||
structure.setVanillaSource("source:city");
|
||||
when(data.load(IrisStructure.class, "test:city_definition", false)).thenReturn(structure);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "test:city_definition", structure);
|
||||
|
||||
IrisStructurePlacement editable = new IrisStructurePlacement();
|
||||
editable.getStructures().add("test:city_definition");
|
||||
@@ -182,7 +184,7 @@ public class IrisStructureLocatorContractTest {
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:city");
|
||||
structure.setVanillaSource("minecraft:ancient_city");
|
||||
when(data.load(IrisStructure.class, "test:city", false)).thenReturn(structure);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "test:city", structure);
|
||||
registerSinglePieceGraph(data, structure, "test:city");
|
||||
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
@@ -211,7 +213,7 @@ public class IrisStructureLocatorContractTest {
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:city");
|
||||
structure.setVanillaSource("minecraft:ancient_city");
|
||||
when(data.load(IrisStructure.class, "test:city", false)).thenReturn(structure);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "test:city", structure);
|
||||
registerSinglePieceGraph(data, structure, "test:city");
|
||||
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
@@ -270,11 +272,11 @@ public class IrisStructureLocatorContractTest {
|
||||
when(targetObject.getW()).thenReturn(100);
|
||||
when(targetObject.getH()).thenReturn(1);
|
||||
when(targetObject.getD()).thenReturn(1);
|
||||
when(data.load(IrisStructure.class, "test:city", false)).thenReturn(structure);
|
||||
when(data.load(IrisJigsawPool.class, "test:start", false)).thenReturn(startPool);
|
||||
when(data.load(IrisJigsawPool.class, "test:target", false)).thenReturn(targetPool);
|
||||
when(data.load(IrisJigsawPiece.class, "test:start-piece", false)).thenReturn(startPiece);
|
||||
when(data.load(IrisJigsawPiece.class, "test:target-piece", false)).thenReturn(targetPiece);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "test:city", structure);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.POOLS, "test:start", startPool);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.POOLS, "test:target", targetPool);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.PIECES, "test:start-piece", startPiece);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.PIECES, "test:target-piece", targetPiece);
|
||||
when(data.load(IrisObject.class, "test:start-object", false)).thenReturn(startObject);
|
||||
when(data.load(IrisObject.class, "test:target-object", false)).thenReturn(targetObject);
|
||||
assertFalse(StructureGraphCatalog.compile(data, structure).isAssemblyViable());
|
||||
@@ -300,7 +302,7 @@ public class IrisStructureLocatorContractTest {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:city");
|
||||
when(data.load(IrisStructure.class, "test:city", false)).thenReturn(structure);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "test:city", structure);
|
||||
registerSinglePieceGraph(data, structure, "test:city");
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement()
|
||||
.setNativeSuppression(NativeStructureSuppression.REPLACE_SOURCE);
|
||||
@@ -321,6 +323,7 @@ public class IrisStructureLocatorContractTest {
|
||||
@Test
|
||||
public void missingNonReplacementStructureFailsInsteadOfBeingSkipped() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
ModuleResourceFixture.serve(data);
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
placement.getStructures().add("test:missing");
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
@@ -800,7 +803,7 @@ public class IrisStructureLocatorContractTest {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:density");
|
||||
when(data.load(IrisStructure.class, "test:density", false)).thenReturn(structure);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "test:density", structure);
|
||||
registerSinglePieceGraph(data, structure, "test:density");
|
||||
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
@@ -839,8 +842,8 @@ public class IrisStructureLocatorContractTest {
|
||||
when(object.getW()).thenReturn(1);
|
||||
when(object.getH()).thenReturn(1);
|
||||
when(object.getD()).thenReturn(1);
|
||||
when(data.load(IrisJigsawPool.class, poolKey, false)).thenReturn(pool);
|
||||
when(data.load(IrisJigsawPiece.class, pieceKey, false)).thenReturn(piece);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.POOLS, poolKey, pool);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.PIECES, pieceKey, piece);
|
||||
when(data.load(IrisObject.class, objectKey, false)).thenReturn(object);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.structure.StructureAssemblyResult;
|
||||
import art.arcane.iris.engine.framework.structure.StructureAssemblyStatus;
|
||||
@@ -1195,15 +1197,15 @@ public class StructureAssemblerTest {
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
|
||||
private Fixture() {
|
||||
when(data.load(IrisJigsawPool.class, "terminal", false)).thenReturn(new IrisJigsawPool());
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.POOLS, "terminal", new IrisJigsawPool());
|
||||
}
|
||||
|
||||
private void pool(String key, IrisJigsawPool pool) {
|
||||
when(data.load(IrisJigsawPool.class, key, false)).thenReturn(pool);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.POOLS, key, pool);
|
||||
}
|
||||
|
||||
private void piece(String key, IrisJigsawPiece piece) {
|
||||
when(data.load(IrisJigsawPiece.class, key, false)).thenReturn(piece);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.PIECES, key, piece);
|
||||
}
|
||||
|
||||
private void object(String key, IrisObject object) {
|
||||
|
||||
+31
-20
@@ -16,8 +16,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.pack;
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
@@ -34,7 +35,8 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class StructureGraphPackValidatorTest {
|
||||
/** The structure module's graph check, run on real pack folders the way Iris opens a pack to validate it. */
|
||||
public class StructureGraphValidationTest {
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@@ -49,7 +51,7 @@ public class StructureGraphPackValidatorTest {
|
||||
+ "\"direction\":\"NORTH_NEGATIVE_Z\",\"pool\":\"castle/start\",\"name\":\"path\",\"targetName\":\"path\"}]}");
|
||||
writeObjectHeader(pack.resolve("objects/castle/start.iob"), 1, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertTrue(validation.errors().stream().anyMatch(message -> message.contains("non-positive weight 0")));
|
||||
assertTrue(validation.errors().stream().anyMatch(message -> message.contains("outside object bounds")));
|
||||
@@ -67,7 +69,7 @@ public class StructureGraphPackValidatorTest {
|
||||
"{\"object\":\"castle/piece\",\"connectors\":[]}");
|
||||
writeObjectHeader(pack.resolve("objects/castle/piece.iob"), 1, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertTrue(validation.errors().stream().anyMatch(message -> message.contains("fallback cycle")));
|
||||
}
|
||||
@@ -89,7 +91,7 @@ public class StructureGraphPackValidatorTest {
|
||||
writeObjectHeader(pack.resolve("objects/castle/start.iob"), 1, 1, 1);
|
||||
writeObjectHeader(pack.resolve("objects/castle/target.iob"), 1, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertTrue(validation.errors().stream().anyMatch(
|
||||
message -> message.contains("does not produce a complete deterministic assembly")));
|
||||
@@ -116,7 +118,7 @@ public class StructureGraphPackValidatorTest {
|
||||
writeObjectHeader(pack.resolve("objects/castle/start.iob"), 1, 1, 1);
|
||||
writeObjectHeader(pack.resolve("objects/castle/target.iob"), 1, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
}
|
||||
@@ -138,8 +140,8 @@ public class StructureGraphPackValidatorTest {
|
||||
writeObjectHeader(pack.resolve("objects/library/start.iob"), 1, 1, 1);
|
||||
writeObjectHeader(pack.resolve("objects/library/target.iob"), 1, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation =
|
||||
StructureGraphPackValidator.validate(pack, Set.of());
|
||||
StructureGraphValidation.Validation validation =
|
||||
validate(pack, Set.of());
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertTrue(validation.warnings().toString(), validation.warnings().isEmpty());
|
||||
@@ -156,7 +158,7 @@ public class StructureGraphPackValidatorTest {
|
||||
Path object = pack.resolve("objects/castle/start.iob");
|
||||
writeTruncatedObjectHeader(object, 1, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertEquals(List.of("Malformed Iris object resource " + object
|
||||
+ ": EOFException"), validation.errors());
|
||||
@@ -172,8 +174,8 @@ public class StructureGraphPackValidatorTest {
|
||||
"{\"object\":\"library/start\",\"connectors\":[]}");
|
||||
writeTruncatedObjectHeader(pack.resolve("objects/library/start.iob"), 1, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation =
|
||||
StructureGraphPackValidator.validate(pack, Set.of());
|
||||
StructureGraphValidation.Validation validation =
|
||||
validate(pack, Set.of());
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
}
|
||||
@@ -188,7 +190,7 @@ public class StructureGraphPackValidatorTest {
|
||||
"{\"object\":\"castle/start\",\"connectors\":[]}");
|
||||
writeSignedObject(pack.resolve("objects/castle/start.iob"), 18, 31, 41, -9, -15, -20);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertFalse(validation.errors().toString(),
|
||||
validation.errors().stream().anyMatch(message -> message.contains("missing object")));
|
||||
@@ -205,8 +207,8 @@ public class StructureGraphPackValidatorTest {
|
||||
"{\"object\":\"castle/start\",\"connectors\":[]}");
|
||||
writeObjectHeader(pack.resolve("objects/castle/start.iob"), 3, 9, 3);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
List<StructureGraphPackValidator.SampledVerticalEnvelope> envelopes =
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
List<StructureGraphValidation.SampledVerticalEnvelope> envelopes =
|
||||
validation.sampledVerticalEnvelopes().get("castle");
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
@@ -215,7 +217,7 @@ public class StructureGraphPackValidatorTest {
|
||||
&& envelope.minimumYOffset() == -4
|
||||
&& envelope.maximumYOffset() == 4));
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> envelopes.add(new StructureGraphPackValidator.SampledVerticalEnvelope(1L, 1, 0, 0)));
|
||||
() -> envelopes.add(new StructureGraphValidation.SampledVerticalEnvelope(1L, 1, 0, 0)));
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> validation.sampledVerticalEnvelopes().put("other", List.of()));
|
||||
}
|
||||
@@ -233,7 +235,7 @@ public class StructureGraphPackValidatorTest {
|
||||
+ "\"name\":\"source\",\"targetName\":\"door\"}]}" );
|
||||
writeObjectHeader(pack.resolve("objects/castle/start.iob"), 1, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
}
|
||||
@@ -245,7 +247,7 @@ public class StructureGraphPackValidatorTest {
|
||||
write(pack, "jigsaw-pools/castle/start.json",
|
||||
"{\"pieces\":[{\"empty\":true,\"weight\":1}]}");
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertFalse(validation.replacementOutputStructures().contains("castle"));
|
||||
@@ -262,7 +264,7 @@ public class StructureGraphPackValidatorTest {
|
||||
"{\"object\":\"castle/start\",\"connectors\":[]}");
|
||||
writeObjectHeader(pack.resolve("objects/castle/start.iob"), 1, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertFalse(validation.replacementOutputStructures().contains("castle"));
|
||||
@@ -279,7 +281,7 @@ public class StructureGraphPackValidatorTest {
|
||||
"{\"object\":\"castle/start\",\"connectors\":[]}");
|
||||
writeObjectHeader(pack.resolve("objects/castle/start.iob"), 34, 1, 1);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertFalse(validation.replacementOutputStructures().contains("castle"));
|
||||
@@ -310,13 +312,22 @@ public class StructureGraphPackValidatorTest {
|
||||
writeObjectHeader(pack.resolve("objects/castle/start.iob"), 3, 3, 3);
|
||||
writeObjectHeader(pack.resolve("objects/castle/recursive.iob"), 3, 3, 3);
|
||||
|
||||
StructureGraphPackValidator.Validation validation = StructureGraphPackValidator.validate(pack);
|
||||
StructureGraphValidation.Validation validation = validate(pack, null);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().stream().anyMatch(
|
||||
message -> message.contains("does not produce a complete deterministic assembly")
|
||||
&& message.contains("seed 0")));
|
||||
}
|
||||
|
||||
private static StructureGraphValidation.Validation validate(Path pack, Set<String> activeStructureKeys) {
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try {
|
||||
return StructureGraphValidation.validate(data, activeStructureKeys);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void write(Path root, String relativePath, String content) throws Exception {
|
||||
Path file = root.resolve(relativePath);
|
||||
Files.createDirectories(file.getParent());
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
package art.arcane.iris.engine.framework.structure;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.IrisModuleHost;
|
||||
import art.arcane.iris.core.project.ModuleResourceSchemas;
|
||||
import art.arcane.iris.core.project.SchemaTestPlatform;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPool;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.volmit.host.ResourceKindRegistration;
|
||||
import com.volmit.host.ValidatorRegistration;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* The pilot: structures, jigsaw pools and pieces are resource kinds of module {@code iris:structure}, read from the
|
||||
* folders and files packs have always had, and Iris has no loaders of its own for them any more.
|
||||
*/
|
||||
public class StructureResourcesTest {
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void theStructureModuleOwnsTheKindsAndTheirValidator() throws Exception {
|
||||
IrisData data = IrisData.openValidation(castlePack("owned").toFile());
|
||||
try {
|
||||
var catalog = data.getModules().pack().catalog();
|
||||
|
||||
assertEquals(List.of("iris:structure/piece", "iris:structure/pool", "iris:structure/structure"),
|
||||
catalog.resourceKinds().stream().map(registration -> registration.kind().id().toString()).toList());
|
||||
assertEquals(List.of("jigsaw-pieces", "jigsaw-pools", "structures"),
|
||||
catalog.resourceKinds().stream().map(ResourceKindRegistration::kind).map(kind -> kind.folder()).toList());
|
||||
assertTrue(catalog.validators().stream().map(ValidatorRegistration::validator).anyMatch(StructureValidator.class::isInstance));
|
||||
assertFalse(data.getLoaders().containsKey(IrisStructure.class));
|
||||
assertFalse(data.getLoaders().containsKey(IrisJigsawPool.class));
|
||||
assertFalse(data.getLoaders().containsKey(IrisJigsawPiece.class));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structuresPoolsAndPiecesAreReadThroughPackResources() throws Exception {
|
||||
Path pack = castlePack("castles");
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try {
|
||||
IrisStructure castle = StructureResources.structure(data, "castle");
|
||||
|
||||
assertEquals("castle/start", castle.getStartPool());
|
||||
assertEquals(5, castle.getMaxDepth());
|
||||
assertEquals("castle", castle.getLoadKey());
|
||||
assertEquals(pack.resolve("structures/castle.json").toFile(), castle.getLoadFile());
|
||||
assertSame(data, castle.getLoader());
|
||||
assertSame(castle, data.getPackResources().find(StructureResources.STRUCTURES.key(new ResourceId("castles", "castle"))).orElseThrow());
|
||||
assertEquals("castle/start", StructureResources.pool(data, "castle/start").getPieces().getFirst().getPiece());
|
||||
assertEquals("castle/start", StructureResources.piece(data, "castle/start").getObject());
|
||||
assertEquals(List.of("castle"), StructureResources.structureKeys(data));
|
||||
assertEquals(List.of("castle/start"), StructureResources.pieceKeys(data));
|
||||
assertNull(StructureResources.structure(data, "missing"));
|
||||
assertNull(StructureResources.structure(data, " "));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBrokenStructureIsAbsentToLookupsButAnErrorToPackResources() throws Exception {
|
||||
Path pack = castlePack("broken");
|
||||
write(pack, "structures/ruin.json", "{\"maxDepth\":");
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try {
|
||||
assertNull(StructureResources.structure(data, "ruin"));
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> data.getPackResources().find(StructureResources.STRUCTURES.key(new ResourceId("broken", "ruin"))));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rewrittenFilesAreReadAgainAfterInvalidationDumpAndHotload() throws Exception {
|
||||
Path pack = castlePack("reloaded");
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try {
|
||||
assertEquals(5, StructureResources.structure(data, "castle").getMaxDepth());
|
||||
write(pack, "structures/castle.json", "{\"startPool\":\"castle/start\",\"maxDepth\":9}");
|
||||
write(pack, "structures/tower.json", "{\"startPool\":\"castle/start\"}");
|
||||
assertEquals("a snapshot keeps what it read", 5, StructureResources.structure(data, "castle").getMaxDepth());
|
||||
|
||||
data.invalidateStructureResources();
|
||||
assertEquals(9, StructureResources.structure(data, "castle").getMaxDepth());
|
||||
assertEquals(List.of("castle", "tower"), StructureResources.structureKeys(data));
|
||||
|
||||
write(pack, "structures/castle.json", "{\"startPool\":\"castle/start\",\"maxDepth\":3}");
|
||||
data.dump();
|
||||
assertEquals(3, StructureResources.structure(data, "castle").getMaxDepth());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
|
||||
IrisData runtime = IrisData.openRuntime(pack.toFile());
|
||||
try {
|
||||
assertEquals(3, StructureResources.structure(runtime, "castle").getMaxDepth());
|
||||
write(pack, "structures/castle.json", "{\"startPool\":\"castle/start\",\"maxDepth\":2}");
|
||||
runtime.hotloaded();
|
||||
assertEquals(2, StructureResources.structure(runtime, "castle").getMaxDepth());
|
||||
} finally {
|
||||
runtime.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioDescribesStructuresAsIrisDoesAndCompletesTheirPools() throws Exception {
|
||||
Path pack = castlePack("studio");
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try (SchemaTestPlatform ignored = SchemaTestPlatform.bind(temporaryFolder.getRoot())) {
|
||||
List<JSONObject> entries = ModuleResourceSchemas.entries(data, true);
|
||||
|
||||
assertEquals(List.of("./.iris/schema/jigsaw-pieces-schema.json", "./.iris/schema/jigsaw-pools-schema.json",
|
||||
"./.iris/schema/structures-schema.json"), entries.stream().map(entry -> entry.getString("url")).toList());
|
||||
JSONObject structures = new JSONObject(Files.readString(pack.resolve(".iris/schema/structures-schema.json")));
|
||||
JSONObject startPool = structures.getJSONObject("properties").getJSONObject("startPool");
|
||||
assertEquals("#/definitions/erzjigsaw-pools", startPool.getString("$ref"));
|
||||
assertEquals("[\"castle/start\"]",
|
||||
structures.getJSONObject("definitions").getJSONObject("erzjigsaw-pools").getJSONArray("enum").toString());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void irisReservesTheFoldersItStillReadsItself() {
|
||||
var reserved = IrisModuleHost.get().reservedFolders();
|
||||
|
||||
assertTrue(reserved.containsAll(List.of("biomes", "regions", "dimensions", "objects", "snippet", "modules")));
|
||||
assertFalse(reserved.contains("structures"));
|
||||
assertFalse(reserved.contains("jigsaw-pools"));
|
||||
assertFalse(reserved.contains("jigsaw-pieces"));
|
||||
}
|
||||
|
||||
private Path castlePack(String name) throws Exception {
|
||||
File pack = temporaryFolder.newFolder(name);
|
||||
write(pack.toPath(), "dimensions/main.json", "{\"regions\":[\"region\"]}");
|
||||
write(pack.toPath(), "regions/region.json", "{\"landBiomes\":[\"biome\"]}");
|
||||
write(pack.toPath(), "biomes/biome.json", "{\"name\":\"Biome\"}");
|
||||
write(pack.toPath(), "structures/castle.json", "{\"startPool\":\"castle/start\",\"maxDepth\":5}");
|
||||
write(pack.toPath(), "jigsaw-pools/castle/start.json", "{\"pieces\":[{\"piece\":\"castle/start\"}]}");
|
||||
write(pack.toPath(), "jigsaw-pieces/castle/start.json", "{\"object\":\"castle/start\",\"connectors\":[]}");
|
||||
return pack.toPath();
|
||||
}
|
||||
|
||||
private static void write(Path root, String relative, String content) throws Exception {
|
||||
Path path = root.resolve(relative);
|
||||
Files.createDirectories(path.getParent());
|
||||
Files.writeString(path, content, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
+10
-12
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.engine.platform.studio.generators;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.runtime.jigsaw.JigsawPlanarArchetype;
|
||||
@@ -62,9 +64,8 @@ public class JigsawStudioGeneratorTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void connectorBlocksAreHiddenByDefaultAndCanBeShownPerWorkcell() {
|
||||
IrisData source = mock(IrisData.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisObject> objectLoader = mock(ResourceLoader.class);
|
||||
when(source.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(source);
|
||||
when(source.getObjectLoader()).thenReturn(objectLoader);
|
||||
IrisJigsawConnector connector = new IrisJigsawConnector()
|
||||
.setPosition(new IrisPosition(1, 1, 1))
|
||||
@@ -82,7 +83,7 @@ public class JigsawStudioGeneratorTest {
|
||||
PlatformBlockState stone = mock(PlatformBlockState.class);
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
object.setUnsigned(1, 1, 1, stone);
|
||||
when(pieceLoader.load("test/room", false)).thenReturn(piece);
|
||||
resources.resource(StructureResources.PIECES, "test/room", piece);
|
||||
when(objectLoader.load("test/room", false)).thenReturn(object);
|
||||
JigsawStudioVariant variant = new JigsawStudioVariant(
|
||||
"test/room",
|
||||
@@ -332,9 +333,8 @@ public class JigsawStudioGeneratorTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void rendersSourceVariantInCanonicalOrientationAndRotatesFinalState() {
|
||||
IrisData source = mock(IrisData.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisObject> objectLoader = mock(ResourceLoader.class);
|
||||
when(source.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(source);
|
||||
when(source.getObjectLoader()).thenReturn(objectLoader);
|
||||
IrisJigsawConnector connector = new IrisJigsawConnector()
|
||||
.setPosition(new IrisPosition(2, 1, 1))
|
||||
@@ -357,7 +357,7 @@ public class JigsawStudioGeneratorTest {
|
||||
TileData sourceTile = new TileData("minecraft:chest", tileProperties);
|
||||
object.setUnsigned(0, 0, 0, sourceBlock);
|
||||
object.setUnsignedTile(0, 0, 0, sourceTile);
|
||||
when(pieceLoader.load("village/east", false)).thenReturn(piece);
|
||||
resources.resource(StructureResources.PIECES, "village/east", piece);
|
||||
when(objectLoader.load("village/east", false)).thenReturn(object);
|
||||
JigsawStudioVariant variant = planarVariant("village/east", JigsawPlanarTopology.EAST_END);
|
||||
GeneratorFixture fixture = fixture(
|
||||
@@ -385,9 +385,8 @@ public class JigsawStudioGeneratorTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void invalidRotatedFinalStateFailsRenderPrecisely() {
|
||||
IrisData source = mock(IrisData.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisObject> objectLoader = mock(ResourceLoader.class);
|
||||
when(source.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(source);
|
||||
when(source.getObjectLoader()).thenReturn(objectLoader);
|
||||
IrisJigsawConnector connector = new IrisJigsawConnector()
|
||||
.setPosition(new IrisPosition(2, 1, 1))
|
||||
@@ -402,7 +401,7 @@ public class JigsawStudioGeneratorTest {
|
||||
.setObject("village/east")
|
||||
.setConnectors(new KList<>());
|
||||
piece.getConnectors().add(connector);
|
||||
when(pieceLoader.load("village/east", false)).thenReturn(piece);
|
||||
resources.resource(StructureResources.PIECES, "village/east", piece);
|
||||
when(objectLoader.load("village/east", false)).thenReturn(new IrisObject(3, 3, 3));
|
||||
JigsawStudioVariant variant = planarVariant("village/east", JigsawPlanarTopology.EAST_END);
|
||||
GeneratorFixture fixture = fixture(
|
||||
@@ -422,14 +421,13 @@ public class JigsawStudioGeneratorTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void renderCacheIncludesLoadGenerationAndSupportsExplicitInvalidation() {
|
||||
IrisData source = mock(IrisData.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisObject> objectLoader = mock(ResourceLoader.class);
|
||||
when(source.getJigsawPieceLoader()).thenReturn(pieceLoader);
|
||||
ModuleResourceFixture resources = ModuleResourceFixture.serve(source);
|
||||
when(source.getObjectLoader()).thenReturn(objectLoader);
|
||||
IrisJigsawPiece piece = new IrisJigsawPiece()
|
||||
.setObject("stronghold/hall")
|
||||
.setConnectors(new KList<>());
|
||||
when(pieceLoader.load("stronghold/hall", false)).thenReturn(piece);
|
||||
resources.resource(StructureResources.PIECES, "stronghold/hall", piece);
|
||||
when(objectLoader.load("stronghold/hall", false)).thenReturn(new IrisObject(3, 3, 3));
|
||||
JigsawStudioVariant variant = new JigsawStudioVariant(
|
||||
"stronghold/hall",
|
||||
|
||||
@@ -124,7 +124,13 @@ public class PackTypeBukkitPurityGateTest {
|
||||
"art.arcane.iris.engine.object.prefab.IrisObject",
|
||||
"art.arcane.iris.engine.object.image.IrisImage",
|
||||
"art.arcane.iris.engine.object.image.IrisImageMap",
|
||||
"art.arcane.iris.engine.object.prefab.matter.IrisMatterObject",
|
||||
"art.arcane.iris.engine.object.prefab.matter.IrisMatterObject");
|
||||
|
||||
/**
|
||||
* Iris's classes that built-in modules' resource kinds read from a pack with the same Gson, so they are roots
|
||||
* as much as the loaders' (see {@code StructureResources}).
|
||||
*/
|
||||
private static final List<String> MODULE_RESOURCE_ROOTS = List.of(
|
||||
"art.arcane.iris.engine.object.structure.IrisStructure",
|
||||
"art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPool",
|
||||
"art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece");
|
||||
@@ -488,6 +494,7 @@ public class PackTypeBukkitPurityGateTest {
|
||||
/** The Gson roots, the extra pack-reachable types, and every {@code @Snippet} class. */
|
||||
private static List<String> gateTypes() throws Exception {
|
||||
Set<String> types = new LinkedHashSet<>(GSON_REGISTERED_ROOTS);
|
||||
types.addAll(MODULE_RESOURCE_ROOTS);
|
||||
types.addAll(ADDITIONAL_PACK_TYPES);
|
||||
types.addAll(snippetTypes());
|
||||
return new ArrayList<>(types);
|
||||
|
||||
+6
-4
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.util.common.director.specialhandlers;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
@@ -102,8 +104,8 @@ public class StructureHandlerTest {
|
||||
custom.setLoadKey("iris:custom");
|
||||
IrisStructure collision = new IrisStructure();
|
||||
collision.setLoadKey("pack:collision");
|
||||
when(data.load(IrisStructure.class, "iris:custom_definition", false)).thenReturn(custom);
|
||||
when(data.load(IrisStructure.class, "iris:collision_definition", false)).thenReturn(collision);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:custom_definition", custom);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:collision_definition", collision);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
@@ -173,8 +175,8 @@ public class StructureHandlerTest {
|
||||
placements.add(editablePlacement("iris:replacement_definition"));
|
||||
placements.add(nativePlacement("minecraft:explicit", StructureDistribution.RANDOM_SPREAD, 1.0));
|
||||
|
||||
when(data.load(IrisStructure.class, "iris:editable_definition", false)).thenReturn(editable);
|
||||
when(data.load(IrisStructure.class, "iris:replacement_definition", false)).thenReturn(replacement);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:editable_definition", editable);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:replacement_definition", replacement);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
|
||||
Reference in new issue
Block a user