<commit_before>﻿using LiveSplit.Model.Input;
using LiveSplit.Options;
using LiveSplit.UI;
using System;
using System.Linq;
using Forms = System.Windows.Forms;

namespace LiveSplit.Model
{
    public class LiveSplitState : ICloneable
    {
        public IRun Run { get; set; }
        public ILayout Layout { get; set; }
        public LayoutSettings LayoutSettings { get; set; }
        public ISettings Settings { get; set; }
        public Forms.Form Form { get; set; }

        public TripleDateTime StartTime { get; set; }
        public TimeSpan PauseTime { get; set; }
        public TimeSpan GameTimePauseTime { get; set; }
        public TimerPhase CurrentPhase { get; set; }
        public string CurrentComparison { get; set; }
        public TimingMethod CurrentTimingMethod { get; set; }
        public TimeSpan LoadingTimes { get; set; }
        private bool isGameTimePaused;
        public bool IsGameTimePaused
        {
            get { return isGameTimePaused; }
            set
            {
                if (!value && isGameTimePaused)
                    LoadingTimes = CurrentTime.RealTime.Value - CurrentTime.GameTime.Value;
                else if (value && !isGameTimePaused)
                    GameTimePauseTime = CurrentTime.GameTime.Value;

                isGameTimePaused = value;
            }
        }

        

        //public ReaderWriterLockSlim DrawLock { get; set; }

        public event EventHandler OnSplit;
        public event EventHandler OnUndoSplit;
        public event EventHandler OnSkipSplit;
        public event EventHandler OnStart;
        public event EventHandlerT<TimerPhase> OnReset;
        public event EventHandler OnPause;
        public event EventHandler OnResume;
        public event EventHandler OnScrollUp;
        public event EventHandler OnScrollDown;
        public event EventHandler OnSwitchComparisonPrevious;
        public event EventHandler OnSwitchComparisonNext;

        public event EventHandler RunManuallyModified;
        public event EventHandler ComparisonRenamed;

        public Time CurrentTime
        { 
            get 
            {
                var curTime = new Time();

                if (CurrentPhase == TimerPhase.NotRunning)
                    curTime.RealTime = TimeSpan.Zero;
                else if (CurrentPhase == TimerPhase.Running)
                    curTime.RealTime = TripleDateTime.Now - StartTime;
                else if (CurrentPhase == TimerPhase.Paused)
                    curTime.RealTime = PauseTime;
                else
                    curTime.RealTime = Run.Last().SplitTime.RealTime;

                if (CurrentPhase == TimerPhase.Ended)
                    curTime.GameTime = Run.Last().SplitTime.GameTime;
                else
                    curTime.GameTime = IsGameTimePaused 
                        ? GameTimePauseTime 
                        : curTime.RealTime - LoadingTimes;

                return curTime;
            }
        }

        public int CurrentSplitIndex { get; set; }
        public ISegment CurrentSplit { get { return (CurrentSplitIndex < 0 && CurrentSplitIndex < Run.Count) ? null : Run[CurrentSplitIndex]; } }

        private LiveSplitState() { }

        public LiveSplitState(IRun run, Forms.Form form, ILayout layout, LayoutSettings layoutSettings, ISettings settings)
        {
            Run = run;
            Form = form;
            Layout = layout;
            Settings = settings;
            LayoutSettings = layoutSettings;
            StartTime = TripleDateTime.Now;
            CurrentPhase = TimerPhase.NotRunning;
            CurrentSplitIndex = -1;
            //DrawLock = new ReaderWriterLockSlim();
        }

        public object Clone()
        {<commit_msg>Current Split Index is now checked properly<commit_after>﻿using LiveSplit.Model.Input;
using LiveSplit.Options;
using LiveSplit.UI;
using System;
using System.Linq;
using Forms = System.Windows.Forms;

namespace LiveSplit.Model
{
    public class LiveSplitState : ICloneable
    {
        public IRun Run { get; set; }
        public ILayout Layout { get; set; }
        public LayoutSettings LayoutSettings { get; set; }
        public ISettings Settings { get; set; }
        public Forms.Form Form { get; set; }

        public TripleDateTime StartTime { get; set; }
        public TimeSpan PauseTime { get; set; }
        public TimeSpan GameTimePauseTime { get; set; }
        public TimerPhase CurrentPhase { get; set; }
        public string CurrentComparison { get; set; }
        public TimingMethod CurrentTimingMethod { get; set; }
        public TimeSpan LoadingTimes { get; set; }
        private bool isGameTimePaused;
        public bool IsGameTimePaused
        {
            get { return isGameTimePaused; }
            set
            {
                if (!value && isGameTimePaused)
                    LoadingTimes = CurrentTime.RealTime.Value - CurrentTime.GameTime.Value;
                else if (value && !isGameTimePaused)
                    GameTimePauseTime = CurrentTime.GameTime.Value;

                isGameTimePaused = value;
            }
        }

        

        //public ReaderWriterLockSlim DrawLock { get; set; }

        public event EventHandler OnSplit;
        public event EventHandler OnUndoSplit;
        public event EventHandler OnSkipSplit;
        public event EventHandler OnStart;
        public event EventHandlerT<TimerPhase> OnReset;
        public event EventHandler OnPause;
        public event EventHandler OnResume;
        public event EventHandler OnScrollUp;
        public event EventHandler OnScrollDown;
        public event EventHandler OnSwitchComparisonPrevious;
        public event EventHandler OnSwitchComparisonNext;

        public event EventHandler RunManuallyModified;
        public event EventHandler ComparisonRenamed;

        public Time CurrentTime
        { 
            get 
            {
                var curTime = new Time();

                if (CurrentPhase == TimerPhase.NotRunning)
                    curTime.RealTime = TimeSpan.Zero;
                else if (CurrentPhase == TimerPhase.Running)
                    curTime.RealTime = TripleDateTime.Now - StartTime;
                else if (CurrentPhase == TimerPhase.Paused)
                    curTime.RealTime = PauseTime;
                else
                    curTime.RealTime = Run.Last().SplitTime.RealTime;

                if (CurrentPhase == TimerPhase.Ended)
                    curTime.GameTime = Run.Last().SplitTime.GameTime;
                else
                    curTime.GameTime = IsGameTimePaused 
                        ? GameTimePauseTime 
                        : curTime.RealTime - LoadingTimes;

                return curTime;
            }
        }

        public int CurrentSplitIndex { get; set; }
        public ISegment CurrentSplit { get { return (CurrentSplitIndex >= 0 && CurrentSplitIndex < Run.Count) ? Run[CurrentSplitIndex] : null; } }

        private LiveSplitState() { }

        public LiveSplitState(IRun run, Forms.Form form, ILayout layout, LayoutSettings layoutSettings, ISettings settings)
        {
            Run = run;
            Form = form;
            Layout = layout;
            Settings = settings;
            LayoutSettings = layoutSettings;
            StartTime = TripleDateTime.Now;
            CurrentPhase = TimerPhase.NotRunning;
            CurrentSplitIndex = -1;
            //DrawLock = new ReaderWriterLockSlim();
        }

        public object Clone()
        {
{'fraction_non_alphanumeric': 0.06583653464034972, 'fraction_numerical': 0.0005298715061597563, 'mean_word_length': 1.8436911487758945, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6338038', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1795, 'n_words': 512}