From 1899c8058fde577318c1911a35108ea8d91cd1a7 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Thu, 17 Mar 2022 20:00:07 -0400 Subject: Adding blip sounds to actual audio tags --- webAO/client.js | 11 ++--------- webAO/client/aoHost.js | 5 +++++ webAO/components/__tests__/blips.test.js | 9 +++++++++ webAO/components/blip.js | 17 +++++++++++++++++ webpack.config.js | 3 ++- 5 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 webAO/client/aoHost.js create mode 100644 webAO/components/__tests__/blips.test.js create mode 100644 webAO/components/blip.js diff --git a/webAO/client.js b/webAO/client.js index 8bac1cc..7e82d91 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -1674,15 +1674,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..409b907 --- /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(3) +export default createBlip \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 5c8b1de..a3456af 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,6 +17,7 @@ module.exports = { client: './webAO/client.js', master: './webAO/master.js', dom: glob.sync('./webAO/dom/*.js'), + components: glob.sync('./webAO/components/*.js'), }, node: { global: true, @@ -86,7 +87,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({ -- cgit From 313d3db36e5252cfa06e9a48ef681385730bb7a4 Mon Sep 17 00:00:00 2001 From: Caleb Mabry <36182383+caleb-mabry@users.noreply.github.com> Date: Wed, 23 Mar 2022 15:27:14 -0400 Subject: Update webAO/components/blip.js Co-authored-by: stonedDiscord --- webAO/components/blip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webAO/components/blip.js b/webAO/components/blip.js index 409b907..eacbeaf 100644 --- a/webAO/components/blip.js +++ b/webAO/components/blip.js @@ -13,5 +13,5 @@ const createBlip = (amountOfBlips) => { document.body.appendChild(audio) } } -createBlip(3) +createBlip(6) export default createBlip \ No newline at end of file -- cgit