Esempio n. 1
0
        public void Can_convert_max_TimeSpan()
        {
            var dto = new TimeSpanWrapper {
                TimeSpan = TimeSpan.MaxValue,
            };
            var json     = JsonSerializer.SerializeToString(dto, typeof(TimeSpanWrapper));
            var fromJson = JsonSerializer.DeserializeFromString <TimeSpanWrapper>(json);

            Assert.That(fromJson.TimeSpan, Is.EqualTo(dto.TimeSpan));
        }
Esempio n. 2
0
 public static MessageFragment Time(TimeSpanWrapper timeSpan)
 {
     return(new MessageFragment(timeSpan));
 }
Esempio n. 3
0
 private MessageFragment(TimeSpanWrapper timeSpan)
 {
     this.timeSpan = timeSpan;
     this.type     = FragmentType.Time;
 }
Esempio n. 4
0
        public bool soundTestPlay(String[] foldersOrStuff, int messageNumber = 1)
        {
            List <String>          rawDriverNames = new List <string>();
            List <MessageFragment> fragments      = new List <MessageFragment>();

            if (foldersOrStuff.Length > 0 && File.Exists(foldersOrStuff[0]))
            {
                foldersOrStuff = File.ReadAllLines(foldersOrStuff[0]);
            }
            int    iter        = 0;
            String messageName = "";

            foreach (String stuffToPlay in foldersOrStuff)
            {
                messageName = "sound_test_message_" + messageNumber.ToString();
                iter++;
                int  num;
                bool isNumeric = int.TryParse(stuffToPlay, out num);
                if (stuffToPlay.StartsWith("#") || stuffToPlay.Length < 1)
                {
                    continue;
                }
                if (stuffToPlay.StartsWith("&"))
                {
                    String [] nextNessage = new String [foldersOrStuff.Length - iter];
                    Array.Copy(foldersOrStuff, iter, nextNessage, 0, foldersOrStuff.Length - iter);
                    audioPlayer.playMessageImmediately(new QueuedMessage(messageName, 0, messageFragments: fragments, abstractEvent: this,
                                                                         type: SoundType.IMPORTANT_MESSAGE, priority: 0));
                    messageNumber++;
                    return(soundTestPlay(nextNessage, messageNumber));
                }

                if (isNumeric)
                {
                    fragments.Add(MessageFragment.Integer(num));
                }
                else if (stuffToPlay.ToLower().StartsWith("pause"))
                {
                    String pauseLength = stuffToPlay.Substring(6);
                    isNumeric = int.TryParse(pauseLength, out num);
                    if (isNumeric)
                    {
                        fragments.Add(MessageFragment.Text(Pause(num)));
                    }
                }
                else if (stuffToPlay.ToLower().StartsWith("name"))
                {
                    String nameToMake = stuffToPlay.Substring(5);
                    fragments.Add(MessageFragment.Opponent(makeTempDriver(nameToMake, rawDriverNames)));
                }
                else if (stuffToPlay.ToLower().StartsWith("time"))
                {
                    float     time       = 0;
                    String    timeToMake = "";
                    Precision precision  = Precision.AUTO_LAPTIMES;
                    timeToMake = stuffToPlay.Substring(9);
                    isNumeric  = float.TryParse(timeToMake, out time);
                    if (isNumeric)
                    {
                        if (stuffToPlay.ToLower().Contains("lap"))
                        {
                            precision = Precision.AUTO_LAPTIMES;
                        }
                        else if (stuffToPlay.ToLower().Contains("gap"))
                        {
                            precision = Precision.AUTO_GAPS;
                        }
                        else if (stuffToPlay.ToLower().Contains("hun"))
                        {
                            precision = Precision.HUNDREDTHS;
                        }
                        else if (stuffToPlay.ToLower().Contains("sec"))
                        {
                            precision = Precision.SECONDS;
                        }
                        else if (stuffToPlay.ToLower().Contains("ten"))
                        {
                            precision = Precision.TENTHS;
                        }
                        fragments.Add(MessageFragment.Time(TimeSpanWrapper.FromSeconds(time, precision)));
                    }
                }
                else
                {
                    fragments.Add(MessageFragment.Text(stuffToPlay));
                }
            }
            audioPlayer.playMessageImmediately(new QueuedMessage(messageName, 0, messageFragments: fragments, abstractEvent: this,
                                                                 type: SoundType.IMPORTANT_MESSAGE, priority: 0));
            return(true);
        }
Esempio n. 5
0
 public override void respond(string voiceMessage)
 {
     if (sessionLengthIsTime)
     {
         if (leaderHasFinishedRace)
         {
             Console.WriteLine("Playing last lap message, timeleft = " + timeLeft);
             audioPlayer.playMessageImmediately(new QueuedMessage(folderThisIsTheLastLap, 0));
         }
         if (timeLeft >= 120)
         {
             int minutesLeft = (int)Math.Round(timeLeft / 60f);
             audioPlayer.playMessageImmediately(new QueuedMessage("RaceTime/time_remaining", 0,
                                                                  messageFragments: MessageContents(TimeSpanWrapper.FromMinutes(minutesLeft, Precision.MINUTES), folderRemaining)));
         }
         else if (timeLeft >= 60)
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(folderOneMinuteRemaining, 0));
         }
         else if (timeLeft <= 0)
         {
             if (addExtraLap && !startedExtraLap)
             {
                 Console.WriteLine("Playing extra lap one more lap message, timeleft = " + timeLeft);
                 audioPlayer.playMessageImmediately(new QueuedMessage(folderOneLapAfterThisOne, 0));
             }
             else
             {
                 Console.WriteLine("Playing last lap message, timeleft = " + timeLeft);
                 audioPlayer.playMessageImmediately(new QueuedMessage(folderThisIsTheLastLap, 0));
             }
         }
         else if (timeLeft < 60)
         {
             Console.WriteLine("Playing less than a minute message, timeleft = " + timeLeft);
             audioPlayer.playMessageImmediately(new QueuedMessage(folderLessThanOneMinute, 0));
         }
     }
     else
     {
         if (lapsLeft > 2)
         {
             audioPlayer.playMessageImmediately(new QueuedMessage("RaceTime/laps_remaining", 0,
                                                                  messageFragments: MessageContents(lapsLeft, folderLapsLeft)));
         }
         else if (lapsLeft == 2)
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(folderOneLapAfterThisOne, 0));
         }
         else if (lapsLeft == 1)
         {
             audioPlayer.playMessageImmediately(new QueuedMessage(folderThisIsTheLastLap, 0));
         }
     }
 }
Esempio n. 6
0
        /**
         * Convert a timeSpan to some sound files, using the current language's implementation.
         */
        public List <String> ConvertTimeToSounds(TimeSpanWrapper timeSpanWrapper, Boolean useMoreInflection)
        {
            // Console.WriteLine(new DateTime(timeSpan.Ticks).ToString("HH:mm:ss.F"));
            List <String> messageFolders = new List <String>();

            if (timeSpanWrapper != null)
            {
                Precision precision = timeSpanWrapper.getPrecision();
                // Rounding hacks. Because we treat the tenths or hundredths as separate numbers, they may get
                // rounded - .950 will be rounded to 'point 10' and .995 will be rounded to 'point 100', so we
                // move the time on a bit to ensure this doesn't happen:
                if (precision == Precision.HUNDREDTHS && timeSpanWrapper.timeSpan.Milliseconds > 995)
                {
                    timeSpanWrapper.timeSpan = timeSpanWrapper.timeSpan.Add(TimeSpan.FromMilliseconds(1000 - timeSpanWrapper.timeSpan.Milliseconds));
                }
                else if (timeSpanWrapper.timeSpan.Milliseconds > 949)
                {
                    // move the time on even if we're not asking for TENTHS in our precision argument
                    timeSpanWrapper.timeSpan = timeSpanWrapper.timeSpan.Add(TimeSpan.FromMilliseconds(1000 - timeSpanWrapper.timeSpan.Milliseconds));
                }
                // so now these tenths and hundredths can never be 10 or 100 respectively:
                int tenths     = (int)Math.Round((float)timeSpanWrapper.timeSpan.Milliseconds / 100f);
                int hundredths = (int)Math.Round((float)timeSpanWrapper.timeSpan.Milliseconds / 10f);

                // now call the language-specific implementations
                Boolean useNewENMinutes = SoundPackVersionsHelper.currentSoundPackVersion > 106 && getLocale() == "en" && timeSpanWrapper.timeSpan.Hours == 0 &&
                                          timeSpanWrapper.timeSpan.Minutes > 0 && timeSpanWrapper.timeSpan.Minutes < 3 && timeSpanWrapper.timeSpan.Seconds > 0 && timeSpanWrapper.timeSpan.Seconds < 60;

                Boolean useNewENSeconds = precision != Precision.MINUTES &&
                                          SoundPackVersionsHelper.currentSoundPackVersion > 106 && getLocale() == "en" && timeSpanWrapper.timeSpan.Hours == 0 &&
                                          timeSpanWrapper.timeSpan.Minutes == 0 && (timeSpanWrapper.timeSpan.Seconds > 0 || tenths > 0 ||
                                                                                    (precision == Precision.HUNDREDTHS && hundredths > 0)) && timeSpanWrapper.timeSpan.Seconds < 60;

                Boolean useItalianShortForm = precision != Precision.MINUTES && precision != Precision.SECONDS && !timeSpanWrapper.precisionIsAutoGaps &&
                                              SoundPackVersionsHelper.currentSoundPackVersion > 150 && getLocale() == "it" &&
                                              timeSpanWrapper.timeSpan.Hours == 0 &&
                                              (timeSpanWrapper.timeSpan.Seconds > 0 && (timeSpanWrapper.timeSpan.Minutes > 0 || tenths > 0 || hundredths > 0)); // more checks on numbers?

                if (useNewENSeconds)
                {
                    messageFolders.Add(AbstractEvent.Pause(50));
                    if (precision == Precision.HUNDREDTHS)
                    {
                        messageFolders.AddRange(GetSecondsWithHundredths(timeSpanWrapper.timeSpan.Seconds, hundredths));
                    }
                    else if (precision == Precision.TENTHS)
                    {
                        messageFolders.Add(GetSecondsWithTenths(timeSpanWrapper.timeSpan.Seconds, tenths));
                    }
                    else if (precision == Precision.SECONDS)
                    {
                        messageFolders.AddRange(GetSeconds(timeSpanWrapper.timeSpan.Seconds));
                    }
                }
                else if (useNewENMinutes || useItalianShortForm)
                {
                    messageFolders.Add(AbstractEvent.Pause(50));
                    if (precision == Precision.HUNDREDTHS)
                    {
                        String leadingZero = hundredths < 10 ? "0" : "";
                        messageFolders.AddRange(GetMinutesAndSecondsWithFraction(timeSpanWrapper.timeSpan.Minutes, timeSpanWrapper.timeSpan.Seconds, leadingZero + hundredths, useMoreInflection));
                    }
                    else if (precision == Precision.TENTHS)
                    {
                        messageFolders.AddRange(GetMinutesAndSecondsWithFraction(timeSpanWrapper.timeSpan.Minutes, timeSpanWrapper.timeSpan.Seconds, tenths.ToString(), useMoreInflection));
                    }
                    else if (precision == Precision.SECONDS || precision == Precision.MINUTES)
                    {
                        messageFolders.AddRange(GetMinutesSounds(timeSpanWrapper.timeSpan.Hours, timeSpanWrapper.timeSpan.Minutes, timeSpanWrapper.timeSpan.Seconds, tenths, useMoreInflection, precision));
                        messageFolders.AddRange(GetSecondsSounds(timeSpanWrapper.timeSpan.Hours, timeSpanWrapper.timeSpan.Minutes, timeSpanWrapper.timeSpan.Seconds, tenths, useMoreInflection, precision));
                    }
                }
                else
                {
                    messageFolders.AddRange(GetHoursSounds(timeSpanWrapper.timeSpan.Hours, timeSpanWrapper.timeSpan.Minutes, timeSpanWrapper.timeSpan.Seconds, tenths, useMoreInflection, precision));
                    messageFolders.AddRange(GetMinutesSounds(timeSpanWrapper.timeSpan.Hours, timeSpanWrapper.timeSpan.Minutes, timeSpanWrapper.timeSpan.Seconds, tenths, useMoreInflection, precision));
                    messageFolders.AddRange(GetSecondsSounds(timeSpanWrapper.timeSpan.Hours, timeSpanWrapper.timeSpan.Minutes, timeSpanWrapper.timeSpan.Seconds, tenths, useMoreInflection, precision));
                    messageFolders.AddRange(GetTenthsSounds(timeSpanWrapper.timeSpan.Hours, timeSpanWrapper.timeSpan.Minutes, timeSpanWrapper.timeSpan.Seconds, tenths, useMoreInflection, precision));
                }

                if (getLocale() == "it" && messageFolders.Count > 0)
                {
                    Console.WriteLine(String.Join(", ", messageFolders));
                }
            }
            return(messageFolders);
        }