public void FormatTimeAsDash_WhenTimeIsNullRegardlessOfAccuracy(TimeAccuracy accuracy)
        {
            var sut = new SegmentTimesFormatter(accuracy);

            var formattedTime = sut.Format(null);

            Assert.Equal(TimeFormatConstants.DASH, formattedTime);
        }
        public void FormatTimeCorrectly_WhenTimeIsValidAndAccuracyIsSupplied(string timespanText, TimeAccuracy accuracy, string expectedTime)
        {
            var sut  = new SegmentTimesFormatter(accuracy);
            var time = TimeSpan.Parse(timespanText);

            var formattedTime = sut.Format(time);

            Assert.Equal(expectedTime, formattedTime);
        }
        public void TestSegmentTimesFormatter(string timespanText, TimeAccuracy accuracy, string expected)
        {
            var formatter = new SegmentTimesFormatter(accuracy);

            TimeSpan?time = null;

            if (timespanText != null)
            {
                time = TimeSpan.Parse(timespanText);
            }

            string formatted = formatter.Format(time);

            Assert.AreEqual(expected, formatted);
        }
Esempio n. 4
0
        public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            var lastSplitOffset = state.CurrentSplitIndex == state.Run.Count ? -1 : 0;

            var timingMethod = state.CurrentTimingMethod;

            if (Settings.TimingMethod == "Real Time")
            {
                timingMethod = TimingMethod.RealTime;
            }
            else if (Settings.TimingMethod == "Game Time")
            {
                timingMethod = TimingMethod.GameTime;
            }

            var formatter = new SegmentTimesFormatter(Settings.SegmentTimesAccuracy);

            if (state.CurrentSplitIndex >= 0)
            {
                Comparison     = Settings.Comparison == "Current Comparison" ? state.CurrentComparison : Settings.Comparison;
                Comparison2    = Settings.Comparison2 == "Current Comparison" ? state.CurrentComparison : Settings.Comparison2;
                HideComparison = Settings.HideComparison;

                if (HideComparison || !state.Run.Comparisons.Contains(Comparison2) || Comparison2 == "None")
                {
                    HideComparison = true;
                    if (!state.Run.Comparisons.Contains(Comparison) || Comparison == "None")
                    {
                        Comparison = state.CurrentComparison;
                    }
                }
                else if (!state.Run.Comparisons.Contains(Comparison) || Comparison == "None")
                {
                    HideComparison = true;
                    Comparison     = Comparison2;
                }
                else if (Comparison == Comparison2)
                {
                    HideComparison = true;
                }

                ComparisonName  = CompositeComparisons.GetShortComparisonName(Comparison);
                ComparisonName2 = CompositeComparisons.GetShortComparisonName(Comparison2);

                TimeSpan?segmentTime = null;

                if (Comparison == BestSegmentsComparisonGenerator.ComparisonName)
                {
                    segmentTime = state.Run[state.CurrentSplitIndex + lastSplitOffset].BestSegmentTime[timingMethod];
                }
                else
                {
                    if (state.CurrentSplitIndex == 0 || (state.CurrentSplitIndex == 1 && lastSplitOffset == -1))
                    {
                        segmentTime = state.Run[0].Comparisons[Comparison][timingMethod];
                    }
                    else if (state.CurrentSplitIndex > 0)
                    {
                        segmentTime = state.Run[state.CurrentSplitIndex + lastSplitOffset].Comparisons[Comparison][timingMethod]
                                      - state.Run[state.CurrentSplitIndex - 1 + lastSplitOffset].Comparisons[Comparison][timingMethod];
                    }
                }

                LabelSegment.Text = ComparisonName + ":";

                LabelBest.Text = ComparisonName2 + ":";

                if (Comparison != "None")
                {
                    if (segmentTime != null)
                    {
                        SegmentTime.Text = formatter.Format(segmentTime);
                    }
                    else
                    {
                        SegmentTime.Text = TimeFormatConstants.DASH;
                    }
                }

                if (!HideComparison)
                {
                    TimeSpan?bestSegmentTime = null;
                    if (Comparison2 == BestSegmentsComparisonGenerator.ComparisonName)
                    {
                        bestSegmentTime = state.Run[state.CurrentSplitIndex + lastSplitOffset].BestSegmentTime[timingMethod];
                    }
                    else
                    {
                        if (state.CurrentSplitIndex == 0 || (state.CurrentSplitIndex == 1 && lastSplitOffset == -1))
                        {
                            bestSegmentTime = state.Run[0].Comparisons[Comparison2][timingMethod];
                        }
                        else if (state.CurrentSplitIndex > 0)
                        {
                            bestSegmentTime = state.Run[state.CurrentSplitIndex + lastSplitOffset].Comparisons[Comparison2][timingMethod]
                                              - state.Run[state.CurrentSplitIndex - 1 + lastSplitOffset].Comparisons[Comparison2][timingMethod];
                        }
                    }

                    if (bestSegmentTime != null)
                    {
                        BestSegmentTime.Text = formatter.Format(bestSegmentTime);
                    }
                    else
                    {
                        BestSegmentTime.Text = TimeFormatConstants.DASH;
                    }
                }
                if (state.CurrentSplitIndex >= 0)
                {
                    SplitName.Text = state.Run[state.CurrentSplitIndex + lastSplitOffset].Name;
                }
                else
                {
                    SplitName.Text = "";
                }
            }

            SegmentTimer.Settings.TimingMethod      = Settings.TimingMethod;
            InternalComponent.Settings.TimingMethod = Settings.TimingMethod;
            SegmentTimer.Update(null, state, width, height, mode);
            InternalComponent.Update(null, state, width, height, mode);

            var icon = state.CurrentSplitIndex >= 0 ? state.Run[state.CurrentSplitIndex + lastSplitOffset].Icon : null;

            Cache.Restart();
            Cache["SplitIcon"] = icon;
            if (Cache.HasChanged)
            {
                if (icon == null)
                {
                    FrameCount = 0;
                }
                else
                {
                    FrameCount = icon.GetFrameCount(new FrameDimension(icon.FrameDimensionsList[0]));
                }
            }
            Cache["SplitName"]             = SplitName.Text;
            Cache["LabelSegment"]          = LabelSegment.Text;
            Cache["LabelBest"]             = LabelBest.Text;
            Cache["SegmentTime"]           = SegmentTime.Text;
            Cache["BestSegmentTime"]       = BestSegmentTime.Text;
            Cache["SegmentTimerText"]      = SegmentTimer.BigTextLabel.Text + SegmentTimer.SmallTextLabel.Text;
            Cache["InternalComponentText"] = InternalComponent.BigTextLabel.Text + InternalComponent.SmallTextLabel.Text;
            if (InternalComponent.BigTextLabel.Brush != null && invalidator != null)
            {
                if (InternalComponent.BigTextLabel.Brush is LinearGradientBrush)
                {
                    Cache["TimerColor"] = ((LinearGradientBrush)InternalComponent.BigTextLabel.Brush).LinearColors.First().ToArgb();
                }
                else
                {
                    Cache["TimerColor"] = InternalComponent.BigTextLabel.ForeColor.ToArgb();
                }
            }

            if (invalidator != null && (Cache.HasChanged || FrameCount > 1))
            {
                invalidator.Invalidate(0, 0, width, height);
            }
        }