diff --git a/src/main/java/cz/jzitnik/game/Game.java b/src/main/java/cz/jzitnik/game/Game.java index c9930f5..3418dd5 100644 --- a/src/main/java/cz/jzitnik/game/Game.java +++ b/src/main/java/cz/jzitnik/game/Game.java @@ -208,8 +208,8 @@ public class Game extends AutoTransientSupport { for (Block block : blocks) { if (block.getClass().isAnnotationPresent(MiningSound.class)) { new Thread(() -> { - gameStates.dependencies.sound.playSound(configuration, - block.getClass().getAnnotation(MiningSound.class).value()); + var anot = block.getClass().getAnnotation(MiningSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); }).start(); } } @@ -223,8 +223,8 @@ public class Game extends AutoTransientSupport { for (Block block : blocks) { if (block.getClass().isAnnotationPresent(MiningSound.class)) { new Thread(() -> { - gameStates.dependencies.sound.playSound(configuration, - block.getClass().getAnnotation(MiningSound.class).value()); + var anot = block.getClass().getAnnotation(MiningSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); }).start(); } } @@ -238,8 +238,8 @@ public class Game extends AutoTransientSupport { for (Block block : blocks) { if (block.getClass().isAnnotationPresent(MiningSound.class)) { new Thread(() -> { - gameStates.dependencies.sound.playSound(configuration, - block.getClass().getAnnotation(MiningSound.class).value()); + var anot = block.getClass().getAnnotation(MiningSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); }).start(); } } @@ -309,10 +309,9 @@ public class Game extends AutoTransientSupport { for (Block block : blocksCopy) { if (block.getClass().isAnnotationPresent(MineSound.class)) { - var key = block.getClass().getAnnotation(MineSound.class).value(); - new Thread(() -> { - gameStates.dependencies.sound.playSound(configuration, key); + var anot = block.getClass().getAnnotation(MiningSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); }).start(); } } @@ -473,9 +472,8 @@ public class Game extends AutoTransientSupport { blocks.removeAll(blocksRemove); for (Block block : blocks) { if (block.getClass().isAnnotationPresent(PlaceSound.class)) { - var key = block.getClass().getAnnotation(PlaceSound.class).value(); - - gameStates.dependencies.sound.playSound(configuration, key); + var anot = block.getClass().getAnnotation(PlaceSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); } } gameStates.dependencies.eventHandlerProvider.handlePlace(screenRenderer, this, x, y); @@ -518,9 +516,8 @@ public class Game extends AutoTransientSupport { for (Block block : blocks) { if (block.getClass().isAnnotationPresent(WalkSound.class)) { - var key = block.getClass().getAnnotation(WalkSound.class).value(); - - gameStates.dependencies.sound.playSound(configuration, key); + var anot = block.getClass().getAnnotation(WalkSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); } } } diff --git a/src/main/java/cz/jzitnik/game/core/sound/Sound.java b/src/main/java/cz/jzitnik/game/core/sound/Sound.java index 5eaa9c2..5db11fe 100644 --- a/src/main/java/cz/jzitnik/game/core/sound/Sound.java +++ b/src/main/java/cz/jzitnik/game/core/sound/Sound.java @@ -1,6 +1,7 @@ package cz.jzitnik.game.core.sound; import java.io.IOException; +import java.lang.annotation.Annotation; import java.util.HashMap; import java.util.Random; import java.util.Set; @@ -37,7 +38,7 @@ public class Sound { } } - public void playSound(Configuration configuration, SoundKey soundKey) { + public void playSound(Configuration configuration, SoundKey soundKey, Class anot) { var volume = configuration.getSoundVolume(); var annotation = map.get(soundKey); @@ -45,17 +46,14 @@ public class Sound { var resources = annotation.resourceLocation(); var resource = resources[random.nextInt(resources.length)]; - var typeVolume = annotation.getClass().isAnnotationPresent(SoundTypeSet.class) - ? annotation.getClass().getAnnotation(SoundTypeSet.class).value().getVolume() + var typeVolume = anot.isAnnotationPresent(SoundTypeSet.class) + ? anot.getAnnotation(SoundTypeSet.class).value().getVolume() : 0; - log.debug("Type volume: {}", typeVolume); - log.debug("Config volume: {}", volume); - new Thread(() -> { try { SoundPlayer.playSound(resource, typeVolume, volume); - } catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) { + } catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) { // TODO Auto-generated catch block e.printStackTrace(); }