mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Settings are keyed by feature id and always an object: drop aliases and the one-option bare value
The settings decoder, the studio schema renderer and the schema builder no longer know aliases. Tests and fixtures use the iris:deposit object form.
This commit is contained in:
1 parent
2851e5d304
commit
d6228c3074
10 files changed
+84
-129
No files matched your search
@@ -29,6 +29,7 @@ import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ResolvedGraph;
|
||||
import com.volmit.host.schema.FeatureSchema;
|
||||
import com.volmit.host.schema.SchemaOption;
|
||||
import com.volmit.host.schema.ValueKind;
|
||||
import com.volmit.stage.MantleStage;
|
||||
import com.volmit.stage.Stage;
|
||||
@@ -91,14 +92,16 @@ public class BuiltInGenerationGraphTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depositsAreSettingsOfEveryLevelWrittenAsTheirOldList() throws IOException {
|
||||
public void depositsAreSettingsOfEveryLevelWrittenAsTheirIdWithGenerators() throws IOException {
|
||||
try (LoadedPack pack = BuiltInPack.serve(mock(IrisData.class), folder, List.of())) {
|
||||
for (Target level : List.of(Target.DIMENSION, Target.REGION, Target.BIOME)) {
|
||||
FeatureSchema deposits = pack.schema().fields(level).stream()
|
||||
.filter(feature -> feature.settings().name().equals(DepositSettings.class.getName()))
|
||||
.findFirst().orElseThrow();
|
||||
assertEquals("deposits", deposits.alias().orElseThrow());
|
||||
ValueKind generators = deposits.shorthand().orElseThrow().kind();
|
||||
assertEquals("iris:deposit", deposits.key());
|
||||
SchemaOption option = deposits.settings().options().getFirst();
|
||||
assertEquals("generators", option.name());
|
||||
ValueKind generators = option.kind();
|
||||
assertEquals("generators are a module class of IrisApi types, not an Iris class",
|
||||
new ValueKind.ListKind(new ValueKind.ObjectKind(DepositGenerator.class.getName()), false), generators);
|
||||
}
|
||||
|
||||
@@ -27,15 +27,17 @@ import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* The deposits packs have always written read into {@link DepositGenerator}, a settings class of IrisApi types only,
|
||||
* The deposit generators packs have always written, now under {@code "iris:deposit": {"generators": [...]}}, read into {@link DepositGenerator}, a settings class of IrisApi types only,
|
||||
* with the values Iris's own deposit generator class read from the same JSON.
|
||||
*/
|
||||
public class DepositSettingsDecodingTest {
|
||||
private static final String REGION_DEPOSITS = """
|
||||
{"deposits": [
|
||||
{"iris:deposit": {"generators": [
|
||||
{"minHeight": 15, "maxPerChunk": 26, "maxHeight": 410, "minPerChunk": 4, "minSize": 3, "maxSize": 8,
|
||||
"palette": [{"block": "minecraft:iron_ore"}, {"block": "minecraft:coal_ore"}], "varience": 4},
|
||||
{"heightDistribution": "TRIANGLE", "placementScope": "FULL_HEIGHT", "surfaceClearance": 0, "shape": "VANILLA_ELLIPSOID",
|
||||
@@ -45,7 +47,7 @@ public class DepositSettingsDecodingTest {
|
||||
"snippet/deposit/diamonds",
|
||||
"snippet/diamonds",
|
||||
{}
|
||||
]}
|
||||
]}}
|
||||
""";
|
||||
|
||||
@Rule
|
||||
@@ -140,10 +142,20 @@ public class DepositSettingsDecodingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theFeatureIdReadsTheSameAsTheOldKey() {
|
||||
String byId = "{\"iris:deposit\": {\"generators\": [{\"maxHeight\": 16}]}}";
|
||||
public void theOldBareListUnderTheOldKeyIsNotSettings() {
|
||||
JSONObject old = new JSONObject("{\"deposits\": [{\"maxHeight\": 16}]}");
|
||||
|
||||
assertEquals(16, deposits(byId).getFirst().maxHeight());
|
||||
assertSame(ModuleSettings.NONE, decoder.decode(Target.REGION, old, "region forests"));
|
||||
assertFalse(decoder.keys(Target.REGION).contains("deposits"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBareListUnderTheFeatureIdIsRefused() {
|
||||
JSONObject bare = new JSONObject("{\"iris:deposit\": [{\"maxHeight\": 16}]}");
|
||||
|
||||
IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, () -> decoder.decode(Target.REGION, bare, "region forests"));
|
||||
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("write the settings as an object"));
|
||||
}
|
||||
|
||||
private List<DepositGenerator> deposits(String regionJson) {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ModuleChunkGenerationTest {
|
||||
private Engine engine;
|
||||
private Hunk<PlatformBlockState> blocks;
|
||||
|
||||
@Feature(id = "iris:pillar", name = "Pillar", alias = "pillar", targets = {Target.BIOME, Target.REGION, Target.DIMENSION})
|
||||
@Feature(id = "iris:pillar", name = "Pillar", targets = {Target.BIOME, Target.REGION, Target.DIMENSION})
|
||||
public static final class PillarSettings implements IrisFeature {
|
||||
private BlockState block = BlockState.parse("minecraft:stone");
|
||||
private int x;
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ModuleSettingsDecoderTest {
|
||||
private LoadedPack pack;
|
||||
private ModuleSettingsDecoder decoder;
|
||||
|
||||
@Feature(id = "iris:moss", name = "Moss", alias = "moss", targets = {Target.BIOME, Target.REGION})
|
||||
@Feature(id = "iris:moss", name = "Moss", targets = {Target.BIOME, Target.REGION})
|
||||
public static final class MossSettings implements IrisFeature {
|
||||
private int radius = 3;
|
||||
private BlockState block = new BlockState("minecraft:moss_block");
|
||||
@@ -83,12 +83,12 @@ public class ModuleSettingsDecoderTest {
|
||||
private int size = 1;
|
||||
}
|
||||
|
||||
@Feature(id = "iris:moss/cover", name = "Cover", alias = "cover", targets = Target.BIOME)
|
||||
@Feature(id = "iris:moss/cover", name = "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)
|
||||
@Feature(id = "iris:moss/marks", name = "Marks", targets = Target.BIOME)
|
||||
public static final class MarksSettings implements IrisFeature {
|
||||
private List<IrisPosition> marks = List.of();
|
||||
}
|
||||
@@ -141,31 +141,27 @@ public class ModuleSettingsDecoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readsSettingsUnderTheirIdOrBuiltInAliasKeepingOmittedDefaults() {
|
||||
public void readsSettingsUnderTheirIdKeepingOmittedDefaults() {
|
||||
MossSettings byId = moss("{\"iris:moss\": {\"radius\": 7, \"block\": \"minecraft:oak_log[axis=y]\"}}");
|
||||
MossSettings byAlias = moss("{\"moss\": {\"palette\": \"iris:moss/wet\"}}");
|
||||
MossSettings partial = moss("{\"iris:moss\": {\"palette\": \"iris:moss/wet\"}}");
|
||||
|
||||
assertEquals(7, byId.radius);
|
||||
assertEquals(BlockState.parse("minecraft:oak_log[axis=y]"), byId.block);
|
||||
assertEquals(ResourceId.parse("iris:moss/default"), byId.palette);
|
||||
assertEquals(3, byAlias.radius);
|
||||
assertEquals(ResourceId.parse("iris:moss/wet"), byAlias.palette);
|
||||
assertEquals(1, byAlias.patch.size);
|
||||
assertEquals(3, partial.radius);
|
||||
assertEquals(ResourceId.parse("iris:moss/wet"), partial.palette);
|
||||
assertEquals(1, partial.patch.size);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void declaresNothingWhereNoKeyIsPresent() {
|
||||
assertSame(ModuleSettings.NONE, decoder.decode(Target.BIOME, new JSONObject("{\"name\": \"Dunes\"}"), "biome desert/dunes"));
|
||||
assertSame(ModuleSettings.NONE, decoder.decode(Target.DIMENSION, new JSONObject("{\"moss\": {}}"), "dimension overworld"));
|
||||
assertSame(ModuleSettings.NONE, decoder.decode(Target.DIMENSION, new JSONObject("{\"iris:moss\": {}}"), "dimension overworld"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bothTheAliasAndTheIdInOneObjectFail() {
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class,
|
||||
() -> moss("{\"moss\": {}, \"iris:moss\": {}}"));
|
||||
|
||||
assertEquals("biome desert/dunes sets both \"moss\" and \"iris:moss\", the alias and the id of settings iris:moss; keep one",
|
||||
failure.getMessage());
|
||||
public void aShortKeyIsNotAKeyOfTheSettings() {
|
||||
assertSame(ModuleSettings.NONE, decoder.decode(Target.BIOME, new JSONObject("{\"moss\": {\"radius\": 7}}"), "biome desert/dunes"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,10 +169,10 @@ public class ModuleSettingsDecoderTest {
|
||||
Path snippets = Files.createDirectories(packFolder.resolve("snippet/moss-patch"));
|
||||
Files.writeString(snippets.resolve("wide.json"), "{\"size\": 9}");
|
||||
|
||||
assertEquals(9, moss("{\"moss\": {\"patch\": \"snippet/wide\"}}").patch.size);
|
||||
assertEquals(9, moss("{\"iris:moss\": {\"patch\": \"snippet/wide\"}}").patch.size);
|
||||
|
||||
IllegalArgumentException missing = assertThrows(IllegalArgumentException.class,
|
||||
() -> moss("{\"moss\": {\"patch\": \"snippet/narrow\"}}"));
|
||||
() -> moss("{\"iris:moss\": {\"patch\": \"snippet/narrow\"}}"));
|
||||
assertTrue(missing.getMessage(), missing.getMessage().contains("Snippet snippet/narrow has no file snippet/moss-patch/narrow.json"));
|
||||
}
|
||||
|
||||
@@ -185,7 +181,7 @@ public class ModuleSettingsDecoderTest {
|
||||
Path snippets = Files.createDirectories(packFolder.resolve("snippet/moss-patch"));
|
||||
Files.writeString(snippets.resolve("wide.json"), "{\"size\": 9}");
|
||||
|
||||
assertEquals(9, moss("{\"moss\": {\"patch\": \"snippet/moss-patch/wide\"}}").patch.size);
|
||||
assertEquals(9, moss("{\"iris:moss\": {\"patch\": \"snippet/moss-patch/wide\"}}").patch.size);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,27 +223,28 @@ public class ModuleSettingsDecoderTest {
|
||||
@Test
|
||||
public void badValuesNameTheSettingsKeyAndResource() {
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class,
|
||||
() -> moss("{\"moss\": {\"block\": \"stone\"}}"));
|
||||
() -> moss("{\"iris:moss\": {\"block\": \"stone\"}}"));
|
||||
|
||||
assertTrue(failure.getMessage(), failure.getMessage().startsWith("Cannot read settings iris:moss under \"moss\" in biome desert/dunes: "));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().startsWith("Cannot read settings iris:moss under \"iris:moss\" in biome desert/dunes: "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listsTheKeysModulesReadPerTarget() {
|
||||
assertEquals(Set.of("iris:moss", "moss", "iris:moss/cover", "cover", "iris:moss/marks", "marks", "iris:moss/values"), decoder.keys(Target.BIOME));
|
||||
assertEquals(Set.of("iris:moss", "iris:moss/cover", "iris:moss/marks", "iris:moss/values"), decoder.keys(Target.BIOME));
|
||||
assertEquals(Set.of(), decoder.keys(Target.DIMENSION));
|
||||
}
|
||||
|
||||
@Test
|
||||
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")
|
||||
public void settingsAreAlwaysAnObjectEvenWithOneOption() {
|
||||
assertEquals(0.25, decoder.decode(Target.BIOME, new JSONObject("{\"iris:moss/cover\": {\"amount\": 0.25}}"), "biome desert/dunes")
|
||||
.find(CoverSettings.class).orElseThrow().amount, 0);
|
||||
|
||||
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());
|
||||
for (String bare : List.of("0.5", "[1, 2]", "true")) {
|
||||
IllegalArgumentException refused = assertThrows(IllegalArgumentException.class,
|
||||
() -> decoder.decode(Target.BIOME, new JSONObject("{\"iris:moss/cover\": " + bare + "}"), "biome desert/dunes"));
|
||||
assertEquals("Cannot read settings iris:moss/cover under \"iris:moss/cover\" in biome desert/dunes: write the settings as an object,"
|
||||
+ " {\"<option>\": ...}", refused.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -267,7 +264,7 @@ public class ModuleSettingsDecoderTest {
|
||||
}).create();
|
||||
ModuleSettingsDecoder withIrisGson = new ModuleSettingsDecoder(pack.catalog(), packFolder, () -> iris);
|
||||
|
||||
List<IrisPosition> marks = withIrisGson.decode(Target.BIOME, new JSONObject("{\"marks\": [\"a\", \"b\"]}"), "biome desert/dunes")
|
||||
List<IrisPosition> marks = withIrisGson.decode(Target.BIOME, new JSONObject("{\"iris:moss/marks\": {\"marks\": [\"a\", \"b\"]}}"), "biome desert/dunes")
|
||||
.find(MarksSettings.class).orElseThrow().marks;
|
||||
|
||||
assertEquals(List.of(marked, marked), marks);
|
||||
|
||||
@@ -256,22 +256,21 @@ public class SchemaBuilderParityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectPlacementSchemaRendersModuleSettingsUnderTheirIdAndAliasWithTheirShorthand() throws IOException {
|
||||
public void objectPlacementSchemaRendersModuleSettingsUnderTheirId() throws IOException {
|
||||
JSONObject schema = new SchemaBuilder(IrisObjectPlacement.class, structureSchemaData(glowModuleSchema())).construct();
|
||||
JSONObject properties = rootProperties(schema);
|
||||
JSONArray forms = properties.getJSONObject("example:glow").getJSONArray("anyOf");
|
||||
String definition = definitionKey(forms.getJSONObject(0));
|
||||
String definition = definitionKey(properties.getJSONObject("example:glow"));
|
||||
JSONObject level = schema.getJSONObject("definitions").getJSONObject(definition)
|
||||
.getJSONObject("properties").getJSONObject("level");
|
||||
|
||||
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"));
|
||||
assertFalse("no alias property", properties.has("glow"));
|
||||
assertFalse("settings are their object only, no bare value form", properties.getJSONObject("example:glow").has("anyOf"));
|
||||
assertFalse("no alias constraint", schema.has("allOf"));
|
||||
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
|
||||
@@ -699,7 +698,7 @@ public class SchemaBuilderParityTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Feature(id = "example:glow", name = "Glow", alias = "glow", targets = Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "example:glow", name = "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)
|
||||
|
||||
Reference in new issue
Block a user