aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/AudioManager.cs61
-rw-r--r--ShiftOS_TheReturn/Commands.cs40
2 files changed, 71 insertions, 30 deletions
diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs
index 553a1d9..0a1a210 100644
--- a/ShiftOS_TheReturn/AudioManager.cs
+++ b/ShiftOS_TheReturn/AudioManager.cs
@@ -83,21 +83,28 @@ namespace ShiftOS.Engine
/// <param name="file">The file to play.</param>
public static void Play(string file)
{
- try
+ bool play = true;
+ float volume = 1f;
+ if (SaveSystem.CurrentSave != null)
{
- _reader = new AudioFileReader(file);
- _out = new WaveOut();
- _out.Init(_reader);
- _out.Play();
- if (SaveSystem.CurrentSave == null)
- _out.Volume = 1.0f;
- else
- _out.Volume = (float)SaveSystem.CurrentSave.MusicVolume / 100;
- _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); };
+ play = (SaveSystem.CurrentSave.SoundEnabled);
+ volume = (float)SaveSystem.CurrentSave.MusicVolume / 100f;
}
- catch(Exception ex)
+ if (play)
{
- Console.WriteLine("Audio error: " + ex.Message);
+ try
+ {
+ _reader = new AudioFileReader(file);
+ _out = new WaveOut();
+ _out.Init(_reader);
+ _out.Volume = volume;
+ _out.Play();
+ _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); };
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Audio error: " + ex.Message);
+ }
}
}
@@ -107,15 +114,27 @@ namespace ShiftOS.Engine
/// <param name="str">The stream to read from.</param>
public static void PlayStream(Stream str)
{
- var bytes = new byte[str.Length];
- str.Read(bytes, 0, bytes.Length);
- ShiftOS.Engine.AudioManager.Stop();
- if (File.Exists("snd.wav"))
- File.Delete("snd.wav");
- File.WriteAllBytes("snd.wav", bytes);
-
- ShiftOS.Engine.AudioManager.Play("snd.wav");
-
+ try
+ {
+ bool play = true;
+ float volume = 1f;
+ if (SaveSystem.CurrentSave != null)
+ {
+ play = (SaveSystem.CurrentSave.SoundEnabled);
+ volume = (float)SaveSystem.CurrentSave.MusicVolume / 100f;
+ }
+ if (play)
+ {
+ ShiftOS.Engine.AudioManager.Stop();
+ _out = new WaveOut();
+ var mp3 = new WaveFileReader(str);
+ _out.Init(mp3);
+ _out.Volume = volume;
+ _out.Play();
+ _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); };
+ }
+ }
+ catch { }
}
public static event Action PlayCompleted;
diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs
index ec89539..e379a50 100644
--- a/ShiftOS_TheReturn/Commands.cs
+++ b/ShiftOS_TheReturn/Commands.cs
@@ -383,26 +383,48 @@ namespace ShiftOS.Engine
[Namespace("sos")]
public static class ShiftOSCommands
{
- [Command("setsfxvolume", description = "Set the volume of various sound effects to a value between 1 and 100.")]
+
+ [Command("setsfxenabled", description = "Set whether or not sound effects are enabled in the system.")]
[RequiresArgument("value")]
- public static bool SetSfxVolume(Dictionary<string, object> args)
+ public static bool SetSfxEnabled(Dictionary<string, object> args)
{
- int value = int.Parse(args["value"].ToString());
- if (value >= 0 && value <= 100)
+ try
{
- SaveSystem.CurrentSave.SfxVolume = value;
+ bool value = Convert.ToBoolean(args["value"].ToString());
+ SaveSystem.CurrentSave.SoundEnabled = value;
SaveSystem.SaveGame();
}
- else
+ catch
{
- Console.WriteLine("Volume must be between 0 and 100!");
+ Console.WriteLine("Error: Value must be either true or false.");
}
return true;
}
- [Command("setmusicvolume", description ="Set the music volume to a value between 1 and 100.")]
+
+
+ [Command("setmusicenabled", description = "Set whether or not music is enabled in the system.")]
[RequiresArgument("value")]
- public static bool SetMusicVolume(Dictionary<string, object> args)
+ public static bool SetMusicEnabled(Dictionary<string, object> args)
+ {
+ try
+ {
+ bool value = Convert.ToBoolean(args["value"].ToString());
+ SaveSystem.CurrentSave.MusicEnabled = value;
+ SaveSystem.SaveGame();
+ }
+ catch
+ {
+ Console.WriteLine("Error: Value must be either true or false.");
+ }
+ return true;
+ }
+
+
+
+ [Command("setsfxvolume", description ="Set the system sound volume to a value between 1 and 100.")]
+ [RequiresArgument("value")]
+ public static bool SetSfxVolume(Dictionary<string, object> args)
{
int value = int.Parse(args["value"].ToString());
if(value >= 0 && value <= 100)