1 using Microsoft.Xna.Framework.Audio;
3 using System.Collections.Generic;
13 private static readonly IDictionary<SoundType, int> nextSound =
new Dictionary<SoundType, int>();
14 internal static readonly IDictionary<SoundType, IDictionary<string, int>> sounds =
new Dictionary<SoundType, IDictionary<string, int>>();
15 internal static readonly IDictionary<SoundType, IDictionary<int, ModSound>> modSounds =
new Dictionary<SoundType, IDictionary<int, ModSound>>();
16 internal static SoundEffect[] customSounds =
new SoundEffect[0];
17 internal static SoundEffectInstance[] customSoundInstances =
new SoundEffectInstance[0];
21 public const int customSoundType = 50;
22 internal static readonly IDictionary<int, int> musicToItem =
new Dictionary<int, int>();
23 internal static readonly IDictionary<int, int> itemToMusic =
new Dictionary<int, int>();
24 internal static readonly IDictionary<int, IDictionary<int, int>> tileToMusic =
new Dictionary<int, IDictionary<int, int>>();
28 nextSound[type] = GetNumVanilla(type);
29 sounds[type] =
new Dictionary<string, int>();
30 modSounds[type] =
new Dictionary<int, ModSound>();
34 internal static int ReserveSoundID(
SoundType type) {
35 int reserveID = nextSound[type];
41 return nextSound[type];
48 if (sounds[type].ContainsKey(sound)) {
49 return sounds[type][sound];
61 internal static LegacySoundStyle GetLegacySoundSlot(
SoundType type,
string sound) {
62 if (sounds[type].ContainsKey(sound)) {
63 return new LegacySoundStyle((
int)type, sounds[type][sound]);
70 internal static void ResizeAndFillArrays() {
71 customSounds =
new SoundEffect[nextSound[
SoundType.Custom]];
72 customSoundInstances =
new SoundEffectInstance[nextSound[
SoundType.Custom]];
73 Array.Resize(ref Main.soundItem, nextSound[
SoundType.Item]);
74 Array.Resize(ref Main.soundInstanceItem, nextSound[
SoundType.Item]);
75 Array.Resize(ref Main.soundNPCHit, nextSound[
SoundType.NPCHit]);
76 Array.Resize(ref Main.soundInstanceNPCHit, nextSound[
SoundType.NPCHit]);
77 Array.Resize(ref Main.soundNPCKilled, nextSound[
SoundType.NPCKilled]);
78 Array.Resize(ref Main.soundInstanceNPCKilled, nextSound[
SoundType.NPCKilled]);
79 Array.Resize(ref Main.music, nextSound[
SoundType.Music]);
80 Array.Resize(ref Main.musicFade, nextSound[
SoundType.Music]);
82 foreach (
string sound
in sounds[type].Keys) {
83 int slot = GetSoundSlot(type, sound);
86 GetSoundInstanceArray(type)[slot] = GetSoundArray(type)[slot]?.CreateInstance() ?? null;
95 internal static void Unload() {
101 nextSound[type] = GetNumVanilla(type);
102 sounds[type].Clear();
103 modSounds[type].Clear();
111 internal static bool PlayModSound(
int type,
int style,
float volume,
float pan, ref SoundEffectInstance soundEffectInstance) {
123 case customSoundType:
129 if (!modSounds[soundType].ContainsKey(style)) {
132 soundEffectInstance = modSounds[soundType][style].PlaySound(ref GetSoundInstanceArray(soundType)[style], volume, pan, soundType);
136 internal static int GetNumVanilla(
SoundType type) {
141 return Main.maxItemSounds + 1;
143 return Main.maxNPCHitSounds + 1;
145 return Main.maxNPCKilledSounds + 1;
147 return Main.maxMusic;
152 internal static SoundEffect[] GetSoundArray(
SoundType type) {
157 return Main.soundItem;
159 return Main.soundNPCHit;
161 return Main.soundNPCKilled;
166 internal static SoundEffectInstance[] GetSoundInstanceArray(
SoundType type) {
169 return customSoundInstances;
171 return Main.soundInstanceItem;
173 return Main.soundInstanceNPCHit;
175 return Main.soundInstanceNPCKilled;
static int GetSoundSlot(SoundType type, string sound)
Returns the style (last parameter passed to Main.PlaySound) of the sound corresponding to the given S...
static Music GetMusic(string name)
Gets the music with the specified name. The name is in the same format as for texture names...
Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loa...
This class is used to keep track of and support the existence of custom sounds that have been added t...
SoundType
This is an enum of the types of sound you can add to the game. This is used for determining whether a...
static SoundEffect GetSound(string name)
Gets the sound with the specified name. The name is in the same format as for texture names...
static int SoundCount(SoundType type)