Skip to content

Commit

Permalink
Experimenting with Music and Sound control system
Browse files Browse the repository at this point in the history
  • Loading branch information
Iteranya committed Nov 15, 2024
1 parent 8977b0d commit a968d6a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ private void processAction(Map<String, Object> action) {
removeSprite((String) action.get("sprite"), this);
return;
case "dialogue":
String sound = (String) action.get("voice");
updateDialogue(
(String) action.get("label"),
(String) action.get("content"),
(String) action.get("voice"),
this);
return;
case "modify_variable":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ public static Map<String, Object> getDictById(long targetId, List<Map<String, Ob
}

public static void updateDialogue(
String label, String content, VisualNovelEngine vn
String label, String content, String sound,VisualNovelEngine vn
) {
vn.state.setLabel(label);
vn.state.setContent(content);
if(sound!=null){
vn.state.setSound(sound);
}
vn.isEngineRunning.set(false);
vn.currentState.incrementAndGet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ public class DialogueScreen extends Screen{
private String command;
private String music;
private String sound;
private SoundUtils se;




public DialogueScreen(VisualNovelEngine vn) throws FileNotFoundException {
super(Component.empty());
this.vn = vn;
this.se = new SoundUtils();

TextureLoader.loadTexturesFromConfig();
//this.player = player;
//dialogueBox = new DialogueBoxComponent();
Expand Down Expand Up @@ -89,20 +92,20 @@ public void update(){
public void playMusic(String music){
if(music!=null){
ResourceLocation musicPath = new ResourceLocation("mobtalkerredux","music."+music);
SoundUtils.playMusic(musicPath);
se.playMusic(musicPath);
System.out.println("Playing: "+music);
}else{
SoundUtils.stopMusic();
se.stopMusic();
}

}
public void playSound(String sound){
if(sound!=null){
ResourceLocation soundPath = new ResourceLocation("mobtalkerredux","sound/"+sound);
SoundUtils.playSound(soundPath);
ResourceLocation soundPath = new ResourceLocation("mobtalkerredux","sound."+sound);
se.playSound(soundPath);
System.out.println("Playing: "+sound);
}else{
SoundUtils.stopSound();
se.stopSound();
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/arsparadox/mobtalkerredux/vn/view/SoundUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

public class SoundUtils {

private static SimpleSoundInstance currentMusic = null;
private static SimpleSoundInstance currentSound = null;
private SimpleSoundInstance currentMusic = null;
private SimpleSoundInstance currentSound = null;

/**
* Plays a sound effect once at full volume
* Stops any currently playing sound effect
* @param sound The ResourceLocation of the sound to play
*/
public static void playSound(ResourceLocation sound) {
public void playSound(ResourceLocation sound) {
if (currentSound != null) {
Minecraft.getInstance().getSoundManager().stop(currentSound);
}
currentSound = SimpleSoundInstance.forUI(
net.minecraft.sounds.SoundEvent.createVariableRangeEvent(sound),
1.0F, // Volume
1.0F // Pitch
1.0F, // Pitch
1.5F // Volume
);
Minecraft.getInstance().getSoundManager().play(currentSound);
}
Expand All @@ -35,7 +35,7 @@ public static void playSound(ResourceLocation sound) {
* @param volume Volume from 0.0 to 1.0
* @param pitch Pitch from 0.5 to 2.0
*/
public static void playSound(ResourceLocation sound, float volume, float pitch) {
public void playSound(ResourceLocation sound, float volume, float pitch) {
if (currentSound != null) {
Minecraft.getInstance().getSoundManager().stop(currentSound);
}
Expand All @@ -52,7 +52,7 @@ public static void playSound(ResourceLocation sound, float volume, float pitch)
* Automatically stops any currently playing music
* @param music The ResourceLocation of the music to play
*/
public static void playMusic(ResourceLocation music) {
public void playMusic(ResourceLocation music) {
stopMusic();
currentMusic = new SimpleSoundInstance(
music,
Expand All @@ -77,7 +77,7 @@ public static void playMusic(ResourceLocation music) {
* @param music The ResourceLocation of the music to play
* @param volume Volume from 0.0 to 1.0
*/
public static void playMusic(ResourceLocation music, float volume) {
public void playMusic(ResourceLocation music, float volume) {
stopMusic();
currentMusic = new SimpleSoundInstance(
music,
Expand All @@ -99,7 +99,7 @@ public static void playMusic(ResourceLocation music, float volume) {
/**
* Stops any currently playing music
*/
public static void stopMusic() {
public void stopMusic() {
if (currentMusic != null) {
Minecraft.getInstance().getSoundManager().stop(currentMusic);
currentMusic = null;
Expand All @@ -109,7 +109,7 @@ public static void stopMusic() {
/**
* Stops any currently playing sound effect
*/
public static void stopSound() {
public void stopSound() {
if (currentSound != null) {
Minecraft.getInstance().getSoundManager().stop(currentSound);
currentSound = null;
Expand Down
35 changes: 0 additions & 35 deletions src/main/resources/assets/mobtalkerredux/sounds.json

This file was deleted.

Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a968d6a

Please sign in to comment.