From 4a04e4f493980d31012ba19918512ceb2a0e2dda Mon Sep 17 00:00:00 2001 From: stonedDiscord <10584181+stonedDiscord@users.noreply.github.com> Date: Fri, 6 Nov 2020 20:29:49 +0100 Subject: add channels and clientside looping --- webAO/client.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index f91d208..eb27979 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -444,7 +444,7 @@ class Client extends EventEmitter { document.querySelector('#client_chatboxselect [value="' + cookiechatbox + '"]').selected = true; setChatbox(cookiechatbox); - document.getElementById("client_musicaudio").volume = getCookie("musicVolume") || 1; + document.getElementById("client_mvolume").value = getCookie("musicVolume") || 1; changeMusicVolume(); document.getElementById("client_sfxaudio").volume = getCookie("sfxVolume") || 1; changeSFXVolume(); @@ -734,8 +734,11 @@ class Client extends EventEmitter { handleMC(args) { const track = prepChat(args[1]); let charID = Number(args[2]); + const showname = args[3] ? args[3] : ""; + const looping = args[4] ? Boolean(args[4]) : false; + const channel = args[5] ? Number(args[5]) : 0; - const music = viewport.music; + const music = viewport.music[channel]; let musicname; music.pause(); if(track.startsWith("http")) { @@ -743,6 +746,7 @@ class Client extends EventEmitter { } else { music.src = MUSIC_HOST + encodeURI(track.toLowerCase()); } + music.loop = looping; music.play(); try { @@ -1486,8 +1490,9 @@ class Viewport { this.testimonyAudio = document.getElementById("client_testimonyaudio"); this.testimonyAudio.src = `${AO_HOST}sounds/general/sfx-guilty.wav`; - this.music = document.getElementById("client_musicaudio"); - this.music.src = `${AO_HOST}sounds/music/trial (aa).mp3`; + this.music = new Array(3); + this.music.fill(new Audio(`${AO_HOST}sounds/music/trial (aa).mp3`)) + .forEach(channel => channel.volume = 0.5); this.updater = null; this.testimonyUpdater = null; @@ -1513,13 +1518,21 @@ class Viewport { } /** - * Sets the volume of the blip sound. + * Sets the volume of the blip sounds. * @param {number} volume */ set blipVolume(volume) { this.blipChannels.forEach(channel => channel.volume = volume); } + /** + * Sets the volume of the music. + * @param {number} volume + */ + set musicVolume(volume) { + this.music.forEach(channel => channel.volume = volume); + } + /** * Returns the path which the background is located in. */ @@ -2345,7 +2358,8 @@ window.area_click = area_click; * Triggered by the music volume slider. */ export function changeMusicVolume() { - setCookie("musicVolume", document.getElementById("client_musicaudio").volume); + viewport.musicVolume = document.getElementById("client_mvolume").value; + setCookie("musicVolume", document.getElementById("client_mvolume").value); } window.changeMusicVolume = changeMusicVolume; -- cgit