Exemple #1
0
        void Model_OnSplit(object sender, EventArgs e)
        {
            var timeFormatter = new RegularTimeFormatter(TimeAccuracy.Hundredths);

            if (LiveSplitChannel != null && (RaceState == RaceState.RaceStarted || RaceState == RaceState.RaceEnded))
            {
                if (Model.CurrentState.CurrentSplitIndex > 0)
                {
                    var split   = Model.CurrentState.Run[Model.CurrentState.CurrentSplitIndex - 1];
                    var timeRTA = "-";
                    var timeIGT = "-";
                    if (split.SplitTime.RealTime != null)
                    {
                        timeRTA = timeFormatter.Format(split.SplitTime.RealTime);
                    }
                    if (split.SplitTime.GameTime != null)
                    {
                        timeIGT = timeFormatter.Format(split.SplitTime.GameTime);
                    }
                    Client.LocalUser.SendMessage(LiveSplitChannel, String.Format(".time \"{0}\" {1}", Escape(split.Name), timeRTA));
                    Client.LocalUser.SendMessage(LiveSplitChannel, String.Format(".timeGT \"{0}\" {1}", Escape(split.Name), timeIGT));
                }
            }

            if (RaceChannel != null)
            {
                if (Model.CurrentState.CurrentPhase == TimerPhase.Ended && RaceState == RaceState.RaceStarted)
                {
                    Client.LocalUser.SendMessage(RaceChannel, ".done");
                }
            }
        }
        public void Save(IRun run, Stream stream)
        {
            var regularTimeFormatter = new RegularTimeFormatter(TimeAccuracy.Hundredths);
            var shortTimeFormatter   = new ShortTimeFormatter();

            var writer = new StreamWriter(stream);

            if (!string.IsNullOrEmpty(run.GameName))
            {
                writer.Write(Escape(run.GameName));

                if (!string.IsNullOrEmpty(run.CategoryName))
                {
                    writer.Write(" - ");
                }
            }

            writer.Write(Escape(run.CategoryName));
            writer.Write(',');
            writer.WriteLine(Escape(run.AttemptCount.ToString()));

            foreach (var segment in run)
            {
                writer.Write(Escape(segment.Name));
                writer.Write(',');
                writer.Write(Escape(regularTimeFormatter.Format(segment.PersonalBestSplitTime.RealTime)));
                writer.Write(',');
                writer.WriteLine(Escape(shortTimeFormatter.Format(segment.BestSegmentTime.RealTime)));
            }

            writer.Flush();
        }
        public void RegularTimeFormatterFormatsTimeCorrectlyInGivenAccuracy_WhenTimeIsNull(TimeAccuracy timeAccuracy, string expectedTime)
        {
            var sut = new RegularTimeFormatter(timeAccuracy);

            var formattedTime = sut.Format(null);

            Assert.Equal(expectedTime, formattedTime);
        }
        [InlineData("-1.00:02:01.999", TimeAccuracy.Hundredths, "−24:02:01.99")]  // Actual:<0:01.99> [Fail]
        public void NegativesTestRegularTimeFormatter(string timespanText, TimeAccuracy timeAccuracy, string expectedTime)
        {
            var formatter = new RegularTimeFormatter(timeAccuracy);
            var time      = TimeSpan.Parse(timespanText);

            var formattedTime = formatter.Format(time);

            Assert.Equal(expectedTime, formattedTime);
        }
        public void RegularTimeFormatterFormatsTimeCorrectlyInGivenAccuracy_WhenTimeIsValid(string timespanText, TimeAccuracy timeAccuracy, string expectedTime)
        {
            var sut  = new RegularTimeFormatter(timeAccuracy);
            var time = TimeSpan.Parse(timespanText);

            var formattedTime = sut.Format(time);

            Assert.Equal(expectedTime, formattedTime);
        }
 public RivaTunerComponent(LiveSplitState state)
 {
     State                     = state;
     Settings                  = new RivaTunerSettings();
     TimeFormatter             = new RegularTimeFormatter(TimeAccuracy.Hundredths);
     SplitTimeFormatter        = new RegularSplitTimeFormatter(TimeAccuracy.Seconds);
     DeltaFormatter            = new DeltaSplitTimeFormatter(TimeAccuracy.Tenths, true);
     ShortFormatter            = new ShortTimeFormatter();
     PossibleTimeSaveFormatter = new PossibleTimeSaveFormatter();
 }
 public TotalPlaytimeComponent(LiveSplitState state)
 {
     HoursTimeFormatter = new RegularTimeFormatter();
     DaysTimeFormatter  = new DaysTimeFormatter();
     InternalComponent  = new InfoTimeComponent("Total Playtime", TimeSpan.Zero, DaysTimeFormatter);
     Settings           = new TotalPlaytimeSettings()
     {
         CurrentState = state
     };
 }
Exemple #8
0
        public SekiroComponent(LiveSplitState state)
        {
            _control           = new SekiroControl();
            _timeFormatter     = new RegularTimeFormatter(TimeAccuracy.Hundredths);
            _infoTimeComponent = new InfoTimeComponent(ComponentName, TimeSpan.Zero, _timeFormatter);

            state.OnReset += delegate { _oldMillis = 0; };
            state.OnReset += delegate { _oldMillis = 0; };

            _pointer = new SekiroPointer();
        }
        public Component()
        {
            Settings    = new Settings();
            Model       = new TimerModel();
            Connections = new List <Connection>();

            DeltaFormatter     = new PreciseDeltaFormatter(TimeAccuracy.Hundredths);
            SplitTimeFormatter = new RegularTimeFormatter(TimeAccuracy.Hundredths);

            ContextMenuControls = new Dictionary <String, Action>();
            ContextMenuControls.Add("Start Server", Start);
        }
Exemple #10
0
        public string Format(TimeSpan?time)
        {
            var formatter = new RegularTimeFormatter(Accuracy);

            if (time == null)
            {
                return("-");
            }
            else
            {
                return(formatter.Format(time));
            }
        }
Exemple #11
0
        private string FormatNotes(string notePlaceholder)
        {
            var timeFormatter      = new RegularTimeFormatter(TimeAccuracy.Seconds);
            var deltaTimeFormatter = new DeltaTimeFormatter();

            var game     = Run.GameName ?? "";
            var category = Run.GetExtendedCategoryName();
            var pb       = timeFormatter.Format(Run.Last().PersonalBestSplitTime[State.CurrentTimingMethod]) ?? "";
            var title    = Run.GetExtendedName();

            var splitName = "";
            var splitTime = "-";
            var deltaTime = "-";

            if ((State.CurrentPhase == TimerPhase.Running ||
                 State.CurrentPhase == TimerPhase.Paused) &&
                State.CurrentSplitIndex > 0)
            {
                var lastSplit = Run[State.CurrentSplitIndex - 1];

                splitName = lastSplit.Name ?? "";
                splitTime = timeFormatter.Format(lastSplit.SplitTime[State.CurrentTimingMethod]);
                deltaTime = deltaTimeFormatter.Format(lastSplit.SplitTime[State.CurrentTimingMethod] - lastSplit.PersonalBestSplitTime[State.CurrentTimingMethod]);
            }

            var streamLink = "";

            if (notePlaceholder.Contains("$stream"))
            {
                try
                {
                    if (Twitch.Instance.IsLoggedIn || Twitch.Instance.VerifyLogin())
                    {
                        var userName = Twitch.Instance.ChannelName;
                        streamLink = string.Format("http://twitch.tv/{0}", userName);
                    }
                }
                catch { }
            }

            return(notePlaceholder
                   .Replace("$game", game)
                   .Replace("$category", category)
                   .Replace("$title", title)
                   .Replace("$pb", pb)
                   .Replace("$splitname", splitName)
                   .Replace("$splittime", splitTime)
                   .Replace("$delta", deltaTime)
                   .Replace("$stream", streamLink));
        }
 public HistoryAverageComponent(LiveSplitState state)
 {
     Settings = new HistoryAverageComponentSettings()
     {
         CurrentState = state
     };
     Formatter          = new RegularTimeFormatter(Settings.Accuracy);
     InternalComponent  = new HistoryAverageTimeComponent(Settings, Formatter);
     state.OnSplit     += state_OnSplit;
     state.OnUndoSplit += state_OnUndoSplit;
     state.OnReset     += state_OnReset;
     CurrentState       = state;
     CurrentState.RunManuallyModified += CurrentState_RunModified;
     UpdateHistoryValue(state);
 }
Exemple #13
0
        public void TestRegularTimeFormatter(string timespanText, TimeAccuracy timeAccuracy, string expected)
        {
            var formatter = new RegularTimeFormatter(timeAccuracy);

            TimeSpan?time = null;

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

            string formatted = formatter.Format(time);

            Assert.AreEqual(expected, formatted);
        }
        public LeaderBoardComponent(LiveSplitState state)
        {
            State              = state;
            Client             = new SpeedrunComClient(userAgent: Updates.UpdateHelper.UserAgent, maxCacheElements: 0);
            RefreshInterval    = TimeSpan.FromMinutes(5);
            Cache              = new GraphicsCache();
            TimeFormatter      = new AutomaticPrecisionTimeFormatter();
            LocalTimeFormatter = new RegularTimeFormatter();
            InternalComponent  = new InfoTextComponent("Leaderboard", "-");

            Settings = new LeaderBoardSettings()
            {
                CurrentState = state
            };
        }
Exemple #15
0
        public ServerComponent(LiveSplitState state)
        {
            Settings = new Settings();
            Model    = new TimerModel();

            DeltaFormatter     = new PreciseDeltaFormatter(TimeAccuracy.Hundredths);
            SplitTimeFormatter = new RegularTimeFormatter(TimeAccuracy.Hundredths);

            ContextMenuControls = new Dictionary <string, Action>();
            ContextMenuControls.Add("Start Server (WS)", Start);

            State = state;
            Form  = state.Form;

            Model.CurrentState = State;
            State.OnStart     += State_OnStart;
        }
Exemple #16
0
        public CommandServer(LiveSplitState state)
        {
            Model       = new TimerModel();
            Connections = new List <Connection>();

            DeltaFormatter = new DeltaTimeFormatter()
            {
                Accuracy     = TimeAccuracy.Hundredths,
                DropDecimals = false
            };
            SplitTimeFormatter = new RegularTimeFormatter(TimeAccuracy.Hundredths);

            State = state;
            Form  = state.Form;

            Model.CurrentState = State;
            State.OnStart     += State_OnStart;
        }
Exemple #17
0
        public Ds3Component(LiveSplitState state)
        {
            _control           = new Ds3Control();
            _timeFormatter     = new RegularTimeFormatter(TimeAccuracy.Hundredths);
            _infoTimeComponent = new InfoTimeComponent(ComponentName, TimeSpan.Zero, _timeFormatter);
            _infoTimeComponent = new InfoTimeComponent(ComponentName, TimeSpan.Zero, _timeFormatter);

            state.OnReset += delegate {
                _oldMillis = 0;
            };

            state.OnStart += delegate {
                _oldMillis = 0;
            };

            Pointer = new Ds3Pointer();

            _splitter = new Ds3AutoSplitter(state, _control.splitSettings);
        }
 public HistoryAverageTimeComponent(HistoryAverageComponentSettings settings, RegularTimeFormatter formatter)
     : base(settings.Text1, TimeSpan.Zero, formatter)
 {
     Settings = settings;
 }
Exemple #19
0
        public bool SubmitRun(IRun run, string username, string password, Func <Image> screenShotFunction = null, bool attachSplits = false, TimingMethod method = TimingMethod.RealTime, string gameId = "", string categoryId = "", string version = "", string comment = "", string video = "", params string[] additionalParams)
        {
            var timeFormatter = new RegularTimeFormatter(TimeAccuracy.Seconds);

            if (attachSplits)
            {
                comment += " " + SplitsIO.Instance.Share(run, screenShotFunction);
            }

            var postRequest = (HttpWebRequest)WebRequest.Create(GetUri("submit"));

            postRequest.Method      = "POST";
            postRequest.ContentType = "application/x-www-form-urlencoded";

            using (var postStream = postRequest.GetRequestStream())
            {
                var writer = new StreamWriter(postStream);

                writer.Write("nickname=");
                writer.Write(HttpUtility.UrlEncode(username));

                //nickname=CryZeTesting&country=Germany&twitter=CryZe107&youtube=CryZe92&twitch=CryZe92&game=The+Legend+of+Zelda%3A+The+Wind+Waker&category=Test%25&console=&played_on=Emulator&emulator=Dolphin+3.5&region=NTSC-J&time=5%3A07%3A25&date=12%2F18%2F2013&video=http%3A%2F%2Fyoutube.com%2FTesting&notes=Still+in+Browser.+And+I+just+f****d+up+xD

                //Country

                //Twitter

                /*if (Twitter.Instance.)
                 * writer.Write("nickname=");
                 * writer.Write(HttpUtility.UrlEncode(username));*/

                //Youtube

                /*writer.Write("nickname=");
                 * writer.Write(HttpUtility.UrlEncode(username));*/

                if (Twitch.Instance.IsLoggedIn)
                {
                    writer.Write("&twitch=");
                    writer.Write(HttpUtility.UrlEncode(Twitch.Instance.ChannelName));
                }

                writer.Write("&game=");
                writer.Write(HttpUtility.UrlEncode(run.GameName));

                writer.Write("&category=");
                writer.Write(HttpUtility.UrlEncode(run.CategoryName));

                writer.Write("&console="); //TODO We need console
                //writer.Write(HttpUtility.UrlEncode(run.CategoryName));

                //Played on

                //region

                //Time
                writer.Write("&time=");
                writer.Write(HttpUtility.UrlEncode(timeFormatter.Format(run.Last().PersonalBestSplitTime.RealTime)));

                writer.Write("&date=");
                var dateTime = run.AttemptHistory.First(x => x.Time.RealTime == run.Last().PersonalBestSplitTime.RealTime).Ended.Value;
                writer.Write(HttpUtility.UrlEncode(String.Format("{0:00}/{1:00}/{2}", dateTime.Month, dateTime.Day, dateTime.Year)));

                writer.Write("&video=");
                writer.Write(HttpUtility.UrlEncode(video));

                writer.Write("&notes=");
                writer.Write(HttpUtility.UrlEncode(comment));

                writer.Flush();
            }

            using (var resultStream = postRequest.GetResponse().GetResponseStream())
            {
                var reader = new StreamReader(resultStream);

                return(reader.ReadToEnd().Contains("<strong>Submitted!</strong>"));
            }
        }
Exemple #20
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            splitsTreeView.Nodes.Clear();
            try
            {
                var fuzzyGameName = txtSearch.Text;
                if (!string.IsNullOrEmpty(fuzzyGameName))
                {
                    try
                    {
                        var games = SpeedrunCom.Client.Games.GetGames(name: fuzzyGameName, embeds: new GameEmbeds(embedCategories: true));

                        foreach (var game in games)
                        {
                            var gameNode = new TreeNode(game.Name);
                            gameNode.Tag = game.WebLink;
                            var categories    = game.FullGameCategories;
                            var timeFormatter = new RegularTimeFormatter(game.Ruleset.ShowMilliseconds ? TimeAccuracy.Hundredths : TimeAccuracy.Seconds);

                            foreach (var category in categories)
                            {
                                var categoryNode = new TreeNode(category.Name);
                                categoryNode.Tag = category.WebLink;
                                var leaderboard = category.Leaderboard;
                                var records     = leaderboard.Records;

                                foreach (var record in records)
                                {
                                    var place   = record.Rank.ToString(CultureInfo.InvariantCulture).PadLeft(getDigits(records.Count())) + ".   ";
                                    var runners = string.Join(" & ", record.Players.Select(x => x.Name));
                                    var time    = record.Times.Primary;
                                    var runText = place + (time.HasValue ? timeFormatter.Format(time) : "") + " by " + runners;
                                    var runNode = new TreeNode(runText);
                                    runNode.Tag = record;
                                    if (!record.SplitsAvailable)
                                    {
                                        runNode.ForeColor = Color.Gray;
                                    }
                                    categoryNode.Nodes.Add(runNode);
                                }
                                gameNode.Nodes.Add(categoryNode);
                            }
                            splitsTreeView.Nodes.Add(gameNode);
                        }
                    }
                    catch { }

                    try
                    {
                        var fuzzyUserName = txtSearch.Text.TrimStart('@');
                        var users         = SpeedrunCom.Client.Users.GetUsersFuzzy(fuzzyName: fuzzyUserName);

                        foreach (var user in users)
                        {
                            var userNode = new TreeNode("@" + user.Name);
                            userNode.Tag = user.WebLink;
                            var recordsGroupedByGames = SpeedrunCom.Client.Users.GetPersonalBests(user.ID, embeds: new RunEmbeds(embedGame: true, embedCategory: true))
                                                        .GroupBy(x => x.Game.Name);

                            foreach (var recordsForGame in recordsGroupedByGames)
                            {
                                var gameName      = recordsForGame.Key;
                                var gameNode      = new TreeNode(gameName);
                                var game          = recordsForGame.First().Game;
                                var timeFormatter = new RegularTimeFormatter(game.Ruleset.ShowMilliseconds ? TimeAccuracy.Hundredths : TimeAccuracy.Seconds);
                                gameNode.Tag = game.WebLink;

                                foreach (var record in recordsForGame)
                                {
                                    var categoryName = record.Category.Name;

                                    var place       = formatPlace(record.Rank);
                                    var coopRunners = record.Players.Count() > 1 ? " by " + string.Join(" & ", record.Players.Select(x => x.Name)) : "";
                                    var recordText  = timeFormatter.Format(record.Times.Primary) + " in " + categoryName + coopRunners + place;

                                    var recordNode = new TreeNode(recordText);
                                    recordNode.Tag = record;
                                    if (!record.SplitsAvailable)
                                    {
                                        recordNode.ForeColor = Color.Gray;
                                    }
                                    gameNode.Nodes.Add(recordNode);
                                }
                                userNode.Nodes.Add(gameNode);
                            }
                            splitsTreeView.Nodes.Add(userNode);
                        }
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                MessageBox.Show(this, "Search Failed!", "Search Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }