Style: Fix spotless checkStyle
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -7,18 +7,26 @@ import javafx.animation.PauseTransition;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.media.AudioClip;
|
import javafx.scene.media.AudioClip;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages sound effects for the Casono game. Provides methods to play sounds for card reveals and
|
* Manages sound effects for the Casono game. Provides methods to play sounds
|
||||||
|
* for card reveals and
|
||||||
* button clicks.
|
* button clicks.
|
||||||
*/
|
*/
|
||||||
public class SoundManager {
|
public class SoundManager {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(SoundManager.class);
|
||||||
private static final SoundManager INSTANCE = new SoundManager();
|
private static final SoundManager INSTANCE = new SoundManager();
|
||||||
private final Map<String, AudioClip> soundCache = new HashMap<>();
|
private final Map<String, AudioClip> soundCache = new HashMap<>();
|
||||||
private float volume = 0.5f; // Volume level 0.0 - 1.0
|
private static final float MIN_VOLUME = 0.0f;
|
||||||
|
private static final float MAX_VOLUME = 1.0f;
|
||||||
|
private static final float DEFAULT_VOLUME = 0.5f;
|
||||||
|
private float volume = DEFAULT_VOLUME;
|
||||||
private static final long CARD_REVEAL_STAGGER_MS = 120; // Delay between card reveal sounds
|
private static final long CARD_REVEAL_STAGGER_MS = 120; // Delay between card reveal sounds
|
||||||
|
|
||||||
private SoundManager() {}
|
private SoundManager() {
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the singleton instance of SoundManager. */
|
/** Returns the singleton instance of SoundManager. */
|
||||||
public static SoundManager getInstance() {
|
public static SoundManager getInstance() {
|
||||||
@@ -26,7 +34,8 @@ public class SoundManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pre-loads critical sounds into cache to avoid delays on first play. Should be called at
|
* Pre-loads critical sounds into cache to avoid delays on first play. Should be
|
||||||
|
* called at
|
||||||
* application startup.
|
* application startup.
|
||||||
*/
|
*/
|
||||||
public void preloadSounds() {
|
public void preloadSounds() {
|
||||||
@@ -34,7 +43,7 @@ public class SoundManager {
|
|||||||
getOrLoadSound("button-click");
|
getOrLoadSound("button-click");
|
||||||
getOrLoadSound("card-reveal");
|
getOrLoadSound("card-reveal");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Error preloading sounds: " + e.getMessage());
|
LOGGER.error("Error preloading sounds", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,11 +58,15 @@ public class SoundManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays multiple card reveal sounds in sequence with slight stagger/overlap. Used when multiple
|
* Plays multiple card reveal sounds in sequence with slight stagger/overlap.
|
||||||
* cards are revealed at once (e.g., Flop reveals 3 cards, Turn reveals 1 card). Sounds play
|
* Used when multiple
|
||||||
* with a slight delay between them to simulate a person revealing cards one by one.
|
* cards are revealed at once (e.g., Flop reveals 3 cards, Turn reveals 1 card).
|
||||||
|
* Sounds play
|
||||||
|
* with a slight delay between them to simulate a person revealing cards one by
|
||||||
|
* one.
|
||||||
*
|
*
|
||||||
* @param count The number of cards being revealed. Each card gets its own sound with stagger.
|
* @param count The number of cards being revealed. Each card gets its own sound
|
||||||
|
* with stagger.
|
||||||
*/
|
*/
|
||||||
public void playCardRevealMultiple(int count) {
|
public void playCardRevealMultiple(int count) {
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
@@ -70,15 +83,12 @@ public class SoundManager {
|
|||||||
|
|
||||||
PauseTransition pause = new PauseTransition(Duration.millis(delayMs));
|
PauseTransition pause = new PauseTransition(Duration.millis(delayMs));
|
||||||
pause.setOnFinished(
|
pause.setOnFinished(
|
||||||
event ->
|
event -> Platform.runLater(
|
||||||
Platform.runLater(
|
|
||||||
() -> {
|
() -> {
|
||||||
try {
|
try {
|
||||||
playCardReveal();
|
playCardReveal();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(
|
LOGGER.error("Error playing card reveal sound", e);
|
||||||
"Error playing card reveal sound: "
|
|
||||||
+ e.getMessage());
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
pause.play();
|
pause.play();
|
||||||
@@ -96,7 +106,8 @@ public class SoundManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays a generic sound by key. The sound file should exist at: /sounds/{category}/{key}.mp3 or
|
* Plays a generic sound by key. The sound file should exist at:
|
||||||
|
* /sounds/{category}/{key}.mp3 or
|
||||||
* .wav
|
* .wav
|
||||||
*/
|
*/
|
||||||
public void playSound(String soundKey) {
|
public void playSound(String soundKey) {
|
||||||
@@ -107,12 +118,14 @@ public class SoundManager {
|
|||||||
audioClip.play();
|
audioClip.play();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Error playing sound: " + soundKey);
|
LOGGER.error("Error playing sound: {}", soundKey, e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets or loads a sound from cache. Categorizes sounds automatically based on key prefix. */
|
/**
|
||||||
|
* Gets or loads a sound from cache. Categorizes sounds automatically based on
|
||||||
|
* key prefix.
|
||||||
|
*/
|
||||||
private AudioClip getOrLoadSound(String soundKey) {
|
private AudioClip getOrLoadSound(String soundKey) {
|
||||||
if (soundCache.containsKey(soundKey)) {
|
if (soundCache.containsKey(soundKey)) {
|
||||||
return soundCache.get(soundKey);
|
return soundCache.get(soundKey);
|
||||||
@@ -128,12 +141,11 @@ public class SoundManager {
|
|||||||
soundCache.put(soundKey, clip);
|
soundCache.put(soundKey, clip);
|
||||||
return clip;
|
return clip;
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Sound resource not found: " + resourcePath);
|
LOGGER.warn("Sound resource not found: {}", resourcePath);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Failed to load sound: " + resourcePath);
|
LOGGER.error("Failed to load sound: {}", resourcePath, e);
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,7 +163,7 @@ public class SoundManager {
|
|||||||
|
|
||||||
/** Sets the volume for sound effects (0.0 - 1.0). */
|
/** Sets the volume for sound effects (0.0 - 1.0). */
|
||||||
public void setVolume(float volume) {
|
public void setVolume(float volume) {
|
||||||
this.volume = Math.max(0.0f, Math.min(1.0f, volume));
|
this.volume = Math.max(MIN_VOLUME, Math.min(MAX_VOLUME, volume));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the current volume level. */
|
/** Gets the current volume level. */
|
||||||
@@ -171,6 +183,6 @@ public class SoundManager {
|
|||||||
|
|
||||||
/** Unmutes sounds by restoring to default volume. */
|
/** Unmutes sounds by restoring to default volume. */
|
||||||
public void unmute() {
|
public void unmute() {
|
||||||
setVolume(0.5f);
|
setVolume(DEFAULT_VOLUME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -14,10 +14,10 @@ class TaskbarControllerInputValidationTest {
|
|||||||
void updateLogicRunsWithoutCrash() {
|
void updateLogicRunsWithoutCrash() {
|
||||||
GameState state = new GameState();
|
GameState state = new GameState();
|
||||||
|
|
||||||
state.players = List.of(
|
state.players =
|
||||||
|
List.of(
|
||||||
new Player(PlayerId.of("me"), 20000),
|
new Player(PlayerId.of("me"), 20000),
|
||||||
new Player(PlayerId.of("other"), 20000)
|
new Player(PlayerId.of("other"), 20000));
|
||||||
);
|
|
||||||
|
|
||||||
state.phase = "PREFLOP";
|
state.phase = "PREFLOP";
|
||||||
state.currentBet = 200;
|
state.currentBet = 200;
|
||||||
@@ -31,7 +31,6 @@ class TaskbarControllerInputValidationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class DummyController {
|
static class DummyController {
|
||||||
void update(GameState state, PlayerId id) {
|
void update(GameState state, PlayerId id) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user