Esempio n. 1
0
        private void AddToMapping(CSoundFile aSoundFile, FileInfo aFileInfo)
        {
            var at       = typeof(CSoundDirectoryPathAttribute);
            var aEnumTyp = typeof(CSoundDirectoryEnum);
            var aFields  = from aValue in Enum.GetValues(aEnumTyp).Cast <CSoundDirectoryEnum>()
                           select new Tuple <FieldInfo, CSoundDirectoryEnum>(aEnumTyp.GetField(aValue.ToString()), aValue);
            var aAttributes = (from aField in aFields
                               where aField.Item1.IsDefined(at, false)
                               select new Tuple <CSoundDirectoryEnum, CSoundDirectoryPathAttribute>(aField.Item2, aField.Item1.GetCustomAttributes(at, false).OfType <CSoundDirectoryPathAttribute>().Single()));
            var aPath     = TrimBaseDirectory(aFileInfo);
            var aDirEnums = (from aAttrib in aAttributes
                             where aPath.StartsWith(aAttrib.Item2.Path)
                             where aAttrib.Item2.IsLeafDir
                             select aAttrib.Item1).ToArray();
            var aDirEnum  = aDirEnums.Single();
            var aDic      = this.SoundFileDic;
            var aContains = aDic.ContainsKey(aDirEnum);
            var aList     = aContains ? aDic[aDirEnum] : new List <CSoundFile>();

            if (!aContains)
            {
                aDic.Add(aDirEnum, aList);
            }
            aList.Add(aSoundFile);
        }
Esempio n. 2
0
        protected void AddFile(FileInfo aFileInfo)
        {
            var aSoundFile = new CSoundFile(this, aFileInfo);

            this.SoundFiles.Add(aSoundFile);
            if (this.CreateDirectoryDic)
            {
                this.AddToMapping(aSoundFile, aFileInfo);
            }
        }
Esempio n. 3
0
 internal void Add(CSoundFile aSoundFile)
 {
     while (this.CountMax > 0 &&
            this.List.Count >= this.CountMax)
     {
         Debug.Print("CSoundSequence: Remove because of flood.");
         this.List.RemoveAt(0);
     }
     if (this.List.Count < this.CountMax)
     {
         this.List.Add(aSoundFile);
     }
 }
Esempio n. 4
0
 internal void Update()
 {
     if (this.CurrentNullable is object &&
         !this.CurrentNullable.SoundBuffer.IsPlaying)
     {
         //   Debug.Print(DateTime.Now.ToString() + ": CSoundSequence: Sound stopped");
         this.CurrentNullable = default;
     }
     if (this.List.Count > 0 &&
         !(this.CurrentNullable is object))
     {
         // Debug.Print(DateTime.Now.ToString() + ": CSoundSequence: Sound starts.");
         this.CurrentNullable = this.List.First();
         this.CurrentNullable.SoundBuffer.Play();
         this.List.RemoveAt(0);
     }
 }
Esempio n. 5
0
        internal CGemSpeechSoundDirectory(CServiceLocatorNode aParent) : base(aParent)
        {
            this.AddDirectory(CSoundDirectoryEnum.Audio_GemSpeech);
            var aGetGemCategoryEnum = new Func <FileInfo, CGemCategoryEnum>(aFileInfo =>
            { // TODO-Hack
                var aName         = TrimBaseDirectory(aFileInfo).TrimEnd(aFileInfo.Extension).TrimStart(@"Audio\GemSpeech\");
                var aSplit        = aName.Split('_');
                var aCategoryText = aSplit[0];
                var aCategoryEnum = (CGemCategoryEnum)Enum.Parse(typeof(CGemCategoryEnum), aCategoryText);
                return(aCategoryEnum);
            });
            var aGetGemEnum = new Func <FileInfo, CGemEnum>(aFileInfo =>
            {// TODO-Hack
                var aName        = TrimBaseDirectory(aFileInfo).TrimEnd(aFileInfo.Extension).TrimStart(@"Audio\GemSpeech\");
                var aSplit       = aName.Split('_');
                var aGemEnumText = aSplit[1];
                var aGemEnum     = (CGemEnum)Enum.Parse(typeof(CGemEnum), aGemEnumText);
                return(aGemEnum);
            });
            var aSoundFiles1 = this.SoundFiles;
            var aSoundFiles2 = (from aSoundFile in aSoundFiles1
                                select new Tuple <CGemCategoryEnum, CGemEnum, CSoundFile>
                                (
                                    aGetGemCategoryEnum(aSoundFile.FileInfo),
                                    aGetGemEnum(aSoundFile.FileInfo),
                                    aSoundFile
                                )).ToArray();
            var aSoundFilesByGemEnum = new CSoundFile[typeof(CGemEnum).GetEnumMaxValue() + 1];

            foreach (var aSoundFile in aSoundFiles2)
            {
                aSoundFilesByGemEnum[(int)aSoundFile.Item2] = aSoundFile.Item3;
            }
            this.SoundFilesByGemEnum = aSoundFilesByGemEnum;

            this.World.GemCollectedSoundStarting += delegate(CCollectedGemSprite aGemSprite, Action <CSoundFile> aAddFollowUp)
            {
                //var aSound = // (from aTest in aSoundFiles2 where aTest.Item2 == aGemSprite.GemEnum select aTest).Single();
                //aAddFollowUp(aSound.Item3);
            };

            this.SoundSequence = new CSoundSequence(2);

            this.World.GemActivated += delegate(CCollectedGemSprite aGemSprite)
            {
                if (!aGemSprite.ActivateOnCollect)
                {
                    var aGemEnum   = aGemSprite.GemEnum;
                    var aSoundFile = this.GetSoundFile(aGemEnum);
                    if (aSoundFile is object)
                    {
                        this.SoundSequence.Add(aSoundFile);
                    }
                }
                else
                {
                    System.Diagnostics.Debug.Assert(true);
                }
            };

            this.Init();
        }
Esempio n. 6
0
 internal void Play(CSoundFile aSoundFile)
 {
     aSoundFile.SoundBuffer.Volume = this.RandomGenerator.NextFromDoubleRange(this.GetVolumeRange());
     aSoundFile.SoundBuffer.Play();
 }