diff --git a/src/mami.html b/src/mami.html index 43d571c..821e448 100644 --- a/src/mami.html +++ b/src/mami.html @@ -16,8 +16,7 @@
Enable Javascript!
-

{title} is a web based chat and requires Javascript to work.

-

If you use any other privacy tools that prevent loading content from other domains, you may also need to white list static.flash.moe as many resources are loaded from there.

+

{title} is a web based chat application and requires Javascript to work.

diff --git a/src/mami.js/context.js b/src/mami.js/context.js index f1eb06f..53ace67 100644 --- a/src/mami.js/context.js +++ b/src/mami.js/context.js @@ -30,8 +30,8 @@ const MamiContext = function(targetBody) { let soundMgr = null; let sndPckPlay = null; - const soundLib = new MamiSoundLibrary(), - soundPck = new MamiSoundPacks(); + const soundLib = new MamiSoundLibrary(); + const soundPck = new MamiSoundPacks(); pub.initSound = function() { if(soundMgr !== null) @@ -48,35 +48,21 @@ const MamiContext = function(targetBody) { pub.getSoundPacks = function() { return soundPck; }; pub.getSoundPackPlayer = function() { return sndPckPlay; }; - const playSoundBuffer = async (buffer, volume, rate) => { - const source = buffer.createSource(); - if(typeof volume === 'number') - source.setVolume(volume); - if(typeof rate === 'number') - source.setRate(rate); - await source.play(); - }; - - pub.playUrlSound = async (sources, volume, rate) => { - if(soundMgr === null) - return; - - const url = soundMgr.findSupportedUrl(sources); - if(url === null) - return; - - const buffer = await soundMgr.load(`MamiCtx:${url}`, url); - await playSoundBuffer(buffer, volume, rate); - }; - pub.playLibrarySound = async (name, volume, rate) => { if(soundMgr === null) return; const soundInfo = soundLib.getSound(name); - const buffer = await soundMgr.load(soundInfo.getName(), soundInfo.getSources()); - await playSoundBuffer(buffer, volume, rate); + const source = buffer.createSource(); + + if(typeof volume === 'number') + source.setVolume(volume); + + if(typeof rate === 'number') + source.setRate(rate); + + await source.play(); }; const txtTriggers = new MamiTextTriggers; diff --git a/src/mami.js/sockchat_old.js b/src/mami.js/sockchat_old.js index dda6155..9b16f70 100644 --- a/src/mami.js/sockchat_old.js +++ b/src/mami.js/sockchat_old.js @@ -101,34 +101,24 @@ Umi.Protocol.SockChat.Protocol = function(views, settings) { return loading; }; - const playBannedSfx = function() { - if(!mami.hasSound()) - return; - - const urls = { - mp3: '//static.flash.moe/sounds/touhou-death.mp3', - ogg: '//static.flash.moe/sounds/touhou-death.ogg', - }; - - mami.getSound().load('banSFX', urls).then(buffer => buffer.createSource().play()); + const playBannedSfx = async () => { + await mami.playLibrarySound('touhou:pichuun'); }; - const playBannedBgm = function(preload) { + const playBannedBgm = async preload => { if(!mami.hasSound()) return; - const urls = { - opus: '//static.flash.moe/sounds/players-score.opus', - caf: '//static.flash.moe/sounds/players-score.caf' - }; + const soundMgr = mami.getSound(); + const soundLib = mami.getSoundLibrary(); + const soundInfo = soundLib.getSound('touhou:th10score'); - mami.getSound().load('banBGM', urls).then(buffer => { - if(preload) - return; + const buffer = await soundMgr.load(soundInfo.getName(), soundInfo.getSources()); + if(preload) + return; - const source = buffer.createSource(); - source.setLoop(true, 10.512, 38.074); - source.play(); - }); + const source = buffer.createSource(); + source.setLoop(true, 10.512, 38.074); + await source.play(); }; const onOpen = function(ev) { @@ -863,15 +853,14 @@ Umi.Protocol.SockChat.Protocol = function(views, settings) { MamiAnimate({ duration: 550, easing: 'outExpo', - start: function() { + start: () => { playBannedBgm(true); playBannedSfx(); }, - update: function(t) { - const scale = 'scale(' + (1 - .5 * t).toString() + ', ' + (1 - 1 * t).toString() + ')'; - currentView.style.transform = scale; + update: t => { + currentView.style.transform = `scale(${(1 - .5 * t)}, ${(1 - 1 * t)})`; }, - end: function() { + end: () => { getLoadingOverlay(icon, header, message).then(() => { playBannedBgm(); diff --git a/src/mami.js/sound/osukeys.js b/src/mami.js/sound/osukeys.js index e4fb7ad..d9bfd55 100644 --- a/src/mami.js/sound/osukeys.js +++ b/src/mami.js/sound/osukeys.js @@ -1,47 +1,30 @@ #include rng.js const OsuKeys = (() => { - const urlBase = '//static.flash.moe/sounds/'; const rng = new MamiRNG; let sndRng = false; - const playSound = async name => { - if(!mami.hasSound()) - return; - - const soundMgr = mami.getSound(); - - const urls = { - ogg: urlBase + name + '.ogg', - mp3: urlBase + name + '.mp3', - }; - - const buffer = await soundMgr.load('OsuKeys:' + name, urls); - - const source = buffer.createSource(); - if(sndRng) - source.setRate(1.8 - (rng.sample() * 1.5)); - - await source.play(); - }; - const keyHandler = ev => { if(ev.key === 'Control' || ev.key === 'Alt' || ev.key === 'Shift') return; let soundName; if(ev.key === 'Enter' || ev.key === 'NumpadEnter') - soundName = 'key-confirm'; + soundName = 'confirm'; else if(ev.key === 'Backspace' || ev.key === 'Delete') - soundName = 'key-delete'; + soundName = 'delete'; else if(ev.key === 'NumLock' || ev.key === 'CapsLock' || ev.key === 'ScrollLock') - soundName = 'key-caps'; + soundName = 'caps'; else if(ev.key === 'ArrowUp' || ev.key === 'ArrowDown' || ev.key === 'ArrowLeft' || ev.key === 'ArrowRight') - soundName = 'key-movement'; + soundName = 'movement'; else - soundName = `key-press-${rng.next(1, 5)}`; + soundName = `press${rng.next(1, 5)}`; - playSound(soundName); + mami.playLibrarySound( + `osu:key:${soundName}`, + undefined, + sndRng ? (1.8 - (rng.sample() * 1.5)) : undefined + ); }; return { diff --git a/src/mami.js/sound/seinfeld.js b/src/mami.js/sound/seinfeld.js index ffbd56b..ae11ff0 100644 --- a/src/mami.js/sound/seinfeld.js +++ b/src/mami.js/sound/seinfeld.js @@ -1,17 +1,10 @@ #include rng.js const Seinfeld = (function() { - const urlBase = '//static.flash.moe/sounds/seinfeld/', sounds = 22, rng = new MamiRNG; + const sounds = 22; + const rng = new MamiRNG; return { - getRandom: function() { - const name = (rng.next(sounds) + 1).toString(), - url = urlBase + name; - - return { - opus: url + '.opus', - caf: url + '.caf', - }; - }, + getRandom: () => `seinfeld:riff${rng.next(1, sounds + 1)}`, }; })(); diff --git a/src/mami.js/sound/sndmgr.js b/src/mami.js/sound/sndmgr.js index 0b13b47..66d2cdc 100644 --- a/src/mami.js/sound/sndmgr.js +++ b/src/mami.js/sound/sndmgr.js @@ -47,14 +47,6 @@ const MamiSoundManager = function(context) { pub.findSupportedUrl = findSupportedUrl; - pub.loadAnonymous = async urls => { - const url = findSupportedUrl(urls); - if(url === null) - throw 'No supported audio format could be determined.'; - - return await context.createBuffer(url); - }; - pub.load = async (name, urls) => { if(loaded.has(name)) return loaded.get(name); diff --git a/src/mami.js/sound/umisound.js b/src/mami.js/sound/umisound.js index 6b93ef3..e19b82a 100644 --- a/src/mami.js/sound/umisound.js +++ b/src/mami.js/sound/umisound.js @@ -17,7 +17,7 @@ Umi.Sound = (() => { return; if(settings.get('seinfeld')) { - mami.playUrlSound(Seinfeld.getRandom()); + mami.playLibrarySound(Seinfeld.getRandom()); break; }