mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Store Iris settings in iris.toml
Moves an existing iris.json over on first load
This commit is contained in:
1 parent
1e04f61957
commit
0bf7c346a2
34 files changed
+403
-174
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.configuration;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -13,12 +12,11 @@ import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class IrisSettingsDefaultsTest {
|
||||
@Test
|
||||
public void updateChecksDefaultOnAndPersistAnExplicitOptOut() {
|
||||
assertTrue(IrisSettings.parseHotloadSnapshot("{}").getGeneral().isUpdateNotifications());
|
||||
IrisSettings optedOut = IrisSettings.parseHotloadSnapshot(
|
||||
"{\"general\":{\"updateNotifications\":false}}");
|
||||
public void updateChecksDefaultOnAndPersistAnExplicitOptOut() throws Exception {
|
||||
assertTrue(IrisSettings.parseHotloadSnapshot("[general]").getGeneral().isUpdateNotifications());
|
||||
IrisSettings optedOut = IrisSettings.parseHotloadSnapshot("[general]\nupdateNotifications = false");
|
||||
assertFalse(optedOut.getGeneral().isUpdateNotifications());
|
||||
assertFalse(new Gson().fromJson(new Gson().toJson(optedOut), IrisSettings.class)
|
||||
assertFalse(IrisSettingsFile.parse(IrisSettingsFile.render(optedOut))
|
||||
.getGeneral().isUpdateNotifications());
|
||||
}
|
||||
|
||||
@@ -33,20 +31,20 @@ public class IrisSettingsDefaultsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void concurrencyIsNotSerializedIntoIrisJson() {
|
||||
String json = new Gson().toJson(new IrisSettings());
|
||||
public void concurrencyIsNotWrittenToTheSettingsFile() {
|
||||
String toml = IrisSettingsFile.render(new IrisSettings());
|
||||
|
||||
assertFalse("iris.json must not advertise an unconfigurable concurrency block",
|
||||
json.contains("\"concurrency\""));
|
||||
assertFalse("iris.toml must not advertise an unconfigurable concurrency block",
|
||||
toml.contains("concurrency"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void languageAndMetricsAreTheFirstGeneralControls() {
|
||||
String json = new Gson().toJson(new IrisSettings());
|
||||
String toml = IrisSettingsFile.render(new IrisSettings());
|
||||
|
||||
int language = json.indexOf("\"language\"");
|
||||
int metrics = json.indexOf("\"metrics\"");
|
||||
int commandSounds = json.indexOf("\"commandSounds\"");
|
||||
int language = toml.indexOf("\nlanguage = ");
|
||||
int metrics = toml.indexOf("\nmetrics = ");
|
||||
int commandSounds = toml.indexOf("\ncommandSounds = ");
|
||||
assertTrue(language >= 0);
|
||||
assertTrue(language < metrics);
|
||||
assertTrue(metrics < commandSounds);
|
||||
@@ -75,10 +73,10 @@ public class IrisSettingsDefaultsTest {
|
||||
public void studioBlendingDefaultsOnAndAcceptsDisabledHotload() {
|
||||
IrisSettings defaults = new IrisSettings();
|
||||
assertTrue(defaults.getStudio().isBlendChanges());
|
||||
assertTrue(new Gson().fromJson("{\"studio\":{}}", IrisSettings.class).getStudio().isBlendChanges());
|
||||
assertTrue(new Gson().toJson(defaults).contains("\"blendChanges\":true"));
|
||||
assertTrue(IrisSettings.parseHotloadSnapshot("[studio]").getStudio().isBlendChanges());
|
||||
assertTrue(IrisSettingsFile.render(defaults).contains("\nblendChanges = true"));
|
||||
|
||||
IrisSettings changed = IrisSettings.parseHotloadSnapshot("{\"studio\":{\"blendChanges\":false}}");
|
||||
IrisSettings changed = IrisSettings.parseHotloadSnapshot("[studio]\nblendChanges = false");
|
||||
|
||||
assertFalse(changed.getStudio().isBlendChanges());
|
||||
assertEquals(256, changed.getGenerator().getGenerationTransitionWidthBlocks());
|
||||
@@ -91,11 +89,10 @@ public class IrisSettingsDefaultsTest {
|
||||
IrisSettings.settings = live;
|
||||
try {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> IrisSettings.installHotloadSnapshot("{\"general\":"));
|
||||
() -> IrisSettings.installHotloadSnapshot("[general"));
|
||||
assertSame(live, IrisSettings.settings);
|
||||
|
||||
IrisSettings installed = IrisSettings.installHotloadSnapshot(
|
||||
"{\"general\":{\"language\":\"fr_FR\"},\"world\":null}");
|
||||
IrisSettings installed = IrisSettings.installHotloadSnapshot("[general]\nlanguage = \"fr_FR\"");
|
||||
assertSame(installed, IrisSettings.settings);
|
||||
assertEquals("fr_FR", installed.getGeneral().getLanguage());
|
||||
assertNotNull(installed.getWorld());
|
||||
@@ -112,7 +109,7 @@ public class IrisSettingsDefaultsTest {
|
||||
IrisSettings.settings = live;
|
||||
try {
|
||||
boolean applied = IrisSettings.applyHotloadSnapshot(
|
||||
"{\"general\":{\"language\":\"de_DE\"}}",
|
||||
"[general]\nlanguage = \"de_DE\"",
|
||||
candidate -> false
|
||||
);
|
||||
|
||||
@@ -131,7 +128,7 @@ public class IrisSettingsDefaultsTest {
|
||||
IrisSettings.settings = live;
|
||||
try {
|
||||
boolean applied = IrisSettings.applyHotloadSnapshot(
|
||||
"{\"general\":{\"language\":\"de_DE\"},\"world\":null}",
|
||||
"[general]\nlanguage = \"de_DE\"",
|
||||
candidate -> "de_DE".equals(candidate.getGeneral().getLanguage())
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
package art.arcane.iris.configuration;
|
||||
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.world.IrisRuntimeSchedulerMode;
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class IrisSettingsFileTest {
|
||||
private static final FileTime LONG_AGO = FileTime.fromMillis(1_000_000L);
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
private IrisPlatform previousPlatform;
|
||||
private IrisSettings previousSettings;
|
||||
private File settingsFile;
|
||||
private File legacyFile;
|
||||
|
||||
@Before
|
||||
public void bindPlatform() throws Exception {
|
||||
previousSettings = IrisSettings.settings;
|
||||
previousPlatform = IrisPlatforms.isBound() ? IrisPlatforms.get() : null;
|
||||
IrisPlatforms.unbind();
|
||||
File dataFolder = temporaryFolder.newFolder("Iris");
|
||||
settingsFile = new File(dataFolder, IrisSettingsFile.FILE_NAME);
|
||||
legacyFile = new File(dataFolder, IrisSettingsFile.LEGACY_FILE_NAME);
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
doReturn(settingsFile).when(platform).dataFile(IrisSettingsFile.FILE_NAME);
|
||||
IrisPlatforms.bind(platform);
|
||||
}
|
||||
|
||||
@After
|
||||
public void restore() {
|
||||
IrisPlatforms.unbind();
|
||||
if (previousPlatform != null) {
|
||||
IrisPlatforms.bind(previousPlatform);
|
||||
}
|
||||
IrisSettings.settings = previousSettings;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writtenSettingsReadBackUnchanged() throws Exception {
|
||||
IrisSettings edited = new IrisSettings();
|
||||
edited.getGeneral().setLanguage("de_DE");
|
||||
edited.getGeneral().setDebug(true);
|
||||
edited.getWorld().setAsyncTickIntervalMS(1_250L);
|
||||
edited.getWorld().setTargetSpawnEntitiesPerChunk(1.5D);
|
||||
edited.getPregen().setRuntimeSchedulerMode(IrisRuntimeSchedulerMode.FOLIA);
|
||||
edited.getPerformance().getEngineSVC().setParallelism(6);
|
||||
|
||||
String rendered = IrisSettingsFile.render(edited);
|
||||
IrisSettings readBack = IrisSettingsFile.parse(rendered);
|
||||
|
||||
assertEquals(new Gson().toJson(edited), new Gson().toJson(readBack));
|
||||
assertEquals(rendered, IrisSettingsFile.render(readBack));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingFileIsCreatedFromDefaults() throws Exception {
|
||||
IrisSettings loaded = IrisSettingsFile.load();
|
||||
|
||||
assertEquals(new Gson().toJson(new IrisSettings()), new Gson().toJson(loaded));
|
||||
assertEquals(IrisSettingsFile.render(new IrisSettings()), Files.readString(settingsFile.toPath()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void legacyJsonMovesToToml() throws Exception {
|
||||
Files.writeString(legacyFile.toPath(), "{\"general\":{\"debug\":true},\"pregen\":{\"runtimeSchedulerMode\":\"FOLIA\"}}");
|
||||
|
||||
IrisSettings loaded = IrisSettingsFile.load();
|
||||
|
||||
assertTrue(loaded.getGeneral().isDebug());
|
||||
assertEquals(IrisRuntimeSchedulerMode.FOLIA, loaded.getPregen().getRuntimeSchedulerMode());
|
||||
assertFalse(legacyFile.exists());
|
||||
assertTrue(IrisSettingsFile.parse(Files.readString(settingsFile.toPath())).getGeneral().isDebug());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void brokenLegacyJsonStaysWhereItIs() throws Exception {
|
||||
Files.writeString(legacyFile.toPath(), "{\"general\":");
|
||||
|
||||
IrisSettings loaded = IrisSettingsFile.load();
|
||||
|
||||
assertFalse(loaded.getGeneral().isDebug());
|
||||
assertEquals("{\"general\":", Files.readString(legacyFile.toPath()));
|
||||
assertFalse(settingsFile.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void brokenTomlIsNotOverwritten() throws Exception {
|
||||
String broken = "[general]\ndebug = tru\n";
|
||||
Files.writeString(settingsFile.toPath(), broken);
|
||||
|
||||
IrisSettings loaded = IrisSettingsFile.load();
|
||||
|
||||
assertFalse(loaded.getGeneral().isDebug());
|
||||
assertEquals(broken, Files.readString(settingsFile.toPath()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upToDateFileIsNotRewritten() throws Exception {
|
||||
Files.writeString(settingsFile.toPath(), IrisSettingsFile.render(new IrisSettings()));
|
||||
Files.setLastModifiedTime(settingsFile.toPath(), LONG_AGO);
|
||||
|
||||
IrisSettingsFile.load();
|
||||
|
||||
assertEquals(LONG_AGO, Files.getLastModifiedTime(settingsFile.toPath()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingKeysAreAddedOnLoad() throws Exception {
|
||||
Files.writeString(settingsFile.toPath(), "[general]\ndebug = true\n");
|
||||
|
||||
IrisSettingsFile.load();
|
||||
|
||||
String rewritten = Files.readString(settingsFile.toPath());
|
||||
assertTrue(rewritten.contains("\ndebug = true"));
|
||||
assertTrue(rewritten.contains("\n[studio]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void documentedSettingsCarryTheirComment() {
|
||||
String rendered = IrisSettingsFile.render(new IrisSettings());
|
||||
|
||||
assertTrue(rendered.contains("# Turns unresolved pack content keys and bad block-state properties into blocking pack errors.\n"
|
||||
+ "# Effect: The -Diris.strictContent system property overrides this.\n"
|
||||
+ "strictContentKeys = false\n"));
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -21,7 +21,7 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Iris rewrites iris.json on every read so a file written by an older build gains the keys it is missing.
|
||||
* Iris rewrites iris.toml on every read that finds it out of date so a file written by an older build gains the keys it is missing.
|
||||
* That write used to fail into an empty catch, which is how a read-only or full data folder turned every
|
||||
* settings change an operator made in game into something that silently vanished on the next boot.
|
||||
*/
|
||||
@@ -53,10 +53,10 @@ public class IrisSettingsRewriteFailureTest {
|
||||
|
||||
@Test
|
||||
public void anUnwritableSettingsFileIsReported() throws Exception {
|
||||
File settingsFile = temporaryFolder.newFile("iris.json");
|
||||
Files.writeString(settingsFile.toPath(), "{}");
|
||||
File settingsFile = temporaryFolder.newFile(IrisSettingsFile.FILE_NAME);
|
||||
Files.writeString(settingsFile.toPath(), "[general]");
|
||||
assertTrue("this test needs a file the JVM can mark read-only", settingsFile.setWritable(false));
|
||||
doReturn(settingsFile).when(capturingPlatform).dataFile("iris.json");
|
||||
doReturn(settingsFile).when(capturingPlatform).dataFile(IrisSettingsFile.FILE_NAME);
|
||||
|
||||
IrisSettings.invalidate();
|
||||
IrisSettings.get();
|
||||
@@ -66,14 +66,14 @@ public class IrisSettingsRewriteFailureTest {
|
||||
|
||||
@Test
|
||||
public void aWritableSettingsFileIsRewrittenQuietly() throws Exception {
|
||||
File settingsFile = temporaryFolder.newFile("iris.json");
|
||||
Files.writeString(settingsFile.toPath(), "{}");
|
||||
doReturn(settingsFile).when(capturingPlatform).dataFile("iris.json");
|
||||
File settingsFile = temporaryFolder.newFile(IrisSettingsFile.FILE_NAME);
|
||||
Files.writeString(settingsFile.toPath(), "[general]");
|
||||
doReturn(settingsFile).when(capturingPlatform).dataFile(IrisSettingsFile.FILE_NAME);
|
||||
|
||||
IrisSettings.invalidate();
|
||||
IrisSettings.get();
|
||||
|
||||
verify(capturingPlatform, never()).reportError(anyString(), any(Throwable.class));
|
||||
assertTrue(Files.readString(settingsFile.toPath()).contains("general"));
|
||||
assertTrue(Files.readString(settingsFile.toPath()).contains("[general]"));
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class SettingsHotloadWatchTest {
|
||||
public void setUp() throws Exception {
|
||||
previousSettings = IrisSettings.settings;
|
||||
dataFolder = temporaryFolder.newFolder("iris-hotload");
|
||||
settingsFile = new File(dataFolder, "iris.json");
|
||||
settingsFile = new File(dataFolder, IrisSettingsFile.FILE_NAME);
|
||||
overrideFolder = new File(dataFolder, "languages");
|
||||
Files.createDirectories(overrideFolder.toPath());
|
||||
String settings = settings("en_US");
|
||||
@@ -416,7 +416,7 @@ public class SettingsHotloadWatchTest {
|
||||
}
|
||||
|
||||
private String settings(String locale) {
|
||||
return "{\"general\":{\"language\":\"" + locale + "\"}}";
|
||||
return "[general]\nlanguage = \"" + locale + "\"\n";
|
||||
}
|
||||
|
||||
private String locale(String locale, String permissionMessage) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettingsFile;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.EngineRuntimeBuilder.RuntimeAssembly;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureOwnershipStore;
|
||||
@@ -87,7 +88,7 @@ public class EngineShutdownDrainTest {
|
||||
previousPlatform = IrisPlatforms.isBound() ? IrisPlatforms.get() : null;
|
||||
IrisPlatforms.unbind();
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
when(platform.dataFile("iris.json")).thenReturn(PLATFORM_FILES.getRoot().toPath().resolve("iris.json").toFile());
|
||||
when(platform.dataFile(IrisSettingsFile.FILE_NAME)).thenReturn(PLATFORM_FILES.getRoot().toPath().resolve(IrisSettingsFile.FILE_NAME).toFile());
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
when(platform.registries()).thenReturn(registries);
|
||||
when(registries.block(anyString())).thenReturn(mock(NativeBlockState.class));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.localization;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.configuration.IrisSettingsFile;
|
||||
import art.arcane.iris.testsupport.ProjectPaths;
|
||||
import art.arcane.volmlib.util.localization.MessageArgument;
|
||||
import art.arcane.volmlib.util.localization.LocaleOverlay;
|
||||
@@ -171,7 +172,7 @@ public class IrisLanguageTest {
|
||||
IrisSettings previous = IrisSettings.settings;
|
||||
IrisSettings current = new IrisSettings();
|
||||
IrisSettings.settings = current;
|
||||
Files.createDirectory(dataFolder.toPath().resolve("iris.json"));
|
||||
Files.createDirectory(dataFolder.toPath().resolve(IrisSettingsFile.FILE_NAME));
|
||||
IrisLanguage.start();
|
||||
try {
|
||||
assertThrows(ExecutionException.class,
|
||||
@@ -525,7 +526,7 @@ public class IrisLanguageTest {
|
||||
IrisSettings.settings = live;
|
||||
try {
|
||||
boolean applied = IrisSettings.applyHotloadSnapshot(
|
||||
"{\"general\":{\"language\":\"../invalid\"}}",
|
||||
"[general]\nlanguage = \"../invalid\"",
|
||||
IrisLanguage::reload
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user