feat(settings): persisted Music level; SettingsMenu applies via GameIO
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import thb.jeanluc.adventure.save.SaveSlotInfo;
|
||||
import thb.jeanluc.adventure.save.Settings;
|
||||
import thb.jeanluc.adventure.save.SettingsStore;
|
||||
import thb.jeanluc.adventure.io.ConsoleIO;
|
||||
import thb.jeanluc.adventure.io.MusicLevel;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@@ -64,11 +65,18 @@ class MenuTest {
|
||||
@Test
|
||||
void settingsMenuTogglesGlyphAndPersists(@TempDir Path dir) {
|
||||
SettingsStore store = new SettingsStore(dir.resolve("settings.json"));
|
||||
// choose "Glyph mode" (assume option 2) → its toggle, then "Back" (last)
|
||||
TestIO io = new TestIO().enqueue("2").enqueue("3");
|
||||
Settings result = SettingsMenu.show(io, Settings.defaults(), store, new ConsoleIO());
|
||||
// UNICODE default toggles to ASCII; persisted
|
||||
TestIO io = new TestIO().enqueue("2").enqueue("4"); // toggle Glyphs, then Back
|
||||
Settings result = SettingsMenu.show(io, Settings.defaults(), store);
|
||||
assertThat(result.glyphMode()).isEqualTo(ConsoleIO.GlyphMode.ASCII);
|
||||
assertThat(store.load().glyphMode()).isEqualTo(ConsoleIO.GlyphMode.ASCII);
|
||||
}
|
||||
|
||||
@Test
|
||||
void settingsMenuCyclesMusicLevelAndPersists(@TempDir Path dir) {
|
||||
SettingsStore store = new SettingsStore(dir.resolve("settings.json"));
|
||||
TestIO io = new TestIO().enqueue("3").enqueue("4"); // cycle Music once, then Back
|
||||
Settings result = SettingsMenu.show(io, Settings.defaults(), store);
|
||||
assertThat(result.musicLevel()).isEqualTo(MusicLevel.MEDIUM.next()); // HIGH
|
||||
assertThat(store.load().musicLevel()).isEqualTo(MusicLevel.MEDIUM.next());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package thb.jeanluc.adventure.save;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import thb.jeanluc.adventure.io.ConsoleIO;
|
||||
import thb.jeanluc.adventure.io.MusicLevel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -34,4 +35,18 @@ class SettingsStoreTest {
|
||||
Settings loaded = new SettingsStore(file).load();
|
||||
assertThat(loaded).isEqualTo(Settings.defaults());
|
||||
}
|
||||
|
||||
@Test
|
||||
void musicLevelRoundTrips(@TempDir Path dir) {
|
||||
SettingsStore store = new SettingsStore(dir.resolve("settings.json"));
|
||||
store.save(new Settings(ConsoleIO.ColorMode.AUTO, ConsoleIO.GlyphMode.UNICODE, MusicLevel.HIGH));
|
||||
assertThat(store.load().musicLevel()).isEqualTo(MusicLevel.HIGH);
|
||||
}
|
||||
|
||||
@Test
|
||||
void oldSettingsWithoutMusicDefaultToMedium(@TempDir Path dir) throws Exception {
|
||||
Path file = dir.resolve("settings.json");
|
||||
Files.writeString(file, "{\"colorMode\":\"ON\",\"glyphMode\":\"ASCII\"}");
|
||||
assertThat(new SettingsStore(file).load().musicLevel()).isEqualTo(MusicLevel.MEDIUM);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user