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.Framework
{
public class XACTSound : Sound
{
public WaveBank waveBank;
public ISoundBank soundBank;
public string soundName;
WaveBank vanillaWaveBank;
ISoundBank vanillaSoundBank;
Cue song;
///
/// Make a new Sound Manager to play and manage sounds in a modded wave bank.
///
/// The reference to the wave bank in the mod's asset folder.
/// The reference to the sound bank in the mod's asset folder.
public XACTSound(WaveBank newWaveBank, ISoundBank newSoundBank,string soundName)
{
this.waveBank = newWaveBank;
this.soundBank = newSoundBank;
vanillaSoundBank = Game1.soundBank;
vanillaWaveBank = Game1.waveBank;
this.soundName = soundName;
song = this.soundBank.GetCue(this.soundName);
}
///
/// Play a sound from the mod's wave bank.
///
/// The name of the sound in the mod's wave bank. This will fail if the sound doesn't exists. This is also case sensitive.
public void play(string soundName)
{
Game1.waveBank = this.waveBank;
Game1.soundBank = this.soundBank;
if (this.song == null) return;
this.song.Play();
Game1.waveBank = this.vanillaWaveBank;
Game1.soundBank = this.vanillaSoundBank;
}
///
/// Pauses the first instance of this sound.
///
///
public void pause(string soundName)
{
if (this.song == null) return;
this.song.Pause();
}
///
/// Resume the first instance of the sound that has this name.
///
public void resume(string soundName)
{
if (this.song == null) return;
this.song.Resume();
}
///
/// Stop the first instance of the sound that has this name.
///
///
public void stop(string soundName)
{
if (this.song == null) return;
this.song.Stop(AudioStopOptions.Immediate);
}
///
/// Resumes a paused song.
///
public void resume()
{
this.resume(soundName);
}
///
/// Plays this song.
///
public void play()
{
this.play(this.soundName);
}
///
/// Plays this song.
///
public void play(float volume)
{
this.play(this.soundName);
}
///
/// Pauses this song.
///
public void pause()
{
this.pause(this.soundName);
}
///
/// Stops this somg.
///
public void stop()
{
this.stop(this.soundName);
}
///
/// Restarts this song.
///
public void restart()
{
this.stop();
this.play();
}
///
/// Gets a clone of this song.
///
///
public Sound clone()
{
return new XACTSound(this.waveBank, this.soundBank, this.soundName);
}
public string getSoundName()
{
return this.soundName;
}
public bool isStopped()
{
if (this.song == null) return true;
if (this.song.IsStopped) return true;
return false;
}
}
}