From f82785a9cb81f7ff18dcd2ab78d37d3be3203645 Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 23 Apr 2024 15:32:28 +0000 Subject: [PATCH] Added buttons to reload sound packs and libraries. --- src/mami.js/sound/sndlibrary.js | 2 - src/mami.js/sound/sndpacks.js | 2 - src/mami.js/ui/settings.jsx | 106 ++++++++++++++++++++------------ 3 files changed, 67 insertions(+), 43 deletions(-) diff --git a/src/mami.js/sound/sndlibrary.js b/src/mami.js/sound/sndlibrary.js index 1ca5cc6..6f34f5b 100644 --- a/src/mami.js/sound/sndlibrary.js +++ b/src/mami.js/sound/sndlibrary.js @@ -32,8 +32,6 @@ const MamiSoundLibrary = function(soundMgr) { throw 'soundInfo must contain a name field'; if(typeof soundInfo.sources !== 'object') throw 'soundInfo must contain a sources field'; - if(sounds.has(soundInfo.name)) - throw 'a sound with that name has already been registered'; let sources = {}, sCount = 0; diff --git a/src/mami.js/sound/sndpacks.js b/src/mami.js/sound/sndpacks.js index 1e22a96..62320dd 100644 --- a/src/mami.js/sound/sndpacks.js +++ b/src/mami.js/sound/sndpacks.js @@ -71,8 +71,6 @@ const MamiSoundPacks = function() { throw 'packInfo must contain a name field'; if(typeof packInfo.events !== 'object') throw 'packInfo must contain a events field'; - if(packs.has(packInfo.name)) - throw 'a pack with that name has already been registered'; const events = new Map; for(const eventName in packInfo.events) { diff --git a/src/mami.js/ui/settings.jsx b/src/mami.js/ui/settings.jsx index c3d89fb..0187ce9 100644 --- a/src/mami.js/ui/settings.jsx +++ b/src/mami.js/ui/settings.jsx @@ -270,49 +270,17 @@ Umi.UI.Settings = (function() { title: 'Messages to keep on clear', type: 'number', }, - { - title: 'Reload emoticons', - type: 'button', - invoke: button => { - const emotes = futami.get('emotes'); - setTimeout(() => { - button.disabled = true; - - futami.getJson('emotes', true) - .then(emotes => { - MamiEmotes.clear(); - MamiEmotes.loadLegacy(emotes); - }) - .finally(() => { - Umi.UI.Emoticons.Init(); - button.disabled = false; - }); - }, 200); - }, - }, - { - title: 'Reload joke triggers', - type: 'button', - invoke: button => { - button.disabled = true; - - const triggers = mami.textTriggers; - triggers.clearTriggers(); - - if(mami.settings.get('playJokeSounds')) - futami.getJson('texttriggers', true) - .then(trigInfos => triggers.addTriggers(trigInfos)) - .finally(() => button.disabled = false); - }, - }, + ], + }, + { + name: 'actions', + title: 'Actions', + items: [ { title: 'Open compatibility client', type: 'button', invoke: () => { - const meow = $e('a', { href: window.AMI_URL, target: '_blank', style: { display: 'none' } }); - document.body.appendChild(meow); - meow.click(); - $r(meow); + window.open(window.AMI_URL, '_blank', 'noopener'); }, }, { @@ -337,6 +305,66 @@ Umi.UI.Settings = (function() { } }, }, + { + title: 'Reload emoticons', + type: 'button', + invoke: async button => { + const textOrig = button.value; + + button.disabled = true; + button.value = 'Reloading emoticons...'; + try { + const emotes = await futami.getJson('emotes', true); + MamiEmotes.clear(); + MamiEmotes.loadLegacy(emotes); + } finally { + Umi.UI.Emoticons.Init(); + button.value = textOrig; + button.disabled = false; + } + }, + }, + { + title: 'Reload sound library', + type: 'button', + invoke: async button => { + const textOrig = button.value; + + button.disabled = true; + button.value = 'Reloading sound library...'; + try { + const sounds = await futami.getJson('sounds2'); + if(Array.isArray(sounds.library)) + mami.sound.library.register(sounds.library, true); + + if(Array.isArray(sounds.packs)) { + mami.sound.packs.register(sounds.packs, true); + mami.settings.touch('soundPack', true); + } + } finally { + button.value = textOrig; + button.disabled = false; + } + }, + }, + { + title: 'Reload joke triggers', + type: 'button', + invoke: async button => { + const textOrig = button.value; + + button.disabled = true; + button.value = 'Reloading joke triggers...'; + try { + const triggers = await futami.getJson('texttriggers', true); + mami.textTriggers.clearTriggers(); + mami.textTriggers.addTriggers(triggers) + } finally { + button.value = textOrig; + button.disabled = false; + } + }, + }, ], }, {