mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Show pack modules' settings in studio and reload them when their jars change
- SchemaBuilder renders the settings the pack's modules add: each feature at a dimension, region, biome or object placement becomes a property under its id and, for built-ins, its alias, with a constraint that an object holds only one of the two. Each settings class is one definition; options carry their kind, bounds, defaults and descriptions, and references complete from the same lists Iris's own fields use. - The code workspace writes a schema for each module snippet type under snippet/<name>/. - A pack whose modules fail to load gets no workspace; the error is logged instead of writing schemas without the modules. - PackModuleSet forgets loaded or failed modules once the jars in <pack>/modules change, and the workspace then reloads the pack data, so studio picks up rebuilt module jars. The studio hotload watcher now also reacts to .jar files. - Placement tests name Iris's built-in states by their own keys, since those resolve once per JVM with whichever platform a test bound first.
This commit is contained in:
1 parent
529d70b14a
commit
2aab5ae9a3
9 files changed
+496
-41
No files matched your search
@@ -20,6 +20,7 @@ import org.mockito.Answers;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -89,6 +90,23 @@ public class IrisCodeWorkspaceTest {
|
||||
stamp.toMillis(), Files.getLastModifiedTime(file.toPath()).toMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackWhoseModulesFailToLoadGetsNoWorkspaceUntilItsJarsAreFixed() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("broken-modules");
|
||||
Path brokenJar = Files.createDirectories(pack.toPath().resolve("modules")).resolve("broken.jar");
|
||||
Files.writeString(brokenJar, "not a jar");
|
||||
IrisCodeWorkspace workspace = new IrisCodeWorkspace(new IrisProject(pack));
|
||||
|
||||
assertFalse(workspace.updateWorkspace());
|
||||
data = IrisData.get(pack);
|
||||
assertFalse(workspace.getCodeWorkspaceFile().exists());
|
||||
|
||||
Files.delete(brokenJar);
|
||||
|
||||
assertTrue(workspace.updateWorkspace());
|
||||
assertTrue(workspace.getCodeWorkspaceFile().isFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workspaceSchemaEntriesAreEmittedInStableSortedOrder() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("sorted");
|
||||
|
||||
@@ -59,11 +59,25 @@ import art.arcane.volmlib.util.collection.KList;
|
||||
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 com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.host.schema.PackSchema;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -240,6 +254,23 @@ public class SchemaBuilderParityTest {
|
||||
assertFalse(properties.has("surfaceOpeningClearance"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectPlacementSchemaRendersModuleSettingsUnderTheirIdAndAlias() throws IOException {
|
||||
JSONObject schema = new SchemaBuilder(IrisObjectPlacement.class, structureSchemaData(glowModuleSchema())).construct();
|
||||
JSONObject properties = rootProperties(schema);
|
||||
String definition = definitionKey(properties.getJSONObject("example:glow"));
|
||||
JSONObject level = schema.getJSONObject("definitions").getJSONObject(definition)
|
||||
.getJSONObject("properties").getJSONObject("level");
|
||||
|
||||
assertEquals(definition, definitionKey(properties.getJSONObject("glow")));
|
||||
assertEquals("integer", level.getString("type"));
|
||||
assertEquals(1, level.getInt("minimum"));
|
||||
assertEquals(15, level.getInt("maximum"));
|
||||
assertEquals(7, level.getInt("default"));
|
||||
assertEquals("How bright the glow is", level.getString("description"));
|
||||
assertTrue(schema.toString().contains("{\"not\":{\"required\":[\"glow\",\"example:glow\"]}}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dimensionSchemaExposesSurfaceSupportDefaults() {
|
||||
JSONObject properties = rootProperties(
|
||||
@@ -285,7 +316,17 @@ public class SchemaBuilderParityTest {
|
||||
}
|
||||
|
||||
private static IrisData structureSchemaData() {
|
||||
return structureSchemaData(new PackSchema(List.of(), List.of()));
|
||||
}
|
||||
|
||||
/** {@code modules} is what the pack's modules add to its JSON. */
|
||||
private static IrisData structureSchemaData(PackSchema modules) {
|
||||
IrisData data = mock(IrisData.class);
|
||||
LoadedPack pack = mock(LoadedPack.class);
|
||||
PackModuleSet moduleSet = mock(PackModuleSet.class);
|
||||
when(pack.schema()).thenReturn(modules);
|
||||
when(moduleSet.pack()).thenReturn(pack);
|
||||
when(data.getModules()).thenReturn(moduleSet);
|
||||
ResourceLoader<IrisStructure> structureLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisJigsawPiece> pieceLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisExpression> expressionLoader = mock(ResourceLoader.class);
|
||||
@@ -592,4 +633,33 @@ public class SchemaBuilderParityTest {
|
||||
public void reportError(Throwable error) {
|
||||
}
|
||||
}
|
||||
|
||||
private static PackSchema glowModuleSchema() throws IOException {
|
||||
Path root = Files.createTempDirectory("glow-pack");
|
||||
try (LoadedPack pack = LoadedPack.load(Files.createDirectory(root.resolve("pack")),
|
||||
ModuleHost.of(List.of(new GlowModule())).copyingJarsTo(Files.createDirectory(root.resolve("copies"))))) {
|
||||
return pack.schema();
|
||||
}
|
||||
}
|
||||
|
||||
@Feature(id = "example:glow", name = "Glow", alias = "glow", targets = Target.OBJECT_PLACEMENT)
|
||||
public static final class GlowSettings implements IrisFeature {
|
||||
@com.volmit.config.Desc("How bright the glow is")
|
||||
@com.volmit.config.MinNumber(1)
|
||||
@com.volmit.config.MaxNumber(15)
|
||||
private int level = 7;
|
||||
}
|
||||
|
||||
public static final class GlowModule implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("example:glow", "Glow", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
graph.define(Stage.placement("example:glow/light")).when(GlowSettings.class).run((context, glow) -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-5
@@ -19,6 +19,7 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPlacementPack;
|
||||
import art.arcane.iris.core.modules.ModuleObjectPlacement;
|
||||
import art.arcane.iris.core.modules.ObjectPlacementResult;
|
||||
import art.arcane.iris.core.modules.PlatformBlockStates;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeStructureVolume;
|
||||
@@ -65,8 +66,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisObjectPlacementRegressionTest {
|
||||
private static final int ANCHOR_Y = 80;
|
||||
private static final String SNOW_LAYER = "minecraft:snow[layers=1]";
|
||||
private static final String CAVE_AIR = "minecraft:cave_air";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
@@ -143,7 +142,7 @@ public class IrisObjectPlacementRegressionTest {
|
||||
int resultY = lineObject(3).place(0, ANCHOR_Y, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
// The object's own blocks replace the bored air below, so only the extension stays air.
|
||||
List<BlockWrite> airWrites = placer.writesOf(CAVE_AIR);
|
||||
List<BlockWrite> airWrites = placer.writesOf(keyOf(IrisObject.States.AIR));
|
||||
assertEquals(3, airWrites.size());
|
||||
assertTrue(airWrites.stream().allMatch(write -> write.y() == resultY + 1));
|
||||
assertTrue(airWrites.stream().allMatch(write -> write.x() == 0));
|
||||
@@ -196,7 +195,7 @@ public class IrisObjectPlacementRegressionTest {
|
||||
|
||||
object.place(0, ANCHOR_Y, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
List<BlockWrite> snowWrites = placer.writesOf(SNOW_LAYER);
|
||||
List<BlockWrite> snowWrites = placer.writesOf(keyOf(IrisObject.States.SNOW_LAYERS[0]));
|
||||
assertEquals(1, snowWrites.size());
|
||||
assertEquals(ANCHOR_Y, snowWrites.get(0).y());
|
||||
}
|
||||
@@ -502,7 +501,7 @@ public class IrisObjectPlacementRegressionTest {
|
||||
List<BlockWrite> center = placer.writes().stream().filter(write -> write.x() == 0 && write.z() == 0).toList();
|
||||
assertEquals(List.of(82, 81, 83), center.stream().map(BlockWrite::y).toList());
|
||||
assertEquals(solid.key(), center.get(0).state().key());
|
||||
assertEquals(SNOW_LAYER, center.get(2).state().key());
|
||||
assertEquals(keyOf(IrisObject.States.SNOW_LAYERS[0]), center.get(2).state().key());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -574,6 +573,14 @@ public class IrisObjectPlacementRegressionTest {
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* The key a placement writes a built-in state under. Iris resolves its built-in states once per JVM, with
|
||||
* whichever platform a test bound first, so tests name them by their own keys.
|
||||
*/
|
||||
private static String keyOf(PlatformBlockState builtIn) {
|
||||
return PlatformBlockStates.namespaced(builtIn.key());
|
||||
}
|
||||
|
||||
private static PlatformBlockState state(String key, boolean solid) {
|
||||
PlatformBlockState state = mock(PlatformBlockState.class);
|
||||
when(state.key()).thenReturn(key);
|
||||
|
||||
Reference in new issue
Block a user