diff --git a/src/mami.js/sound/sndlibrary.js b/src/mami.js/sound/sndlibrary.js index 4398fc9..e90210e 100644 --- a/src/mami.js/sound/sndlibrary.js +++ b/src/mami.js/sound/sndlibrary.js @@ -70,11 +70,8 @@ const MamiSoundLibrary = function(soundMgr) { clear: () => { sounds.clear(); }, - forEach: body => { - if(typeof body !== 'function') - return; - sounds.forEach(body); - }, + info: name => getSound(name), + names: () => Array.from(sounds.keys()), has: name => sounds.has(name), get: getSound, getSources: getSoundSources, diff --git a/src/mami.js/sound/sndpacks.js b/src/mami.js/sound/sndpacks.js index 44c3026..bf9f7a9 100644 --- a/src/mami.js/sound/sndpacks.js +++ b/src/mami.js/sound/sndpacks.js @@ -116,6 +116,12 @@ const MamiSoundPacks = function() { return packInfo; }; + const getPack = name => { + if(!packs.has(name)) + throw 'No pack with this name has been registered.'; + return packs.get(name); + }; + return { register: registerPack, unregister: name => { @@ -124,16 +130,9 @@ const MamiSoundPacks = function() { clear: () => { packs.clear(); }, - forEach: body => { - if(typeof body !== 'function') - return; - packs.forEach(body); - }, + info: name => getPack(name), + names: () => Array.from(packs.keys()), has: name => packs.has(name), - get: name => { - if(!packs.has(name)) - throw 'No pack with this name has been registered.'; - return packs.get(name); - }, + get: getPack, }; }; diff --git a/src/mami.js/ui/domaintrans.jsx b/src/mami.js/ui/domaintrans.jsx index 497b033..c6c371b 100644 --- a/src/mami.js/ui/domaintrans.jsx +++ b/src/mami.js/ui/domaintrans.jsx @@ -57,8 +57,7 @@ const MamiDomainTransition = function(onImport, onDismiss) { const soundLib = mami.getSoundLibrary(); const soundRNG = new MamiRNG(); - const soundNames = []; - soundLib.forEach((info, name) => soundNames.push(name)); + const soundNames = soundLib.names(); const playRandomSound = () => soundLib.play(soundNames[soundRNG.next(soundNames.length)]); diff --git a/src/mami.js/ui/settings.jsx b/src/mami.js/ui/settings.jsx index c63f2c2..68c01b3 100644 --- a/src/mami.js/ui/settings.jsx +++ b/src/mami.js/ui/settings.jsx @@ -138,10 +138,12 @@ Umi.UI.Settings = (function() { title: 'Sound pack', type: 'select', options: () => { + const registry = mami.getSoundPacks(); const packs = {}; - mami.getSoundPacks().forEach(function(pack) { - packs[pack.getName()] = pack.getTitle(); - }); + + for(const name of registry.names()) + packs[name] = registry.info(name).getTitle(); + return packs; }, },