forked from RPTools/maptool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add playSound(soundName) function to MapTool to play local sounds - Currently 3 sounds available: "dink", "clink", and "door" - Sounds only play on client's computer, but this could be easily changed - Add command to play local sounds with playSound(fileName,filePath) - Example: [playSound("music.mp3", "C:/")], assuming there is a music.mp3 in drive C: - Proof of concept that demonstrates how sounds could be implemented - First step to fulfill RPTools#615
- Loading branch information
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/net/rptools/maptool/client/functions/SoundFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* This software Copyright by the RPTools.net development team, and | ||
* licensed under the Affero GPL Version 3 or, at your option, any later | ||
* version. | ||
* | ||
* MapTool Source Code is distributed in the hope that it will be | ||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License * along with this source Code. If not, please visit | ||
* <http://www.gnu.org/licenses/> and specifically the Affero license | ||
* text at <http://www.gnu.org/licenses/agpl.html>. | ||
*/ | ||
package net.rptools.maptool.client.functions; | ||
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.List; | ||
import net.rptools.lib.sound.SoundManager; | ||
import net.rptools.maptool.client.MapTool; | ||
import net.rptools.parser.Parser; | ||
import net.rptools.parser.ParserException; | ||
import net.rptools.parser.function.AbstractFunction; | ||
|
||
public class SoundFunctions extends AbstractFunction { | ||
|
||
/** The singleton instance. */ | ||
private static final SoundFunctions instance = new SoundFunctions(); | ||
|
||
private SoundFunctions() { | ||
super(1, 2, "playSound"); | ||
} | ||
|
||
/** | ||
* Gets the SoundFunctions instance. | ||
* | ||
* @return the instance. | ||
*/ | ||
public static SoundFunctions getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public Object childEvaluate(Parser parser, String functionName, List<Object> args) | ||
throws ParserException { | ||
SoundManager soundManager = MapTool.getSoundManager(); | ||
URL sound; | ||
if (args.size() == 1 || args.get(1).toString().equals("")) { | ||
sound = soundManager.getRegisteredSound(args.get(0).toString()); | ||
} else { | ||
try { | ||
String path = args.get(1).toString() + args.get(0).toString(); | ||
File file = new File(path); | ||
if (!file.exists()) { | ||
throw new ParserException("Can't find file"); | ||
} | ||
sound = file.toURI().toURL(); | ||
} catch (MalformedURLException e) { | ||
throw new ParserException("Wrong URL"); | ||
} | ||
} | ||
if (sound == null) { | ||
return 0; | ||
} else { | ||
soundManager.playSound(sound); | ||
return 1; | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters