예제 #1
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)
     {
         // TODO: this call doesn't nuke the pearls list if we add a NONE type - it should
         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 another");
                 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;
 }
예제 #2
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);
 }
예제 #3
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
         {
             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);
             }
         }
     }
 }
예제 #4
0
        public void initialise()
        {
            if (soundFolderName.Length > 3 && (soundFolderName.Substring(1, 2) == @":\" || soundFolderName.Substring(1, 2) == @":/"))
            {
                soundFilesPath = soundFolderName;
            } else {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    soundFilesPath = Path.Combine(Path.GetDirectoryName(
                                            System.Reflection.Assembly.GetEntryAssembly().Location), @"..\", @"..\", soundFolderName);
                }
                else
                {
                    soundFilesPath = Path.Combine(Path.GetDirectoryName(
                                            System.Reflection.Assembly.GetEntryAssembly().Location), soundFolderName);
                }
            }

            voiceFolderPath = Path.Combine(soundFilesPath, "voice");
            fxFolderPath = Path.Combine(soundFilesPath , "fx");
            backgroundFilesPath = Path.Combine(soundFilesPath, "background_sounds");
            Console.WriteLine("Voice dir full path = " + voiceFolderPath);
            Console.WriteLine("FX dir full path = " + fxFolderPath);
            Console.WriteLine("Background sound dir full path = " + backgroundFilesPath);
            DirectoryInfo soundDirectory = new DirectoryInfo(soundFilesPath);
            if (!soundDirectory.Exists)
            {
                Console.WriteLine("Unable to find sound directory " + soundDirectory.FullName);
                return;
            }
            float soundPackVersion = getSoundPackVersion(soundDirectory);
            if (soundPackVersion == -1 || soundPackVersion == 0)
            {
                Console.WriteLine("Unable to get sound pack version - expected a file called version_info with a single line containing a version number, e.g. 2.0");
            }
            else if (soundPackVersion < minimumSoundPackVersion)
            {
                Console.WriteLine("The sound pack version in use is " + soundPackVersion + " but this version of the app requires version "
                    + minimumSoundPackVersion + " or greater.");
                Console.WriteLine("You must update your sound pack to run this application");
                return;
            }
            else
            {
                Console.WriteLine("Minimum sound pack version = " + minimumSoundPackVersion + " using sound pack version " + soundPackVersion);
            }
            pearlsOfWisdom = new PearlsOfWisdom();
            int soundsCount = 0;
            try
            {
                DirectoryInfo fxSoundDirectory = new DirectoryInfo(fxFolderPath);
                if (!fxSoundDirectory.Exists)
                {
                    Console.WriteLine("Unable to find fx directory " + fxSoundDirectory.FullName);
                    return;
                }
                FileInfo[] bleepFiles = fxSoundDirectory.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);
                        }
                        else if (bleepFile.Name.StartsWith("short"))
                        {
                            enableEndBleep = true;
                            openAndCacheClip("short_bleep", bleepFile.FullName);
                        }
                    }
                }
                DirectoryInfo voiceSoundDirectory = new DirectoryInfo(voiceFolderPath);
                if (!voiceSoundDirectory.Exists)
                {
                    Console.WriteLine("Unable to find voice directory " + voiceSoundDirectory.FullName);
                    return;
                }
                DirectoryInfo[] eventFolders = voiceSoundDirectory.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);
                                        soundsCount++;
                                        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");
                    }
                }
                Console.WriteLine("Cached " + soundsCount + " clips");
                initialised = true;
            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine("Unable to find sounds directory - path: " + soundFolderName);
            }
        }