mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Read module settings per column with every level as its own entry
Chunk stages now run where any column of the chunk configures their settings, and every level (dimension, region, surface biome, placement) is its own entry: the most-specific-wins merge is gone. Settings with one option accept a bare JSON value, Iris's pack object classes in built-in settings are read with the pack's own Gson, and studio renders both: the shorthand as an alternative form and Iris classes with Iris's own definitions.
This commit is contained in:
1 parent
5f30e27485
commit
efa6cb4b4a
18 files changed
+269
-114
No files matched your search
@@ -43,12 +43,14 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -78,7 +80,8 @@ public class ModuleChunkGenerationTest {
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
graph.define(Stage.chunk("iris:pillar/raise")).when(PillarSettings.class).run((context, pillar) -> {
|
||||
graph.define(Stage.chunk("iris:pillar/raise")).when(PillarSettings.class).run((context, pillars) -> {
|
||||
PillarSettings pillar = pillars.getLast().value();
|
||||
com.volmit.hunk.Hunk<BlockState> chunk = context.hunk(BlockState.class);
|
||||
chunk.set(0, 1, 0, chunk.get(0, 0, 0));
|
||||
chunk.set(pillar.x, 2, 0, pillar.block);
|
||||
@@ -106,6 +109,37 @@ public class ModuleChunkGenerationTest {
|
||||
pack.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyLevelThatConfiguresTheSettingsIsItsOwnEntryInLevelOrder() {
|
||||
List<List<String>> seen = new ArrayList<>();
|
||||
ChunkModuleSettings settings = new ChunkModuleSettings(engine, new PackResourceIds(folder.getRoot()));
|
||||
IrisRegion region = configured(new IrisRegion(), pillar(1));
|
||||
region.setLoadKey("hot");
|
||||
IrisBiome biome = configured(new IrisBiome(), pillar(2));
|
||||
biome.setLoadKey("desert/dunes");
|
||||
when(engine.getRegion(5, 6)).thenReturn(region);
|
||||
when(engine.getSurfaceBiome(5, 6)).thenReturn(biome);
|
||||
when(engine.getDimension()).thenReturn(configured(new IrisDimension(), pillar(0)));
|
||||
|
||||
settings.at(PillarSettings.class, 5, 6).forEach(entry -> seen.add(List.of(entry.level().name(), entry.source().toString())));
|
||||
|
||||
String pack = folder.getRoot().getName().toLowerCase(java.util.Locale.ROOT).replaceAll("[^a-z0-9_.-]", "_");
|
||||
assertEquals(List.of(List.of("DIMENSION", pack + ":dimension/null"), List.of("REGION", pack + ":region/hot"),
|
||||
List.of("BIOME", pack + ":biome/desert/dunes")), seen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stagesRunWhereAnyColumnOfTheChunkConfiguresThem() {
|
||||
when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion());
|
||||
IrisBiome plain = new IrisBiome();
|
||||
IrisBiome pillared = configured(new IrisBiome(), pillar(3));
|
||||
when(engine.getSurfaceBiome(anyInt(), anyInt())).thenAnswer(call -> call.getArgument(0, Integer.class) == 15 ? pillared : plain);
|
||||
|
||||
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, null, ModuleChunkGenerationTest::platformState);
|
||||
|
||||
assertEquals("minecraft:oak_log[axis=y]", blocks.get(3, 2, 0).key());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stagesRunWhereTheChunksBiomeConfiguresThemAndWriteIrisBlocks() {
|
||||
blocks.set(0, 0, 0, platformState("minecraft:dirt"));
|
||||
@@ -139,7 +173,9 @@ public class ModuleChunkGenerationTest {
|
||||
}
|
||||
|
||||
private void generate(IrisBiome biome) {
|
||||
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, null, new IrisRegion(), biome, ModuleChunkGenerationTest::platformState);
|
||||
when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion());
|
||||
when(engine.getSurfaceBiome(anyInt(), anyInt())).thenReturn(biome);
|
||||
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, null, ModuleChunkGenerationTest::platformState);
|
||||
}
|
||||
|
||||
private static PillarSettings pillar(int x) {
|
||||
|
||||
@@ -18,7 +18,14 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -69,6 +76,16 @@ public class ModuleSettingsDecoderTest {
|
||||
private int size = 1;
|
||||
}
|
||||
|
||||
@Feature(id = "iris:moss/cover", name = "Cover", alias = "cover", targets = Target.BIOME)
|
||||
public static final class CoverSettings implements IrisFeature {
|
||||
private double amount = 1;
|
||||
}
|
||||
|
||||
@Feature(id = "iris:moss/marks", name = "Marks", alias = "marks", targets = Target.BIOME)
|
||||
public static final class MarksSettings implements IrisFeature {
|
||||
private List<IrisPosition> marks = List.of();
|
||||
}
|
||||
|
||||
public static final class MossModule implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
@@ -80,13 +97,20 @@ public class ModuleSettingsDecoderTest {
|
||||
graph.define(Stage.chunk("iris:moss/spread")).when(MossSettings.class).run((context, moss) -> {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerSettings(CoverSettings.class);
|
||||
registry.registerSettings(MarksSettings.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void loadPack() throws IOException {
|
||||
packFolder = folder.newFolder("pack").toPath();
|
||||
pack = LoadedPack.load(packFolder, ModuleHost.of(List.of(new MossModule())).copyingJarsTo(folder.newFolder("copies").toPath()));
|
||||
decoder = new ModuleSettingsDecoder(pack.catalog(), packFolder);
|
||||
pack = LoadedPack.load(packFolder, ModuleHost.of(List.of(new MossModule()))
|
||||
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE).copyingJarsTo(folder.newFolder("copies").toPath()));
|
||||
decoder = new ModuleSettingsDecoder(pack.catalog(), packFolder, Gson::new);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -148,17 +172,42 @@ public class ModuleSettingsDecoderTest {
|
||||
|
||||
@Test
|
||||
public void listsTheKeysModulesReadPerTarget() {
|
||||
assertEquals(Set.of("iris:moss", "moss"), decoder.keys(Target.BIOME));
|
||||
assertEquals(Set.of("iris:moss", "moss", "iris:moss/cover", "cover", "iris:moss/marks", "marks"), decoder.keys(Target.BIOME));
|
||||
assertEquals(Set.of(), decoder.keys(Target.DIMENSION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moreSpecificSettingsReplaceLessSpecificOnesOfTheSameType() {
|
||||
ModuleSettings region = decoder.decode(Target.REGION, new JSONObject("{\"moss\": {\"radius\": 2}}"), "region hot");
|
||||
ModuleSettings biome = decoder.decode(Target.BIOME, new JSONObject("{\"moss\": {\"radius\": 5}}"), "biome desert/dunes");
|
||||
public void settingsWithOneOptionReadABareValueAsThatOption() {
|
||||
assertEquals(0.5, decoder.decode(Target.BIOME, new JSONObject("{\"cover\": 0.5}"), "biome desert/dunes")
|
||||
.find(CoverSettings.class).orElseThrow().amount, 0);
|
||||
assertEquals(0.25, decoder.decode(Target.BIOME, new JSONObject("{\"cover\": {\"amount\": 0.25}}"), "biome desert/dunes")
|
||||
.find(CoverSettings.class).orElseThrow().amount, 0);
|
||||
|
||||
assertEquals(5, region.overriddenBy(biome).find(MossSettings.class).orElseThrow().radius);
|
||||
assertEquals(2, region.overriddenBy(ModuleSettings.NONE).find(MossSettings.class).orElseThrow().radius);
|
||||
assertEquals(5, ModuleSettings.NONE.overriddenBy(biome).find(MossSettings.class).orElseThrow().radius);
|
||||
IllegalArgumentException several = assertThrows(IllegalArgumentException.class, () -> moss("{\"moss\": 4}"));
|
||||
assertEquals("Cannot read settings iris:moss under \"moss\" in biome desert/dunes: write an object; only settings with exactly"
|
||||
+ " one option may be written as that option's value, and these have 4", several.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void irisClassesInBuiltInSettingsAreReadByThePacksGson() {
|
||||
IrisPosition marked = new IrisPosition(1, 2, 3);
|
||||
Gson iris = new GsonBuilder().registerTypeAdapter(IrisPosition.class, new TypeAdapter<IrisPosition>() {
|
||||
@Override
|
||||
public void write(JsonWriter out, IrisPosition value) throws IOException {
|
||||
out.value("marked");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisPosition read(JsonReader in) throws IOException {
|
||||
in.nextString();
|
||||
return marked;
|
||||
}
|
||||
}).create();
|
||||
ModuleSettingsDecoder withIrisGson = new ModuleSettingsDecoder(pack.catalog(), packFolder, () -> iris);
|
||||
|
||||
List<IrisPosition> marks = withIrisGson.decode(Target.BIOME, new JSONObject("{\"marks\": [\"a\", \"b\"]}"), "biome desert/dunes")
|
||||
.find(MarksSettings.class).orElseThrow().marks;
|
||||
|
||||
assertEquals(List.of(marked, marked), marks);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -96,7 +96,7 @@ public class ObjectPlacementModuleSettingsTest {
|
||||
public void install(StageGraph graph) {
|
||||
graph.define(TOP).when(GlowSettings.class).requires(BlocksStages.COMPLETE, AnchorStages.FINAL).run((context, glow) -> {
|
||||
int y = context.output(AnchorStages.FINAL).y() + 1;
|
||||
context.access().set(new PlacedBlock(new BlockPosition(0, y, 0), com.volmit.block.BlockState.parse(glow.block), Optional.empty()));
|
||||
context.access().set(new PlacedBlock(new BlockPosition(0, y, 0), com.volmit.block.BlockState.parse(glow.getFirst().value().block), Optional.empty()));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class ObjectPlacementModuleSettingsTest {
|
||||
|
||||
data = mock(IrisData.class);
|
||||
pack = BuiltInPlacementPack.serve(data, folder, List.of(new GlowModule()));
|
||||
ModuleSettingsDecoder decoder = new ModuleSettingsDecoder(pack.catalog(), folder.getRoot().toPath());
|
||||
ModuleSettingsDecoder decoder = new ModuleSettingsDecoder(pack.catalog(), folder.getRoot().toPath(), Gson::new);
|
||||
gson = new GsonBuilder().registerTypeAdapterFactory(new ObjectPlacementSettingsReader(() -> decoder)).create();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
@@ -37,7 +38,7 @@ public class PackModuleSetTest {
|
||||
|
||||
@Test
|
||||
public void loadsOnFirstUseAndClosesWithItsOwner() throws IOException {
|
||||
PackModuleSet modules = new PackModuleSet(folder.newFolder("plain"));
|
||||
PackModuleSet modules = new PackModuleSet(folder.newFolder("plain"), Gson::new);
|
||||
|
||||
assertSame(modules.pack(), modules.pack());
|
||||
assertTrue(modules.pack().packModules().isEmpty());
|
||||
@@ -50,7 +51,7 @@ public class PackModuleSetTest {
|
||||
public void aFailedLoadIsRememberedWithThePackNamed() throws IOException {
|
||||
File pack = folder.newFolder("broken");
|
||||
Files.writeString(Files.createDirectories(pack.toPath().resolve("modules")).resolve("empty.jar"), "not a jar");
|
||||
PackModuleSet modules = new PackModuleSet(pack);
|
||||
PackModuleSet modules = new PackModuleSet(pack, Gson::new);
|
||||
|
||||
PackModulesException first = assertThrows(PackModulesException.class, modules::pack);
|
||||
PackModulesException second = assertThrows(PackModulesException.class, modules::settings);
|
||||
|
||||
@@ -22,10 +22,8 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineMetrics;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimensionModeType;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
@@ -119,7 +117,7 @@ public class PerfectionModuleTest {
|
||||
}
|
||||
|
||||
private void generate() {
|
||||
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, null, new IrisRegion(), new IrisBiome(), key -> block(key, false));
|
||||
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, null, key -> block(key, false));
|
||||
}
|
||||
|
||||
private static PlatformBlockState decorant(boolean held) {
|
||||
|
||||
@@ -255,14 +255,16 @@ public class SchemaBuilderParityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectPlacementSchemaRendersModuleSettingsUnderTheirIdAndAlias() throws IOException {
|
||||
public void objectPlacementSchemaRendersModuleSettingsUnderTheirIdAndAliasWithTheirShorthand() throws IOException {
|
||||
JSONObject schema = new SchemaBuilder(IrisObjectPlacement.class, structureSchemaData(glowModuleSchema())).construct();
|
||||
JSONObject properties = rootProperties(schema);
|
||||
String definition = definitionKey(properties.getJSONObject("example:glow"));
|
||||
JSONArray forms = properties.getJSONObject("example:glow").getJSONArray("anyOf");
|
||||
String definition = definitionKey(forms.getJSONObject(0));
|
||||
JSONObject level = schema.getJSONObject("definitions").getJSONObject(definition)
|
||||
.getJSONObject("properties").getJSONObject("level");
|
||||
|
||||
assertEquals(definition, definitionKey(properties.getJSONObject("glow")));
|
||||
assertEquals(definition, definitionKey(properties.getJSONObject("glow").getJSONArray("anyOf").getJSONObject(0)));
|
||||
assertEquals("settings with one option also take its bare value", "integer", forms.getJSONObject(1).getString("type"));
|
||||
assertEquals("integer", level.getString("type"));
|
||||
assertEquals(1, level.getInt("minimum"));
|
||||
assertEquals(15, level.getInt("maximum"));
|
||||
|
||||
Reference in new issue
Block a user