Skip to content

Commit

Permalink
Add wrapper methods to play sounds in Java client
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Jul 24, 2024
1 parent 9174ecc commit ffe1124
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/games/stendhal/client/sound/facade/SoundSystemFacade.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2010 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -16,6 +16,7 @@
import java.util.List;

import games.stendhal.client.listener.PositionChangeListener;
import games.stendhal.common.constants.SoundLayer;

/**
* this class is the interface between the game logic and the
Expand All @@ -41,4 +42,13 @@ public interface SoundSystemFacade extends PositionChangeListener {
public void changeVolume(float volume);

public List<String> getDeviceNames();

public SoundHandle playLocalizedEffect(String name, int x, int y, int radius, SoundLayer layer,
float volume, boolean loop);

public SoundHandle playLocalizedEffect(String name, int x, int y, SoundLayer layer);

public SoundHandle playGlobalizedEffect(String name, SoundLayer layer, float volume, boolean loop);

public SoundHandle playGlobalizedEffect(String name, SoundLayer layer);
}
28 changes: 27 additions & 1 deletion src/games/stendhal/client/sound/nosound/NoSoundFacade.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2010 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -20,6 +20,7 @@
import games.stendhal.client.sound.facade.SoundHandle;
import games.stendhal.client.sound.facade.SoundSystemFacade;
import games.stendhal.client.sound.facade.Time;
import games.stendhal.common.constants.SoundLayer;

public class NoSoundFacade implements SoundSystemFacade {

Expand Down Expand Up @@ -56,6 +57,31 @@ public void mute(boolean turnOffSound, boolean useFading, Time delay) {
// do nothing
}

@Override
public SoundHandle playLocalizedEffect(String name, int x, int y, int radius, SoundLayer layer, float volume,
boolean loop) {
// do nothing
return new NoSoundHandle();
}

@Override
public SoundHandle playLocalizedEffect(String name, int x, int y, SoundLayer layer) {
// do nothing
return new NoSoundHandle();
}

@Override
public SoundHandle playGlobalizedEffect(String name, SoundLayer layer, float volume, boolean loop) {
// do nothing
return new NoSoundHandle();
}

@Override
public SoundHandle playGlobalizedEffect(String name, SoundLayer layer) {
// do nothing
return new NoSoundHandle();
}

@Override
public void stop(SoundHandle sound, Time fadingDuration) {
// do nothing
Expand Down
36 changes: 35 additions & 1 deletion src/games/stendhal/client/sound/sound/SoundSystemFacadeImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2010 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -12,18 +12,25 @@
***************************************************************************/
package games.stendhal.client.sound.sound;

import static games.stendhal.common.Constants.DEFAULT_SOUND_RADIUS;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;

import games.stendhal.client.sound.facade.AudibleArea;
import games.stendhal.client.sound.facade.AudibleCircleArea;
import games.stendhal.client.sound.facade.InfiniteAudibleArea;
import games.stendhal.client.sound.facade.SoundFileType;
import games.stendhal.client.sound.facade.SoundGroup;
import games.stendhal.client.sound.facade.SoundHandle;
import games.stendhal.client.sound.facade.SoundSystemFacade;
import games.stendhal.client.sound.facade.Time;
import games.stendhal.client.sound.manager.DeviceEvaluator.Device;
import games.stendhal.client.sound.manager.SoundManagerNG.Sound;
import games.stendhal.common.constants.SoundLayer;
import games.stendhal.common.math.Algebra;

/**
Expand Down Expand Up @@ -70,6 +77,33 @@ public void update() {
}
}

@Override
public SoundHandle playLocalizedEffect(String name, int x, int y, int radius, SoundLayer layer,
float volume, boolean loop) {
final AudibleArea area = new AudibleCircleArea(Algebra.vecf(x, y), radius / 4.0f, radius);
final SoundGroup group = getGroup(layer.groupName);
group.loadSound(name, name + ".ogg", SoundFileType.OGG, false);
return group.play(name, volume, 0, area, null, loop, true);
}

@Override
public SoundHandle playLocalizedEffect(String name, int x, int y, SoundLayer layer) {
return playLocalizedEffect(name, x, y, DEFAULT_SOUND_RADIUS, layer, 1.0f, false);
}

@Override
public SoundHandle playGlobalizedEffect(String name, SoundLayer layer, float volume, boolean loop) {
final AudibleArea area = new InfiniteAudibleArea();
final SoundGroup group = getGroup(layer.groupName);
group.loadSound(name, name + ".ogg", SoundFileType.OGG, false);
return group.play(name, volume, 0, area, null, loop, true);
}

@Override
public SoundHandle playGlobalizedEffect(String name, SoundLayer layer) {
return playGlobalizedEffect(name, layer, 1.0f, false);
}

@Override
public void stop(SoundHandle sound, Time fadingDuration) {
if (sound != null) {
Expand Down

0 comments on commit ffe1124

Please sign in to comment.