コード例 #1
0
        public int SoundType(string name)
        {
            ModSound sound = GetSound(name);

            if (sound == null)
            {
                return(0);
            }
            return(sound.Type);
        }
コード例 #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;
        }
コード例 #3
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
        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);
            }
        }
コード例 #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);
            }
        }
コード例 #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();
 }
コード例 #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);
            }
        }
コード例 #7
0
        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);
                }
            }
        }
コード例 #8
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
        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);
                }
            }
        }
コード例 #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);
 }
コード例 #10
0
ファイル: ModInternals.cs プロジェクト: re4prr/tModLoader
        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);
                }
            }
        }
コード例 #11
0
ファイル: Mod.cs プロジェクト: popovn/tModLoader
 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);
     }
 }
コード例 #12
0
ファイル: Mod.cs プロジェクト: guyde2011/tModLoader
 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;
 }