aboutsummaryrefslogtreecommitdiff
path: root/webAO/client.js
diff options
context:
space:
mode:
authorsD <stoned@derpymail.org>2020-04-07 18:27:44 +0200
committersD <stoned@derpymail.org>2020-04-07 18:27:44 +0200
commiteab2ace4ae4b558fd6bb224b7c62851cf6b457f3 (patch)
tree154a610b3300989e3e8d894059aec8e8f9cae366 /webAO/client.js
parentc04ddc5a1f054e0b05ce66c0d26ae1653c41fccf (diff)
don't skip the sfx if there was a flash/shake
Diffstat (limited to 'webAO/client.js')
-rw-r--r--webAO/client.js26
1 files changed, 15 insertions, 11 deletions
diff --git a/webAO/client.js b/webAO/client.js
index 1c306c9..b8ffd3c 100644
--- a/webAO/client.js
+++ b/webAO/client.js
@@ -1299,6 +1299,18 @@ class Viewport {
return `${AO_HOST}background/${encodeURI(this.bgname.toLowerCase())}/`;
}
+
+ /**
+ * Play any SFX
+ *
+ * @param {string} sfxname
+ */
+ async playSFX(sfxname) {
+ this.sfxaudio.pause();
+ this.sfxaudio.src = sfxname;
+ this.sfxaudio.play();
+ }
+
/**
* Changes the viewport background based on a given position.
*
@@ -1713,17 +1725,11 @@ async changeBackground(position) {
// Effect stuff
if (this.chatmsg.flash === 2) {
// Shake screen
- this.sfxaudio.pause();
- this.sfxplayed = 1;
- this.sfxaudio.src = AO_HOST + "sounds/general/sfx-stab.wav";
- this.sfxaudio.play();
+ this.playSFX(AO_HOST + "sounds/general/sfx-stab.wav");
document.getElementById("client_gamewindow").style.animation = "shake 0.2s 1";
} else if (this.chatmsg.flash === 1) {
// Flash screen
- this.sfxaudio.pause();
- this.sfxplayed = 1;
- this.sfxaudio.src = AO_HOST + "sounds/general/sfx-realization.wav";
- this.sfxaudio.play();
+ this.playSFX(AO_HOST + "sounds/general/sfx-realization.wav");
document.getElementById("client_fg").style.animation = "flash 0.4s 1";
}
@@ -1838,11 +1844,9 @@ async changeBackground(position) {
}
if (!this.sfxplayed && this.chatmsg.snddelay + this.shoutTimer >= this.textTimer) {
- this.sfxaudio.pause();
this.sfxplayed = 1;
if (this.chatmsg.sound !== "0" && this.chatmsg.sound !== "1" && this.chatmsg.sound !== "" && this.chatmsg.sound !== undefined) {
- this.sfxaudio.src = AO_HOST + "sounds/general/" + encodeURI(this.chatmsg.sound.toLowerCase()) + ".wav";
- this.sfxaudio.play();
+ this.playSFX(AO_HOST + "sounds/general/" + encodeURI(this.chatmsg.sound.toLowerCase()) + ".wav");
}
}
this.textTimer = this.textTimer + UPDATE_INTERVAL;