Ejemplo n.º 1
0
        public SoundManager(IContentManager contentManager)
        {
            // Load the values from file
            var values = AudioManager.LoadValues(_fileName, _rootNodeName);

            // Create the _infos and _soundBuffers arrays large enough to hold all values
            var max = values.Max(x => x.Value);
            _infos = new ISoundInfo[max + 1];
            _soundBuffers = new SoundBuffer[_infos.Length];

            // Populate both collections
            foreach (var value in values)
            {
                var id = new SoundID(value.Value);
                var soundInfo = new SoundInfo(value.Key, id);

                // Ensure no duplicates
                if (_infos[(int)id] != null)
                    throw new DuplicateKeyException(string.Format("Two or more SoundInfos found with the ID `{0}`!", soundInfo.ID));

                if (_infosByName.ContainsKey(soundInfo.Name))
                    throw new DuplicateKeyException(string.Format("Two or more SoundInfos found with the name `{0}`!",
                        soundInfo.Name));

                // Add
                _infosByName.Add(soundInfo.Name, soundInfo);
                _infos[(int)soundInfo.ID] = soundInfo;
                _soundBuffers[(int)soundInfo.ID] = contentManager.LoadSoundBuffer(
                    ContentPaths.SoundsFolder + "/" + soundInfo.Name, ContentLevel.GameScreen);
            }
        }
Ejemplo n.º 2
0
        public SoundManager(IContentManager contentManager)
        {
            // Load the values from file
            var values = AudioManager.LoadValues(_fileName, _rootNodeName);

            // Create the _infos and _soundBuffers arrays large enough to hold all values
            var max = values.Max(x => x.Value);

            _infos        = new ISoundInfo[max + 1];
            _soundBuffers = new SoundBuffer[_infos.Length];

            // Populate both collections
            foreach (var value in values)
            {
                var id        = new SoundID(value.Value);
                var soundInfo = new SoundInfo(value.Key, id);

                // Ensure no duplicates
                if (_infos[(int)id] != null)
                {
                    throw new DuplicateKeyException(string.Format("Two or more SoundInfos found with the ID `{0}`!", soundInfo.ID));
                }

                if (_infosByName.ContainsKey(soundInfo.Name))
                {
                    throw new DuplicateKeyException(string.Format("Two or more SoundInfos found with the name `{0}`!",
                                                                  soundInfo.Name));
                }

                // Add
                _infosByName.Add(soundInfo.Name, soundInfo);
                _infos[(int)soundInfo.ID]        = soundInfo;
                _soundBuffers[(int)soundInfo.ID] = contentManager.LoadSoundBuffer(
                    ContentPaths.SoundsFolder + "/" + soundInfo.Name, ContentLevel.GameScreen);
            }
        }