From 9b6b929c34b943350f53954af1ea582153725355 Mon Sep 17 00:00:00 2001
From: jg175 <jg175@hdm-stuttgart.de>
Date: Thu, 25 Jan 2024 17:39:28 +0100
Subject: [PATCH] UPDATE: soundeffects

---
 .../Controller/GameSceneController.java       |  2 ++
 .../Controller/MapSelectionController.java    |  6 ++++++
 .../battlearena/Model/Sound/MusicPlayer.java  | 10 ++++------
 .../battlearena/Model/Sound/SoundEffects.java | 19 ++++++++++---------
 4 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java
index 18984aff..1b09b4b3 100644
--- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java
+++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java
@@ -101,6 +101,8 @@ public class GameSceneController implements Initializable {
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         }
+
+
         runtimeInfo.setGameState(GameState.PLAYING);
 
         AnimationTimer gameLoop = new AnimationTimer() {
diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapSelectionController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapSelectionController.java
index d8213343..b167600f 100644
--- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapSelectionController.java
+++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapSelectionController.java
@@ -19,6 +19,9 @@ import java.util.ArrayList;
 import java.util.Objects;
 import java.util.ResourceBundle;
 
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+
 public class MapSelectionController implements Initializable {
     @FXML
     private VBox boxBox, parent;
@@ -31,6 +34,8 @@ public class MapSelectionController implements Initializable {
 
     private final ArrayList<MapData> coreMaps = Persistence.getInstance().getCoreMaps();
 
+    private static Logger log = LogManager.getLogger(MapSelectionController.class);
+
     @Override
     public void initialize(URL url, ResourceBundle resourceBundle) {
         ToggleGroup group = new ToggleGroup();
@@ -60,6 +65,7 @@ public class MapSelectionController implements Initializable {
             MusicPlayerSingleton.getInstance().getMediaPlayer().dispose();
             parent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/GameScene.fxml"))));
         } catch (IOException e) {
+            log.info(e.getCause());
             throw new RuntimeException();
         }
     }
diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/MusicPlayer.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/MusicPlayer.java
index 63896675..8305eac0 100644
--- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/MusicPlayer.java
+++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/MusicPlayer.java
@@ -20,22 +20,20 @@ import java.util.ResourceBundle;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-public class MusicPlayer implements Initializable {
+public class MusicPlayer {
     private static final Logger log = LogManager.getLogger(MusicPlayer.class);
     private MediaPlayer mediaPlayer;
     private RuntimeInfo runtimeInfo;
-    @Override
-    public void initialize(URL url, ResourceBundle resourceBundle) {
-        setVolume(runtimeInfo.getMusicVolume());
-    }
+
+        //Runtime
 
 
-    //Todo Make music play
     public void playGameMusic(MusicType musicType) throws IOException {
         Path pathTypeOfMusic = Paths.get(musicType.getPath());
         List<Path> musicPaths = getFilePathsFromResources(pathTypeOfMusic);
         String randomPath = getRandomFilePath(musicPaths);
         String resource = convertPathToResourcePath(randomPath);
+        setVolume(runtimeInfo.getMusicVolume());
         playMusicLoop(resource);
     }
 
diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SoundEffects.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SoundEffects.java
index cef4794d..7c5e4f56 100644
--- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SoundEffects.java
+++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SoundEffects.java
@@ -18,23 +18,23 @@ import java.nio.file.Paths;
 import java.util.List;
 import java.util.ResourceBundle;
 
-public class SoundEffects implements Initializable {
+public class SoundEffects {
     private static final Logger log = LogManager.getLogger(SoundEffects.class);
     private int sfxVolume;
 
     private RuntimeInfo runtimeInfo;
+    GameSceneController gameSceneController;
+
 
-    @Override
-    public void initialize(URL url, ResourceBundle resourceBundle) {
-        sfxVolume = runtimeInfo.getSfxVolume();
-    }
 
     public void playSoundEffect() throws IOException, InterruptedException {
-        GameSceneController gameSceneController = new GameSceneController();
+
+
         MusicPlayer musicPlayer = new MusicPlayer();
         InputHandler inputhandler = InputHandler.getInstance();
-        TileManager tileManager = gameSceneController.getTileManager();
-        IEntity player = gameSceneController.getPlayer();
+        TileManager tileManager = gameSceneController.getTileManager();// TODO Find out why tileManager is null
+        log.info(tileManager);
+        /*IEntity player = gameSceneController.getPlayer();
         ITile[] tileSet = tileManager.getTileSet();
         int[][] map = tileManager.getTileMap();
         int playerPosX;
@@ -54,6 +54,7 @@ public class SoundEffects implements Initializable {
                 String resource = musicPlayer.convertPathToResourcePath(randomPath);
                 Thread sfxLoop = new Thread(() -> {
                     AudioClip effect = new AudioClip(resource);
+                    effect.setVolume(runtimeInfo.getSfxVolume());
                     effect.setVolume((double) sfxVolume / 100); //TODO Replace with own Method
                     effect.play();
                 });
@@ -63,7 +64,7 @@ public class SoundEffects implements Initializable {
                 sfxPaths.clear();
             }
         }
-
+        */
     }
 
 
-- 
GitLab