From 5cca8f5c05712fe33d1e2b9fa1f7260a12eca0bc Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 8 Oct 2024 19:57:37 +0200 Subject: [PATCH] refactor and documentation --- .../pp/battleship/client/BattleshipApp.java | 2 +- .../pp/battleship/client/gui/GameMusic.java | 20 +++++++++++++------ .../battleship/client/gui/VolumeSlider.java | 14 +++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipApp.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipApp.java index 654beb2..25ef74b 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipApp.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/BattleshipApp.java @@ -283,7 +283,7 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient } /** - * Attaches the game sound state and sets its initial enabled state. + * Attaches the background music state and sets its initial enabled state. */ private void attachGameMusic() { final GameMusic gameSound = new GameMusic(); diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/GameMusic.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/GameMusic.java index 0b2d39a..8b3c44e 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/GameMusic.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/GameMusic.java @@ -34,7 +34,7 @@ public class GameMusic extends AbstractAppState{ /** * Checks if sound is enabled in the preferences. * - * @return //TODO + * @return float to which the volume is set */ public static float volumeInPreferences() { return PREFERENCES.getFloat(VOLUME_PREF, 0.5f); @@ -78,7 +78,7 @@ public class GameMusic extends AbstractAppState{ return null; } - /** TODO + /** * Sets the enabled state of this AppState. * Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)} * @@ -87,11 +87,15 @@ public class GameMusic extends AbstractAppState{ @Override public void setEnabled(boolean enabled) { if (isEnabled() == enabled) return; - else if(!isEnabled() && enabled) { - if (music != null) music.play(); - } else if (isEnabled() && !enabled) { - if (music != null) music.stop(); + + if (music != null) { + if (enabled) { + music.play(); + } else { + music.stop(); + } } + super.setEnabled(enabled); LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); //NON-NLS PREFERENCES.putBoolean(ENABLED_PREF, enabled); @@ -104,6 +108,10 @@ public class GameMusic extends AbstractAppState{ setEnabled(!isEnabled()); } + /** + * Sets the volume of music + * @param vol the volume to which the music should be set + */ public void setVolume(float vol){ music.setVolume(vol); PREFERENCES.putFloat(VOLUME_PREF, vol); diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java index df7cbad..aa27292 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java @@ -1,13 +1,20 @@ package pp.battleship.client.gui; import com.simsilica.lemur.Slider; - +/** + * The VolumeSlider class represents the Volume Slider in the Menu. + * It extends the Slider class and provides functionalities for setting the music volume, + * with the help of the Slider in the GUI + */ public class VolumeSlider extends Slider { private final GameMusic music; - private double vol; + /** + * Constructs the Volume Slider for the Menu dialog + * @param music the music instance + */ public VolumeSlider(GameMusic music) { super(); this.music = music; @@ -15,6 +22,9 @@ public class VolumeSlider extends Slider { getModel().setPercent(vol); } + /** + * when triggered it updates the volume to the value set with the slider + */ public void update() { if (vol != getModel().getPercent()) { vol = getModel().getPercent();