Пример #1
0
        public void initialise()
        {
            if (System.Diagnostics.Debugger.IsAttached)
            {
                soundFilesPath = Path.Combine(Path.GetDirectoryName(
                                        System.Reflection.Assembly.GetEntryAssembly().Location), @"..\", @"..\", soundFolderName);
                backgroundFilesPath = Path.Combine(Path.GetDirectoryName(
                                        System.Reflection.Assembly.GetEntryAssembly().Location), @"..\", @"..\", backgroundFolderName);
            }
            else
            {
                soundFilesPath = Path.Combine(Path.GetDirectoryName(
                                        System.Reflection.Assembly.GetEntryAssembly().Location), soundFolderName);
                backgroundFilesPath = Path.Combine(Path.GetDirectoryName(
                                            System.Reflection.Assembly.GetEntryAssembly().Location), backgroundFolderName);
            }
            Console.WriteLine("Sound dir full path = " + soundFilesPath);
            Console.WriteLine("Background sound dir full path = " + backgroundFilesPath);
            pearlsOfWisdom = new PearlsOfWisdom();
            try
            {
                DirectoryInfo soundDirectory = new DirectoryInfo(soundFilesPath);
                Console.WriteLine(soundDirectory);
                FileInfo[] bleepFiles = soundDirectory.GetFiles();
                foreach (FileInfo bleepFile in bleepFiles)
                {
                    if (bleepFile.Name.EndsWith(".wav"))
                    {
                        if (bleepFile.Name.StartsWith("start"))
                        {
                            enableStartBleep = true;
                            openAndCacheClip("start_bleep", bleepFile.FullName);
                        }
                        else if (bleepFile.Name.StartsWith("end"))
                        {
                            enableEndBleep = true;
                            openAndCacheClip("end_bleep", bleepFile.FullName);
                        }
                    }
                }
                DirectoryInfo[] eventFolders = soundDirectory.GetDirectories();
                foreach (DirectoryInfo eventFolder in eventFolders)
                {
                    try {
                        Console.WriteLine("Got event folder " + eventFolder.Name);
                        DirectoryInfo[] eventDetailFolders = eventFolder.GetDirectories();
                        foreach (DirectoryInfo eventDetailFolder in eventDetailFolders)
                        {
                            Console.WriteLine("Got event detail subfolder " + eventDetailFolder.Name);
                            String fullEventName = eventFolder + "/" + eventDetailFolder;
                            try
                            {
                                FileInfo[] soundFiles = eventDetailFolder.GetFiles();
                                foreach (FileInfo soundFile in soundFiles)
                                {
                                    if (soundFile.Name.EndsWith(".wav") && (sweary || !soundFile.Name.StartsWith("sweary")))
                                    {
                                        Console.WriteLine("Got sound file " + soundFile.FullName);
                                        openAndCacheClip(eventFolder + "/" + eventDetailFolder, soundFile.FullName);
                                        if (!enabledSounds.Contains(fullEventName))
                                        {
                                            enabledSounds.Add(fullEventName);
                                        }
                                    }
                                }
                                if (!enabledSounds.Contains(fullEventName))
                                {
                                    Console.WriteLine("Event " + fullEventName + " has no sound files");
                                }
                            }
                            catch (DirectoryNotFoundException e)
                            {
                                Console.WriteLine("Event subfolder " + fullEventName + " not found");
                            }
                        }
                    }
                    catch (DirectoryNotFoundException e)
                    {
                        Console.WriteLine("Unable to find events folder");
                    }
                }

                // spawn a Thread to monitor the queue
                ThreadStart work;
                if (disableImmediateMessages)
                {
                    Console.WriteLine("Interupting and immediate messages are disabled - no spotter or 'green green green'");
                    work = monitorQueueNoImmediateMessages;
                } else
                {
                    work = monitorQueue;
                }
                Thread thread = new Thread(work);
                thread.Start();
                new SmokeTest(this).trigger(new Data.Shared(), new Data.Shared());
            }
            catch (DirectoryNotFoundException e) {
                Console.WriteLine("Unable to find sounds directory - path: " + soundFolderName);
            }
        }
Пример #2
0
 public void queueClip(String eventName, QueuedMessage queuedMessage,  PearlsOfWisdom.PearlType pearlType, double pearlMessageProbability)
 {
     lock (queuedClips)
     {
         if (queuedClips.Contains(eventName))
         {
             Console.WriteLine("Clip for event " + eventName + " is already queued, ignoring");
             return;
         }
         else
         {
             Console.WriteLine("Queuing clip for event " + eventName);
             PearlsOfWisdom.PearlMessagePosition pearlPosition = PearlsOfWisdom.PearlMessagePosition.NONE;
             if (pearlType != PearlsOfWisdom.PearlType.NONE && checkPearlOfWisdomValid(pearlType))
             {
                 pearlPosition = pearlsOfWisdom.getMessagePosition(pearlMessageProbability);
             }
             if (pearlPosition == PearlsOfWisdom.PearlMessagePosition.BEFORE)
             {
                 QueuedMessage pearlQueuedMessage = new QueuedMessage(queuedMessage.abstractEvent);
                 pearlQueuedMessage.dueTime = queuedMessage.dueTime;
                 queuedClips.Add(PearlsOfWisdom.getMessageFolder(pearlType), pearlQueuedMessage);
             }
             queuedClips.Add(eventName, queuedMessage);
             if (pearlPosition == PearlsOfWisdom.PearlMessagePosition.AFTER)
             {
                 QueuedMessage pearlQueuedMessage = new QueuedMessage(queuedMessage.abstractEvent);
                 pearlQueuedMessage.dueTime = queuedMessage.dueTime;
                 queuedClips.Add(PearlsOfWisdom.getMessageFolder(pearlType), pearlQueuedMessage);
             }
         }
     }
 }
Пример #3
0
 // checks that another pearl isn't already queued. If one of the same type is already
 // in the queue this method just returns false. If a conflicting pearl is in the queue
 // this method removes it and returns false, so we don't end up with, for example,
 // a 'keep it up' message in a block that contains a 'your lap times are worsening' message
 private Boolean checkPearlOfWisdomValid(PearlsOfWisdom.PearlType newPearlType)
 {
     Boolean isValid = true;
     if (queuedClips != null && queuedClips.Count > 0)
     {
         List<String> pearlsToPurge = new List<string>();
         foreach (String eventName in queuedClips.Keys)
         {
             if (clipIsPearlOfWisdom(eventName))
             {
                 Console.WriteLine("There's already a pearl in the queue, can't add anothner");
                 isValid = false;
                 if (eventName != PearlsOfWisdom.getMessageFolder(newPearlType))
                 {
                     pearlsToPurge.Add(eventName);
                 }
             }
         }
         foreach (String pearlToPurge in pearlsToPurge)
         {
             queuedClips.Remove(pearlToPurge);
             Console.WriteLine("Queue contains a pearl " + pearlToPurge + " which conflicts with " + newPearlType);
         }
     }
     return isValid;
 }
Пример #4
0
 // we pass in the event which triggered this clip so that we can query the event before playing the
 // clip to check if it's still valid against the latest game state. This is necessary for clips queued
 // with non-zero delays (e.g. you might have crossed the start / finish line between the clip being
 // queued and it being played)
 public void queueClip(String eventName, int secondsDelay, AbstractEvent abstractEvent, 
     PearlsOfWisdom.PearlType pearlType, double pearlMessageProbability)
 {
     queueClip(eventName, new QueuedMessage(secondsDelay, abstractEvent), pearlType, pearlMessageProbability);
 }