Example #1
0
        public int SoundType(string name)
        {
            ModSound sound = GetSound(name);

            if (sound == null)
            {
                return(0);
            }
            return(sound.Type);
        }
Example #2
0
        public void AddSound(string name, ModSound sound, string audioFilename)
        {
            int id = ModSound.ReserveSoundID();

            sound.Name          = name;
            sound.Type          = id;
            sounds[name]        = sound;
            ModSound.sounds[id] = sound;
            sound.audioFilename = audioFilename;
            sound.mod           = this;
        }
Example #3
0
        public void AddSound(SoundType type, string soundPath, ModSound modSound = null)
        {
            int id = SoundLoader.ReserveSoundID(type);

            SoundLoader.sounds[type][soundPath] = id;
            if (modSound != null)
            {
                SoundLoader.modSounds[type][id] = modSound;
                modSound.sound = ModLoader.GetSound(soundPath);
            }
        }
Example #4
0
        private void AutoloadSound(Type type)
        {
            ModSound sound = (ModSound)Activator.CreateInstance(type);

            sound.mod = this;
            string name          = type.Name;
            string audioFilename = (type.Namespace + "." + type.Name).Replace('.', '/');

            if (sound.Autoload(ref name, ref audioFilename))
            {
                AddSound(name, sound, audioFilename);
            }
        }
Example #5
0
 private static void ResizeArrays(bool unloading = false)
 {
     ItemLoader.ResizeArrays();
     EquipLoader.ResizeAndFillArrays();
     Main.InitializeItemAnimations();
     TileLoader.ResizeArrays(unloading);
     WallLoader.ResizeArrays(unloading);
     ProjectileLoader.ResizeArrays();
     NPCLoader.ResizeArrays();
     ModGore.ResizeArrays();
     NPCHeadLoader.ResizeAndFillArrays();
     ModSound.ResizeArrays();
 }
Example #6
0
        /// <summary>
        /// Adds the given sound file to the game as the given type of sound and with the given custom sound playing. If no ModSound instance is provided, the custom sound will play in a similar manner as the default vanilla ones.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="soundPath">The sound path.</param>
        /// <param name="modSound">The mod sound.</param>
        public void AddSound(SoundType type, string soundPath, ModSound modSound = null)
        {
            if (!loading)
            {
                throw new Exception("AddSound can only be called from Mod.Load or Mod.Autoload");
            }

            int id = SoundLoader.ReserveSoundID(type);

            SoundLoader.sounds[type][soundPath] = id;

            if (modSound != null)
            {
                SoundLoader.modSounds[type][id] = modSound;

                modSound.Sound = ModContent.GetSound(soundPath);
            }
        }
        private void AutoloadSounds(IList <Type> modSounds)
        {
            var modSoundNames = modSounds.ToDictionary(t => t.Namespace + "." + t.Name);

            const string SoundFolder = "Sounds/";

            foreach (string soundPath in Assets.EnumeratePaths <SoundEffect>().Where(t => t.StartsWith(SoundFolder)))
            {
                string    substring = soundPath.Substring(SoundFolder.Length);
                SoundType soundType = SoundType.Custom;

                if (substring.StartsWith("Item/"))
                {
                    soundType = SoundType.Item;
                }
                else if (substring.StartsWith("NPCHit/"))
                {
                    soundType = SoundType.NPCHit;
                }
                else if (substring.StartsWith("NPCKilled/"))
                {
                    soundType = SoundType.NPCKilled;
                }

                ModSound modSound = null;

                if (modSoundNames.TryGetValue($"{Name}/{soundPath}".Replace('/', '.'), out Type t))
                {
                    modSound = (ModSound)Activator.CreateInstance(t);
                }

                AddSound(soundType, $"{Name}/{soundPath}", modSound);
            }

            foreach (string music in musics.Keys.Where(t => t.StartsWith("Sounds/")))
            {
                string substring = music.Substring("Sounds/".Length);

                if (substring.StartsWith("Music/"))
                {
                    AddSound(SoundType.Music, Name + '/' + music);
                }
            }
        }
Example #8
0
        private void AutoloadSounds(IList <Type> modSounds)
        {
            IList <string>             sounds        = ModLoader.GetSounds(this);
            string                     soundDir      = Name + "/Sounds/";
            IDictionary <string, Type> modSoundNames = new Dictionary <string, Type>();

            foreach (Type type in modSounds)
            {
                string modSoundName = (type.Namespace + "." + type.Name).Replace('.', '/');
                modSoundNames[modSoundName] = type;
            }
            foreach (string sound in sounds)
            {
                if (sound.IndexOf(soundDir) == 0)
                {
                    string    substring = sound.Substring(soundDir.Length);
                    SoundType soundType = SoundType.Custom;
                    if (substring.IndexOf("Item/") == 0)
                    {
                        soundType = SoundType.Item;
                    }
                    else if (substring.IndexOf("NPCHit/") == 0)
                    {
                        soundType = SoundType.NPCHit;
                    }
                    else if (substring.IndexOf("NPCKilled/") == 0)
                    {
                        soundType = SoundType.NPCKilled;
                    }
                    else if (substring.IndexOf("Music/") == 0)
                    {
                        soundType = SoundType.Music;
                    }
                    string   className = sound.Replace('/', '.');
                    ModSound modSound  = null;
                    if (modSoundNames.ContainsKey(sound))
                    {
                        modSound = (ModSound)Activator.CreateInstance(modSoundNames[sound]);
                    }
                    AddSound(soundType, sound, modSound);
                }
            }
        }
Example #9
0
 internal static void Unload()
 {
     foreach (Mod mod in mods.Values)
     {
         mod.Unload();
     }
     loadedMods.Clear();
     ItemLoader.Unload();
     EquipLoader.Unload();
     TileLoader.Unload();
     WallLoader.Unload();
     ProjectileLoader.Unload();
     NPCLoader.Unload();
     ModGore.Unload();
     NPCHeadLoader.Unload();
     ModSound.Unload();
     textures.Clear();
     sounds.Clear();
     mods.Clear();
     ResizeArrays(true);
 }
Example #10
0
        private void AutoloadSounds(IList <Type> modSounds)
        {
            var modSoundNames = modSounds.ToDictionary(t => t.Namespace + "." + t.Name);

            foreach (var sound in sounds.Keys.Where(t => t.StartsWith("Sounds/")))
            {
                string    substring = sound.Substring("Sounds/".Length);
                SoundType soundType = SoundType.Custom;
                if (substring.StartsWith("Item/"))
                {
                    soundType = SoundType.Item;
                }
                else if (substring.StartsWith("NPCHit/"))
                {
                    soundType = SoundType.NPCHit;
                }
                else if (substring.StartsWith("NPCKilled/"))
                {
                    soundType = SoundType.NPCKilled;
                }
                ModSound modSound = null;
                Type     t;
                if (modSoundNames.TryGetValue((Name + '/' + sound).Replace('/', '.'), out t))
                {
                    modSound = (ModSound)Activator.CreateInstance(t);
                }

                AddSound(soundType, Name + '/' + sound, modSound);
            }
            foreach (var music in musics.Keys.Where(t => t.StartsWith("Sounds/")))
            {
                string substring = music.Substring("Sounds/".Length);
                if (substring.StartsWith("Music/"))
                {
                    AddSound(SoundType.Music, Name + '/' + music);
                }
            }
        }
Example #11
0
 public void AddSound(SoundType type, string soundPath, ModSound modSound = null)
 {
     int id = SoundLoader.ReserveSoundID(type);
     SoundLoader.sounds[type][soundPath] = id;
     if (modSound != null)
     {
         SoundLoader.modSounds[type][id] = modSound;
         modSound.sound = ModLoader.GetSound(soundPath);
     }
 }
Example #12
0
 public void AddSound(string name, ModSound sound, string audioFilename)
 {
     int id = ModSound.ReserveSoundID();
     sound.Name = name;
     sound.Type = id;
     sounds[name] = sound;
     ModSound.sounds[id] = sound;
     sound.audioFilename = audioFilename;
     sound.mod = this;
 }