forked from cdaragorn/Ui-Info-Suite
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #489 from drewhoener/master
1.6.4 Patch PR
- Loading branch information
Showing
10 changed files
with
105 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.IO; | ||
using Microsoft.Xna.Framework.Audio; | ||
using StardewModdingAPI; | ||
using StardewValley; | ||
|
||
namespace UIInfoSuite2.Infrastructure; | ||
|
||
public enum Sounds | ||
{ | ||
LevelUp | ||
} | ||
|
||
public class SoundHelper | ||
{ | ||
private static readonly Lazy<SoundHelper> _instance = new(() => new SoundHelper()); | ||
|
||
private bool _initialized; | ||
|
||
protected SoundHelper() { } | ||
|
||
public static SoundHelper Instance => _instance.Value; | ||
|
||
public void Initialize(IModHelper helper) | ||
{ | ||
if (_initialized) | ||
{ | ||
throw new InvalidOperationException("Cannot re-initialize sound helper"); | ||
} | ||
|
||
RegisterSound(helper, Sounds.LevelUp, "LevelUp.wav"); | ||
|
||
_initialized = true; | ||
} | ||
|
||
private static string GetQualifiedSoundName(Sounds sound) | ||
{ | ||
return $"UIInfoSuite.sounds.{sound.ToString()}"; | ||
} | ||
|
||
private static void RegisterSound( | ||
IModHelper helper, | ||
Sounds sound, | ||
string fileName, | ||
int instanceLimit = -1, | ||
CueDefinition.LimitBehavior? limitBehavior = null | ||
) | ||
{ | ||
CueDefinition newCueDefinition = new() { name = GetQualifiedSoundName(sound) }; | ||
|
||
if (instanceLimit > 0) | ||
{ | ||
newCueDefinition.instanceLimit = instanceLimit; | ||
newCueDefinition.limitBehavior = limitBehavior ?? CueDefinition.LimitBehavior.ReplaceOldest; | ||
} else if (limitBehavior.HasValue) | ||
{ | ||
newCueDefinition.limitBehavior = limitBehavior.Value; | ||
} | ||
|
||
SoundEffect audio; | ||
string filePath = Path.Combine(helper.DirectoryPath, "assets", fileName); | ||
using (var stream = new FileStream(filePath, FileMode.Open)) | ||
{ | ||
audio = SoundEffect.FromStream(stream); | ||
} | ||
|
||
newCueDefinition.SetSound(audio, Game1.audioEngine.GetCategoryIndex("Sound")); | ||
Game1.soundBank.AddCue(newCueDefinition); | ||
ModEntry.MonitorObject.Log($"Registered Sound: {newCueDefinition.name}"); | ||
} | ||
|
||
public static void Play(Sounds sound) | ||
{ | ||
Game1.playSound(GetQualifiedSoundName(sound)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters