Skip to content

Commit

Permalink
Remove SoundManager dependency (smogon#1563)
Browse files Browse the repository at this point in the history
All sound stuff is now handled directly by BattleSound, using the
HTML5 audio API.

The main complicated thing we do with sound is loop music with an intro.
This is unfortunately not supported by ANY sound library out there
(I had to manually add support for it myself to soundManager!)

scottschiller/SoundManager2#13

In the end, I don't think the existing libraries out there actually
give us anything I care about.
  • Loading branch information
Zarel authored Jul 23, 2020
1 parent 54cbc51 commit c113549
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 254 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
"BattleTextParser": false,

// Generic global variables
"Config": false, "BattleSearch": false, "soundManager": false, "Storage": false, "Dex": false, "DexSearch": false,
"Config": false, "BattleSearch": false, "Storage": false, "Dex": false, "DexSearch": false,
"app": false, "toID": false, "toRoomid": false, "toUserid": false, "toName": false, "PSUtils": false, "MD5": false,
"ChatHistory": false, "Topbar": false, "UserList": false,

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package-lock.json
/js/battle-choices.js
/js/battle-text-parser.js
/js/battle-dex.js
/js/battle-sound.js
/js/battle-dex-data.js
/js/battle-animations-moves.js
/js/battle-animations.js
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PS loads itself in phases:
- `client-connection.ts`
- Connect to server
- Preact
- SoundManager
- BattleSound
- `panel-mainmenu.tsx`
- `panel-rooms.tsx`
- `panels.tsx`
Expand Down
5 changes: 1 addition & 4 deletions index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ <h3><button class="closebutton" tabindex="-1"><i class="fa fa-times-circle"></i>
<script src="//play.pokemonshowdown.com/js/lib/jquery-2.1.4.min.js"></script>
<script src="//play.pokemonshowdown.com/js/lib/jquery-cookie.js"></script>
<script src="//play.pokemonshowdown.com/js/lib/autoresize.jquery.min.js?"></script>
<script src="//play.pokemonshowdown.com/js/lib/soundmanager2-nodebug-jsmin.js?"></script>
<script>
soundManager.setup({url: '//play.pokemonshowdown.com/swf/'});
</script>
<script src="//play.pokemonshowdown.com/js/battle-sound.js?"></script>
<script src="//play.pokemonshowdown.com/js/lib/html-css-sanitizer-minified.js?"></script>
<script src="//play.pokemonshowdown.com/js/lib/lodash.core.js?"></script>
<script src="//play.pokemonshowdown.com/js/lib/backbone.js?"></script>
Expand Down
16 changes: 4 additions & 12 deletions js/client-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1279,9 +1279,7 @@
if (autoscroll) {
this.$chatFrame.scrollTop(this.$chat.height());
}
if (!app.focused && !Dex.prefs('mute') && Dex.prefs('notifvolume')) {
soundManager.getSoundById('notif').setVolume(Dex.prefs('notifvolume')).play();
}
if (!app.focused) app.playNotificationSound();
},
addRow: function (line) {
var name, name2, silent;
Expand Down Expand Up @@ -1386,19 +1384,15 @@

case 'notify':
if (row[3] && !this.getHighlight(row[3])) return;
if (!Dex.prefs('mute') && Dex.prefs('notifvolume')) {
soundManager.getSoundById('notif').setVolume(Dex.prefs('notifvolume')).play();
}
app.playNotificationSound();
this.notifyOnce(row[1], row[2], 'highlight');
break;

case 'tempnotify':
var notifyOnce = row[4] !== '!';
if (!notifyOnce) row[4] = '';
if (row[4] && !this.getHighlight(row[4])) return;
if (!this.notifications && !Dex.prefs('mute') && Dex.prefs('notifvolume')) {
soundManager.getSoundById('notif').setVolume(Dex.prefs('notifvolume')).play();
}
if (!this.notifications) app.playNotificationSound();
this.notify(row[2], row[3], row[1], notifyOnce);
break;

Expand Down Expand Up @@ -1655,9 +1649,7 @@
}

if (mayNotify && isHighlighted) {
if (!Dex.prefs('mute') && Dex.prefs('notifvolume')) {
soundManager.getSoundById('notif').setVolume(Dex.prefs('notifvolume')).play();
}
app.playNotificationSound();
var $lastMessage = this.$chat.children().last();
var notifyTitle = "Mentioned by " + name + (this.id === 'lobby' ? '' : " in " + this.title);
var notifyText = $lastMessage.html().indexOf('<span class="spoiler">') >= 0 ? '(spoiler)' : $lastMessage.children().last().text();
Expand Down
8 changes: 2 additions & 6 deletions js/client-ladder.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,13 @@
break;

case 'notify':
if (!Dex.prefs('mute') && Dex.prefs('notifvolume')) {
soundManager.getSoundById('notif').setVolume(Dex.prefs('notifvolume')).play();
}
app.playNotificationSound();
this.notifyOnce(row[1], row.slice(2).join('|'), 'highlight');
break;

case 'tempnotify':
var notifyOnce = row[4] !== '!';
if (!this.notifications && !Dex.prefs('mute') && Dex.prefs('notifvolume')) {
soundManager.getSoundById('notif').setVolume(Dex.prefs('notifvolume')).play();
}
if (!this.notifications) app.playNotificationSound();
this.notify(row[2], row[3], row[1], notifyOnce);
break;

Expand Down
6 changes: 6 additions & 0 deletions js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,12 @@ function toId() {
Dex.prefs('autojoin', curAutojoin);
},

playNotificationSound: function () {
if (window.BattleSound && !Dex.prefs('mute')) {
BattleSound.playSound('audio/notification.wav', Dex.prefs('notifvolume'));
}
},

/*********************************************************
* Popups
*********************************************************/
Expand Down
9 changes: 2 additions & 7 deletions js/replay-embed.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ requireScript('https://play.pokemonshowdown.com/config/config.js?a7');
requireScript('https://play.pokemonshowdown.com/js/lib/jquery-1.11.0.min.js');
requireScript('https://play.pokemonshowdown.com/js/lib/lodash.compat.js');
requireScript('https://play.pokemonshowdown.com/js/lib/html-sanitizer-minified.js');
requireScript('https://play.pokemonshowdown.com/js/lib/soundmanager2-nodebug-jsmin.js');
requireScript('https://play.pokemonshowdown.com/js/battle-sound.js');
requireScript('https://play.pokemonshowdown.com/js/battledata.js?a7');
requireScript('https://play.pokemonshowdown.com/data/pokedex-mini.js?a7');
requireScript('https://play.pokemonshowdown.com/data/pokedex-mini-bw.js?a7');
Expand Down Expand Up @@ -67,17 +67,12 @@ var Replays = {
// eslint-disable-next-line no-self-assign
if (rc2) rc2.innerHTML = rc2.innerHTML;

if (window.soundManager && soundManager.ready) this.soundReady();
if (window.HTMLAudioElement) $('.soundchooser, .startsoundchooser').show();
this.reset();
},
"$": function (sel) {
return this.$el.find(sel);
},
soundReady: function () {
if (Replays.isSoundReady) return;
Replays.isSoundReady = true;
$('.soundchooser, .startsoundchooser').show();
},
clickChangeSetting: function (e) {
e.preventDefault();
var $chooser = $(e.currentTarget).closest('.chooser');
Expand Down
2 changes: 1 addition & 1 deletion preactalpha.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h3><button class="closebutton" tabindex="-1" aria-label="Close"><i class="fa fa
<script defer src="/js/battle-log.js?"></script>
<script defer src="/js/panel-chat.js?"></script>

<script defer src="/js/lib/soundmanager2-nodebug-jsmin.js"></script>
<script defer src="/js/battle-sound.js"></script>
<script defer src="/js/lib/jquery-2.1.4.min.js"></script>
<script defer src="/data/graphics.js?"></script>
<script defer src="/data/text.js?"></script>
Expand Down
9 changes: 1 addition & 8 deletions replays/js/replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
} */
//setTimeout(function(){updateProgress(true)}, 10000);

if (window.soundManager) {
soundManager.onready(function(){
soundManager.ready = true;
$('.soundchooser, .startsoundchooser').show();
});
}

// Panels

var Topbar = Panels.Topbar.extend({
Expand Down Expand Up @@ -162,7 +155,7 @@ var ReplayPanel = Panels.StaticPanel.extend({
var rc2 = this.$('.replay-controls-2')[0];
if (rc2) rc2.innerHTML = rc2.innerHTML;

if (window.soundManager && soundManager.ready) this.$('.soundchooser, .startsoundchooser').show();
if (window.HTMLAudioElement) this.$('.soundchooser, .startsoundchooser').show();
},
clickReplayDownloadButton: function (e) {
var filename = (this.battle.tier || 'Battle').replace(/[^A-Za-z0-9]/g, '');
Expand Down
5 changes: 1 addition & 4 deletions replays/theme/wrapper.inc.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ function ThemeFooterTemplate() {

<script src="//play.pokemonshowdown.com/js/lib/jquery-cookie.js"></script>
<script src="//play.pokemonshowdown.com/js/lib/html-sanitizer-minified.js"></script>
<script src="//play.pokemonshowdown.com/js/lib/soundmanager2-nodebug-jsmin.js?"></script>
<script>
soundManager.setup({url: '//play.pokemonshowdown.com/swf/'});
</script>
<script src="//play.pokemonshowdown.com/js/battle-sound.js?"></script>
<script src="//play.pokemonshowdown.com/config/config.js?"></script>
<script src="//play.pokemonshowdown.com/js/battledata.js?"></script>
<script src="//play.pokemonshowdown.com/data/pokedex-mini.js?"></script>
Expand Down
2 changes: 1 addition & 1 deletion replays/warstory.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function update()
<link rel="stylesheet" href="/style/replayer.css" />
<script src="/js/jquery-1.9.1.min.js"></script>
<script src="/js/jquery-cookie.js"></script>
<script src="/js/soundmanager2.js"></script>
<script src="/js/battle-sound.js"></script>
<script src="/js/battledata.js"></script>
<script src="/data/pokedex-mini.js"></script>
<script src="/data/graphics.js"></script>
Expand Down
Loading

0 comments on commit c113549

Please sign in to comment.