2017-08-22 07:18:21 +08:00
|
|
|
|
using Microsoft.Xna.Framework.Audio;
|
|
|
|
|
using StardewModdingAPI;
|
|
|
|
|
using StardewValley;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace SimpleSoundManager
|
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
class SoundManager
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
2018-06-01 05:38:24 +08:00
|
|
|
|
public Dictionary<string,Sound> sounds;
|
|
|
|
|
public Dictionary<string, XACTMusicPair> musicBanks;
|
2017-08-22 07:18:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// Constructor for this class.
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// </summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
public SoundManager()
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
this.sounds = new Dictionary<string, Sound>();
|
|
|
|
|
this.musicBanks = new Dictionary<string, XACTMusicPair>();
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// Constructor for wav files.
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="soundName"></param>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// <param name="pathToWav"></param>
|
|
|
|
|
public void loadWavFile(string soundName,string pathToWav)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
WavSound wav = new WavSound(pathToWav);
|
|
|
|
|
this.sounds.Add(soundName,wav);
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
2018-06-01 05:38:24 +08:00
|
|
|
|
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// <summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// Constructor for wav files.
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// </summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// <param name="helper"></param>
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// <param name="soundName"></param>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// <param name="pathToWav"></param>
|
|
|
|
|
public void loadWavFile(IModHelper helper,string soundName,string pathToWav)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
WavSound wav = new WavSound(helper ,pathToWav);
|
|
|
|
|
this.sounds.Add(soundName,wav);
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// Constructor for wav files.
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// </summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// <param name="helper"></param>
|
|
|
|
|
/// <param name="songName"></param>
|
|
|
|
|
/// <param name="pathToWav"></param>
|
|
|
|
|
public void loadWavFile(IModHelper helper,string songName,List<string> pathToWav)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
WavSound wav = new WavSound(helper,pathToWav);
|
|
|
|
|
this.sounds.Add(songName,wav);
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// Constructor for XACT files.
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// </summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// <param name="waveBank"></param>
|
|
|
|
|
/// <param name="soundBank"></param>
|
|
|
|
|
/// <param name="songName"></param>
|
|
|
|
|
public void loadXACTFile(WaveBank waveBank, ISoundBank soundBank, string songName)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
XACTSound xactSound = new XACTSound(waveBank, soundBank, songName);
|
|
|
|
|
this.sounds.Add(songName, xactSound);
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// Constructor for XACT files based on already added music packs.
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// </summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// <param name="pairName"></param>
|
|
|
|
|
/// <param name="songName"></param>
|
|
|
|
|
public void loadXACTFile(string pairName, string songName)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
XACTMusicPair musicPair = getMusicPack(pairName);
|
|
|
|
|
if (pairName == null)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
return;
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
2018-06-01 05:38:24 +08:00
|
|
|
|
loadXACTFile(musicPair.waveBank, musicPair.soundBank, songName);
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-01 05:38:24 +08:00
|
|
|
|
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// <summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// Creates a music pack pair that holds .xwb and .xsb music files.
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// </summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// <param name="helper">The mod's helper that will handle the path of the files.</param>
|
|
|
|
|
/// <param name="pairName">The name of this music pack pair.</param>
|
|
|
|
|
/// <param name="wavName">The relative path to the .xwb file</param>
|
|
|
|
|
/// <param name="soundName">The relative path to the .xsb file</param>
|
|
|
|
|
public void loadXACTMusicBank(IModHelper helper,string pairName,string wavName, string soundName)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
this.musicBanks.Add(pairName,new XACTMusicPair(helper, wavName, soundName));
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// Gets the music pack pair from the sound pool.
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// </summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public XACTMusicPair getMusicPack(string name)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
foreach(var pack in this.musicBanks)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
if (name == pack.Key) return pack.Value;
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
2018-06-01 05:38:24 +08:00
|
|
|
|
return null;
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// Gets a clone of the loaded sound.
|
2017-08-22 07:18:21 +08:00
|
|
|
|
/// </summary>
|
2018-06-01 05:38:24 +08:00
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Sound getSoundClone(string name)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
foreach(var sound in this.sounds)
|
2017-08-22 07:18:21 +08:00
|
|
|
|
{
|
2018-06-01 05:38:24 +08:00
|
|
|
|
if (sound.Key == name) return sound.Value.clone();
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
2018-06-01 05:38:24 +08:00
|
|
|
|
return null;
|
2017-08-22 07:18:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|