feat(io): MusicLevel enum (Off/Low/Med/High)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package thb.jeanluc.adventure.io;
|
||||
|
||||
/** Background-music volume level, cycled in the Settings menu. */
|
||||
public enum MusicLevel {
|
||||
OFF, LOW, MEDIUM, HIGH;
|
||||
|
||||
/** Target MASTER_GAIN in decibels. Irrelevant for {@link #OFF} (playback disabled). */
|
||||
public float gainDb() {
|
||||
return switch (this) {
|
||||
case OFF -> Float.NEGATIVE_INFINITY;
|
||||
case LOW -> -20f;
|
||||
case MEDIUM -> -10f;
|
||||
case HIGH -> 0f;
|
||||
};
|
||||
}
|
||||
|
||||
/** @return true when music should play. */
|
||||
public boolean isOn() {
|
||||
return this != OFF;
|
||||
}
|
||||
|
||||
/** Next level in the cycle (wraps HIGH → OFF). */
|
||||
public MusicLevel next() {
|
||||
return values()[(ordinal() + 1) % values().length];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package thb.jeanluc.adventure.io;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class MusicLevelTest {
|
||||
|
||||
@Test
|
||||
void gainIncreasesWithLevel() {
|
||||
assertThat(MusicLevel.LOW.gainDb()).isLessThan(MusicLevel.MEDIUM.gainDb());
|
||||
assertThat(MusicLevel.MEDIUM.gainDb()).isLessThan(MusicLevel.HIGH.gainDb());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isOnOnlyWhenNotOff() {
|
||||
assertThat(MusicLevel.OFF.isOn()).isFalse();
|
||||
assertThat(MusicLevel.LOW.isOn()).isTrue();
|
||||
assertThat(MusicLevel.HIGH.isOn()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void nextCyclesThroughAllAndWraps() {
|
||||
assertThat(MusicLevel.OFF.next()).isEqualTo(MusicLevel.LOW);
|
||||
assertThat(MusicLevel.LOW.next()).isEqualTo(MusicLevel.MEDIUM);
|
||||
assertThat(MusicLevel.MEDIUM.next()).isEqualTo(MusicLevel.HIGH);
|
||||
assertThat(MusicLevel.HIGH.next()).isEqualTo(MusicLevel.OFF);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user