aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--webAO/client.js11
-rw-r--r--webAO/client/aoHost.js5
-rw-r--r--webAO/components/__tests__/blips.test.js9
-rw-r--r--webAO/components/blip.js17
-rw-r--r--webpack.config.js3
5 files changed, 35 insertions, 10 deletions
diff --git a/webAO/client.js b/webAO/client.js
index 14bfd08..bf274db 100644
--- a/webAO/client.js
+++ b/webAO/client.js
@@ -1672,15 +1672,8 @@ class Viewport {
];
// Allocate multiple blip audio channels to make blips less jittery
-
- this.blipChannels = new Array(
- new Audio(`${AO_HOST}sounds/general/sfx-blipmale.opus`),
- new Audio(`${AO_HOST}sounds/general/sfx-blipmale.opus`),
- new Audio(`${AO_HOST}sounds/general/sfx-blipmale.opus`),
- new Audio(`${AO_HOST}sounds/general/sfx-blipmale.opus`),
- new Audio(`${AO_HOST}sounds/general/sfx-blipmale.opus`),
- new Audio(`${AO_HOST}sounds/general/sfx-blipmale.opus`),
- );
+ const blipSelectors = document.getElementsByClassName('blipSound')
+ this.blipChannels = [...blipSelectors];
this.blipChannels.forEach((channel) => channel.volume = 0.5);
this.blipChannels.forEach((channel) => channel.onerror = opusCheck(channel));
this.currentBlipChannel = 0;
diff --git a/webAO/client/aoHost.js b/webAO/client/aoHost.js
new file mode 100644
index 0000000..b387608
--- /dev/null
+++ b/webAO/client/aoHost.js
@@ -0,0 +1,5 @@
+import queryParser from '../utils/queryParser'
+let { asset } = queryParser();
+const DEFAULT_HOST = 'http://attorneyoffline.de/base/';
+const AO_HOST = asset || DEFAULT_HOST
+export default AO_HOST
diff --git a/webAO/components/__tests__/blips.test.js b/webAO/components/__tests__/blips.test.js
new file mode 100644
index 0000000..9c57e78
--- /dev/null
+++ b/webAO/components/__tests__/blips.test.js
@@ -0,0 +1,9 @@
+import createBlip from "../blip";
+
+describe('createBlip', () => {
+ test('create 3 blips audios', () => {
+ document.body.innerHTML = ``
+ createBlip(3)
+ expect(document.getElementsByClassName('blipSound').length).toBe(3)
+ })
+}) \ No newline at end of file
diff --git a/webAO/components/blip.js b/webAO/components/blip.js
new file mode 100644
index 0000000..eacbeaf
--- /dev/null
+++ b/webAO/components/blip.js
@@ -0,0 +1,17 @@
+import AO_HOST from '../client/aoHost'
+
+/**
+ *
+ * @param {number} amountOfBlips Amount of Blips to put on page
+ */
+const createBlip = (amountOfBlips) => {
+ for (let i = 0; i < amountOfBlips; i++) {
+ const audio = document.createElement('audio')
+ const blipUrl = `${AO_HOST}sounds/general/sfx-blipmale.opus`
+ audio.setAttribute('class', 'blipSound')
+ audio.setAttribute('src', blipUrl)
+ document.body.appendChild(audio)
+ }
+}
+createBlip(6)
+export default createBlip \ No newline at end of file
diff --git a/webpack.config.js b/webpack.config.js
index 68546c3..edfe0a4 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -17,6 +17,7 @@ module.exports = {
client: './webAO/client.js',
master: './webAO/master.ts',
dom: glob.sync('./webAO/dom/*.js'),
+ components: glob.sync('./webAO/components/*.js'),
},
node: {
global: true,
@@ -92,7 +93,7 @@ module.exports = {
new HtmlWebpackPlugin({
title: 'Attorney Online',
filename: 'client.html',
- chunks: ['client', 'ui', 'dom'],
+ chunks: ['client', 'ui', 'dom', 'components'],
template: 'public/client.html',
}),
new webpack.DefinePlugin({