private string splitComponent(ISegment segment, string comparison, TimingMethod method)
        {
            TimeSpan?deltaTime = null;
            Color?   color     = null;
            var      i         = State.Run.IndexOf(segment);
            int      delta     = 9;
            int      time      = 9;
            int      split     = Settings.CharacterWidth - delta - time - 2;
            var      segName   = (segment.Name.Length > split) ? segment.Name.Substring(0, split) : segment.Name;

            if (i < State.CurrentSplitIndex)
            {
                deltaTime = segment.SplitTime[method] - segment.Comparisons[comparison][method];
                color     = LiveSplitStateHelper.GetSplitColor(State, deltaTime, i, true, true, comparison, method);
            }
            else
            {
                //Live Delta
                var bestDelta = LiveSplitStateHelper.CheckLiveDelta(State, true, comparison, method);
                if (bestDelta != null && segment == State.CurrentSplit)
                {
                    deltaTime = bestDelta;
                    color     = State.LayoutSettings.TextColor;
                }
            }

            DeltaFormatter.DropDecimals = Settings.DropDecimals;
            DeltaFormatter.Accuracy     = Settings.DeltasAccuracy;
            SplitTimeFormatter.Accuracy = Settings.SplitAccuracy;

            var splitTime = segment.SplitTime[method];

            if (splitTime == null && State.CurrentSplitIndex <= i)
            {
                splitTime = segment.Comparisons[comparison][method];
            }

            return(String.Format("{0}{1, " + -split + "}<C> {2}{3, " + delta + "}<C> {4, " + time + "}\n",
                                 (State.CurrentSplit == segment) ? "<C8>" : "",
                                 segName,
                                 getColor(color),
                                 DeltaFormatter.Format(deltaTime),
                                 SplitTimeFormatter.Format(splitTime)
                                 ));
        }
Ejemplo n.º 2
0
 private void ProcessMessage(String message, Connection clientConnection)
 {
     try
     {
         if (message == "startorsplit")
         {
             if (State.CurrentPhase == TimerPhase.Running)
             {
                 Model.Split();
             }
             else
             {
                 Model.Start();
             }
         }
         else if (message == "split")
         {
             Model.Split();
         }
         else if (message == "unsplit")
         {
             Model.UndoSplit();
         }
         else if (message == "skipsplit")
         {
             Model.SkipSplit();
         }
         else if (message == "pause" && State.CurrentPhase != TimerPhase.Paused)
         {
             Model.Pause();
         }
         else if (message == "resume" && State.CurrentPhase == TimerPhase.Paused)
         {
             Model.Pause();
         }
         else if (message == "reset")
         {
             Model.Reset();
         }
         else if (message == "starttimer")
         {
             Model.Start();
         }
         else if (message.StartsWith("setgametime "))
         {
             var value = message.Split(' ')[1];
             var time  = parseTime(value);
             State.SetGameTime(time);
         }
         else if (message.StartsWith("setloadingtimes "))
         {
             var value = message.Split(' ')[1];
             var time  = parseTime(value);
             State.LoadingTimes = time ?? TimeSpan.Zero;
         }
         else if (message == "pausegametime")
         {
             State.IsGameTimePaused = true;
         }
         else if (message == "unpausegametime")
         {
             AlwaysPauseGameTime    = false;
             State.IsGameTimePaused = false;
         }
         else if (message == "alwayspausegametime")
         {
             AlwaysPauseGameTime    = true;
             State.IsGameTimePaused = true;
         }
         else if (message == "getdelta" || message.StartsWith("getdelta "))
         {
             var comparison = State.CurrentComparison;
             if (message.Contains(" "))
             {
                 comparison = message.Split(new char[] { ' ' }, 2)[1];
             }
             var delta    = LiveSplitStateHelper.GetLastDelta(State, State.CurrentSplitIndex, comparison, State.CurrentTimingMethod);
             var response = DeltaFormatter.Format(delta);
             clientConnection.SendMessage(response);
         }
         else if (message == "getsplitindex")
         {
             var splitindex = State.CurrentSplitIndex;
             var response   = splitindex.ToString();
             clientConnection.SendMessage(response);
         }
         else if (message == "getcurrentsplitname")
         {
             var splitindex       = State.CurrentSplitIndex;
             var currentsplitname = State.CurrentSplit.Name;
             var response         = currentsplitname;
             clientConnection.SendMessage(response);
         }
         else if (message == "getprevioussplitname")
         {
             var previoussplitindex = State.CurrentSplitIndex - 1;
             var previoussplitname  = State.Run[previoussplitindex].Name;
             var response           = previoussplitname;
             clientConnection.SendMessage(response);
         }
         else if (message == "getlastsplittime" && State.CurrentSplitIndex > 0)
         {
             var splittime = State.Run[State.CurrentSplitIndex - 1].SplitTime[State.CurrentTimingMethod];
             var response  = SplitTimeFormatter.Format(splittime);
             clientConnection.SendMessage(response);
         }
         else if (message == "getcomparisonsplittime")
         {
             var splittime = State.CurrentSplit.Comparisons[State.CurrentComparison][State.CurrentTimingMethod];
             var response  = SplitTimeFormatter.Format(splittime);
             clientConnection.SendMessage(response);
         }
         else if (message == "getcurrentrealtime")
         {
             var time     = State.CurrentTime.RealTime;
             var response = SplitTimeFormatter.Format(time);
             clientConnection.SendMessage(response);
         }
         else if (message == "getcurrentgametime")
         {
             var timingMethod = TimingMethod.GameTime;
             if (!State.IsGameTimeInitialized)
             {
                 timingMethod = TimingMethod.RealTime;
             }
             var time     = State.CurrentTime[timingMethod];
             var response = SplitTimeFormatter.Format(time);
             clientConnection.SendMessage(response);
         }
         else if (message == "getcurrenttime")
         {
             var timingMethod = State.CurrentTimingMethod;
             if (timingMethod == TimingMethod.GameTime && !State.IsGameTimeInitialized)
             {
                 timingMethod = TimingMethod.RealTime;
             }
             var time     = State.CurrentTime[timingMethod];
             var response = SplitTimeFormatter.Format(time);
             clientConnection.SendMessage(response);
         }
         else if (message == "getfinaltime" || message.StartsWith("getfinaltime "))
         {
             var comparison = State.CurrentComparison;
             if (message.Contains(" "))
             {
                 comparison = message.Split(new char[] { ' ' }, 2)[1];
             }
             var time = (State.CurrentPhase == TimerPhase.Ended)
                 ? State.CurrentTime[State.CurrentTimingMethod]
                 : State.Run.Last().Comparisons[comparison][State.CurrentTimingMethod];
             var response = SplitTimeFormatter.Format(time);
             clientConnection.SendMessage(response);
         }
         else if (message.StartsWith("getpredictedtime "))
         {
             var comparison = message.Split(new char[] { ' ' }, 2)[1];
             var prediction = PredictTime(State, comparison);
             var response   = SplitTimeFormatter.Format(prediction);
             clientConnection.SendMessage(response);
         }
         else if (message == "getbestpossibletime")
         {
             var comparison = LiveSplit.Model.Comparisons.BestSegmentsComparisonGenerator.ComparisonName;
             var prediction = PredictTime(State, comparison);
             var response   = SplitTimeFormatter.Format(prediction);
             clientConnection.SendMessage(response);
         }
         else if (message == "getcurrenttimerphase")
         {
             var response = State.CurrentPhase.ToString();
             clientConnection.SendMessage(response);
         }
         else if (message.StartsWith("setcomparison "))
         {
             var comparison = message.Split(new char[] { ' ' }, 2)[1];
             State.CurrentComparison = comparison;
         }
         else if (message == "switchto realtime")
         {
             State.CurrentTimingMethod = TimingMethod.RealTime;
         }
         else if (message == "switchto gametime")
         {
             State.CurrentTimingMethod = TimingMethod.GameTime;
         }
         else if (message.StartsWith("setsplitname "))
         {
             int    index = Convert.ToInt32(message.Split(new char[] { ' ' }, 3)[1]);
             string title = message.Split(new char[] { ' ' }, 3)[2];
             State.Run[index].Name = title;
             State.Run.HasChanged  = true;
         }
         else if (message.StartsWith("setcurrentsplitname "))
         {
             string title = message.Split(new char[] { ' ' }, 2)[1];
             State.Run[State.CurrentSplitIndex].Name = title;
             State.Run.HasChanged = true;
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
     }
 }
Ejemplo n.º 3
0
        void connection_MessageReceived(object sender, MessageEventArgs e)
        {
            if (State == null)
            {
                return;
            }

            try
            {
                var message = e.Message;

                if (message == "split")
                {
                    Model.Split();
                }
                else if (message == "unsplit")
                {
                    Model.UndoSplit();
                }
                else if (message == "skipsplit")
                {
                    Model.SkipSplit();
                }
                else if (message == "pause" && State.CurrentPhase != TimerPhase.Paused)
                {
                    Model.Pause();
                }
                else if (message == "resume" && State.CurrentPhase == TimerPhase.Paused)
                {
                    Model.Pause();
                }
                else if (message == "reset")
                {
                    Model.Reset();
                }
                else if (message == "starttimer")
                {
                    Model.Start();
                }
                else if (message.StartsWith("setgametime "))
                {
                    var value = message.Split(' ')[1];
                    var time  = parseTime(value);
                    State.SetGameTime(time);
                }
                else if (message.StartsWith("setloadingtimes "))
                {
                    var value = message.Split(' ')[1];
                    var time  = parseTime(value);
                    State.LoadingTimes = time ?? TimeSpan.Zero;
                }
                else if (message == "pausegametime")
                {
                    State.IsGameTimePaused = true;
                }
                else if (message == "unpausegametime")
                {
                    State.IsGameTimePaused = false;
                }
                else if (message == "getdelta")
                {
                    var delta    = LiveSplitStateHelper.GetLastDelta(State, State.CurrentSplitIndex, State.CurrentComparison, State.CurrentTimingMethod);
                    var response = DeltaFormatter.Format(delta);
                    e.Connection.SendMessage(response);
                }
                else if (message == "getlastsplittime" && State.CurrentSplitIndex > 0)
                {
                    var splittime = State.Run[State.CurrentSplitIndex - 1].SplitTime[State.CurrentTimingMethod];
                    var response  = SplitTimeFormatter.Format(splittime);
                    e.Connection.SendMessage(response);
                }
                else if (message == "getcomparisonsplittime")
                {
                    var splittime = State.CurrentSplit.Comparisons[State.CurrentComparison][State.CurrentTimingMethod];
                    var response  = SplitTimeFormatter.Format(splittime);
                    e.Connection.SendMessage(response);
                }
                else if (message == "getcurrenttime")
                {
                    var time     = State.CurrentTime[State.CurrentTimingMethod];
                    var response = SplitTimeFormatter.Format(time);
                    e.Connection.SendMessage(response);
                }
                else if (message == "getfinaltime" || message.StartsWith("getfinaltime "))
                {
                    var comparison = State.CurrentComparison;
                    if (message.Contains(" "))
                    {
                        comparison = message.Split(new char[] { ' ' }, 2)[1];
                    }
                    var time = (State.CurrentPhase == TimerPhase.Ended)
                        ? State.CurrentTime[State.CurrentTimingMethod]
                        : State.Run.Last().Comparisons[comparison][State.CurrentTimingMethod];
                    var response = SplitTimeFormatter.Format(time);
                    e.Connection.SendMessage(response);
                }
                else if (message.StartsWith("getpredictedtime "))
                {
                    var comparison = message.Split(new char[] { ' ' }, 2)[1];
                    var prediction = PredictTime(State, comparison);
                    var response   = SplitTimeFormatter.Format(prediction);
                    e.Connection.SendMessage(response);
                }
                else if (message == "getbestpossibletime")
                {
                    var comparison = LiveSplit.Model.Comparisons.BestSegmentsComparisonGenerator.ComparisonName;
                    var prediction = PredictTime(State, comparison);
                    var response   = SplitTimeFormatter.Format(prediction);
                    e.Connection.SendMessage(response);
                }
                else if (message.StartsWith("setcomparison "))
                {
                    var comparison = message.Split(new char[] { ' ' }, 2)[1];
                    State.CurrentComparison = comparison;
                }
                else if (message == "switchto realtime")
                {
                    State.CurrentTimingMethod = TimingMethod.RealTime;
                }
                else if (message == "switchto gametime")
                {
                    State.CurrentTimingMethod = TimingMethod.GameTime;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }