コード例 #1
0
        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();
        }
コード例 #2
0
 public string Format(TimeSpan? time)
 {
     var formatter = new RegularTimeFormatter(Accuracy);
     if (time == null)
         return "-";
     else
         return formatter.Format(time);
 }
コード例 #3
0
 public TotalPlaytimeComponent(LiveSplitState state)
 {
     TimeFormatter = new RegularTimeFormatter(TimeAccuracy.Seconds);
     InternalComponent = new InfoTimeComponent("Total Playtime", TimeSpan.Zero, TimeFormatter);
     Settings = new TotalPlaytimeSettings()
     {
         CurrentState = state
     };
 }
コード例 #4
0
        public string Format(TimeSpan?time)
        {
            var formatter = new RegularTimeFormatter(Accuracy);

            if (time == null)
            {
                return(TimeFormatConstants.DASH);
            }

            return(formatter.Format(time));
        }
コード例 #5
0
        public string Format(TimeSpan?time)
        {
            var formatter = new RegularTimeFormatter(Accuracy);

            if (time == null)
            {
                return("-");
            }
            else
            {
                return(formatter.Format(time));
            }
        }
コード例 #6
0
        public WorldRecordComponent(LiveSplitState state)
        {
            State = state;

            RefreshInterval = TimeSpan.FromMinutes(5);
            Cache = new GraphicsCache();
            TimeFormatter = new RegularTimeFormatter();
            InternalComponent = new InfoTextComponent("World Record", "-");
            Settings = new WorldRecordSettings()
            {
                CurrentState = state
            };
        }
コード例 #7
0
ファイル: Component.cs プロジェクト: 0xwas/LiveSplit.Server
        public Component(LiveSplitState state)
        {
            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);

            State = state;
            Model.CurrentState = State;
            State.OnStart += State_OnStart;
        }
コード例 #8
0
 public AutomaticPrecisionTimeFormatter()
 {
     InternalFormatter = new RegularTimeFormatter();
 }
コード例 #9
0
ファイル: Congratsio.cs プロジェクト: Glurmo/LiveSplit
        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.Time;
                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 response = postRequest.GetResponse())
            using (var resultStream = response.GetResponseStream())
            {
                var reader = new StreamReader(resultStream);

                return reader.ReadToEnd().Contains("<strong>Submitted!</strong>");
            }
        }
コード例 #10
0
ファイル: TimerForm.cs プロジェクト: TheKotti/LiveSplit
        void SRL_RacesRefreshed(object sender, EventArgs e)
        {
            Action<ToolStripItem> addItem = null;
            Action clear = null;

            addItem = x =>
            {
                if (InvokeRequired)
                {
                    Invoke(addItem, x);
                }
                else
                {
                    racingMenuItem.DropDownItems.Add(x);
                }
            };
            clear = () =>
            {
                if (InvokeRequired)
                {
                    Invoke(clear);
                }
                else
                {
                    racingMenuItem.DropDownItems.Clear();
                }
            };

            clear();
            foreach (var race in SpeedRunsLiveAPI.Instance.GetRaces())
            {
                if (race.state != 1)
                    continue;

                var game = race.game.name;
                var goal = race.goal;
                var entrants = race.numentrants;
                var plural = entrants == 1 ? "" : "s";
                var title = string.Format("{0} - {1} ({2} Entrant{3})", game, goal, entrants, plural) as string;
                var item = new ToolStripMenuItem();
                item.Text = title.EscapeMenuItemText();
                item.Tag = race.id;
                item.Click += Race_Click;
                addItem(item);

                SetGameImage(item, race);
            }

            if (racingMenuItem.DropDownItems.Count > 0)
                addItem(new ToolStripSeparator());

            foreach (var race in SpeedRunsLiveAPI.Instance.GetRaces())
            {
                if (race.state != 3)
                    continue;

                var game = race.game.name;
                var goal = race.goal;
                var entrants = race.numentrants;
                var startTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                startTime = startTime.AddSeconds(race.time);

                var finishedCount = 0;
                var forfeitedCount = 0;
                foreach (var entrant in race.entrants.Properties.Values)
                {
                    if (entrant.time >= 0)
                        finishedCount++;
                    if (entrant.statetext == "Forfeit")
                        forfeitedCount++;
                }

                var tsItem = new ToolStripMenuItem();

                Action updateTitleAction = null;
                updateTitleAction = () =>
                    {
                        if (InvokeRequired)
                        {
                            if (!IsDisposed)
                            {
                                try
                                {
                                    Invoke(updateTitleAction);
                                }
                                catch { }
                            }
                        }
                        else
                        {
                            try
                            {
                                var timeSpan = TimeStamp.CurrentDateTime - startTime;
                                if (timeSpan < TimeSpan.Zero)
                                    timeSpan = TimeSpan.Zero;
                                var time = new RegularTimeFormatter().Format(timeSpan);
                                var title = string.Format("[{0}] {1} - {2} ({3} / {4} Finished)", time, game, goal, finishedCount, entrants - forfeitedCount) as string;
                                tsItem.Text = title.EscapeMenuItemText();
                            }
                            catch { }
                        }
                    };

                SetGameImage(tsItem, race);

                updateTitleAction();

                new System.Timers.Timer(500) { Enabled = true }.Elapsed += (s, ev) =>
                    {
                        updateTitleAction();
                    };
                tsItem.Click += (s, ev) =>
                    {
                        ShareSettings.Default.Reload();
                        var username = ShareSettings.Default.SRLIRCUsername;
                        var racers = ((IEnumerable<string>)race.entrants.Properties.Keys).Select(x => x.ToLower());
                        if (!racers.Contains((username ?? "").ToLower()))
                            Settings.RaceViewer.ShowRace(race);
                        else
                        {
                            tsItem.Tag = race.id;
                            Race_Click(tsItem, null);
                        }
                    };
                addItem(tsItem);
            }

            if (racingMenuItem.DropDownItems.Count > 0 && !(racingMenuItem.DropDownItems[racingMenuItem.DropDownItems.Count - 1] is ToolStripSeparator))
                addItem(new ToolStripSeparator());

            var newRaceItem = new ToolStripMenuItem();
            newRaceItem.Text = "New Race...";
            newRaceItem.Click += NewRace_Click;
            addItem(newRaceItem);
        }
コード例 #11
0
ファイル: TimerForm.cs プロジェクト: xarrez/LiveSplit
        void SRL_RacesRefreshed(object sender, EventArgs e)
        {
            Action<String> addString = null;
            Action<ToolStripItem> addItem = null;
            Action clear = null;
            addString = x =>
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(addString, x);
                }
                else
                {
                    racingMenuItem.DropDownItems.Add(x.Replace("&", "&&"));
                }
            };
            addItem = x =>
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(addItem, x);
                }
                else
                {
                    racingMenuItem.DropDownItems.Add(x);
                }
            };
            clear = () =>
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(clear);
                }
                else
                {
                    racingMenuItem.DropDownItems.Clear();
                }
            };

            clear();
            foreach (var race in SpeedRunsLiveAPI.Instance.GetRaces())
            {
                if (race.state != 1)
                    continue;

                var game = race.game.name;
                var goal = race.goal;
                var entrants = race.numentrants;
                var plural = entrants == 1 ? "" : "s";
                var title = String.Format("{0} - {1} ({2} Entrant{3})", game, goal, entrants, plural);
                var item = new ToolStripMenuItem();
                item.Text = title;
                item.Tag = race.id;
                item.Click += Race_Click;
                addItem(item);

                new Thread(() =>
                {
                    try
                    {
                        var image = SpeedRunsLiveAPI.Instance.GetGameImage(race.game.abbrev);
                        Action setImage = () =>
                            {
                                try
                                { 
                                    item.Image = image;
                                }
                                catch (Exception ex)
                                {
                                    Log.Error(ex);
                                }
                            };
                        if (InvokeRequired)
                            Invoke(setImage);
                        else
                            setImage();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                    }
                }).Start();
            }

            if (racingMenuItem.DropDownItems.Count > 0)
                addItem(new ToolStripSeparator());

            foreach (var race in SpeedRunsLiveAPI.Instance.GetRaces())
            {
                if (race.state != 3)
                    continue;

                var game = race.game.name;
                var goal = race.goal;
                var entrants = race.numentrants;
                //var plural = entrants == 1 ? "" : "s";
                var startTime = new DateTime(1970,1,1,0,0,0,0);
                startTime = startTime.AddSeconds(race.time);

                var finishedCount = 0;
                var forfeitedCount = 0;
                foreach (var entrant in race.entrants.Properties.Values)
                {
                    if (entrant.time >= 0)
                        finishedCount++;
                    if (entrant.statetext == "Forfeit")
                        forfeitedCount++;
                }

                var tsItem = new ToolStripMenuItem();

                Action updateTitleAction = null;
                updateTitleAction = () =>
                    {
                        if (InvokeRequired)
                        {
                            if (!IsDisposed)
                            {
                                try
                                {
                                    Invoke(updateTitleAction);
                                }
                                catch (Exception ex)
                                {
                                    Log.Error(ex);
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                var timeSpan = DateTime.UtcNow.ToUniversalTime() - startTime;
                                if (timeSpan < TimeSpan.Zero)
                                    timeSpan = TimeSpan.Zero;
                                var time = new RegularTimeFormatter().Format(timeSpan);
                                var title = String.Format("[{0}] {1} - {2} ({3} / {4} Finished)", time, game, goal, finishedCount, entrants - forfeitedCount);
                                title = title.Replace("&", "&&");
                                tsItem.Text = title;
                            }
                            catch (Exception ex)
                            {
                                Log.Error(ex);
                            }
                        }
                    };

                new Thread(() =>
                    {
                        try
                        {
                            var image = SpeedRunsLiveAPI.Instance.GetGameImage(race.game.abbrev);
                            Action setImage = () =>
                            {
                                try
                                {
                                    tsItem.Image = image;
                                }
                                catch (Exception ex)
                                {
                                    Log.Error(ex);
                                }
                            };
                            if (InvokeRequired)
                                Invoke(setImage);
                            else
                                setImage();
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex);
                        }
                    }).Start();

                updateTitleAction();

                new System.Timers.Timer(500) { Enabled = true }.Elapsed += (s, ev) =>
                    {
                        updateTitleAction();
                    };
                tsItem.Click += (s, ev) =>
                    {
                        Settings.RaceViewer.ShowRace(race);
                    };
                addItem(tsItem);
            }

            if (racingMenuItem.DropDownItems.Count > 0 && !(racingMenuItem.DropDownItems[racingMenuItem.DropDownItems.Count - 1] is ToolStripSeparator))
                addItem(new ToolStripSeparator());

            var newRaceItem = new ToolStripMenuItem();
            newRaceItem.Text = "New Race...";
            newRaceItem.Click += NewRace_Click;
            addItem(newRaceItem);
        }
コード例 #12
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);
        }
コード例 #13
0
 public AutomaticPrecisionTimeFormatter()
 {
     InternalFormatter = new RegularTimeFormatter();
 }
コード例 #14
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);
            }
        }
コード例 #15
0
ファイル: SpeedRunsLiveIRC.cs プロジェクト: 0xwas/LiveSplit
        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);
                    if (Model.CurrentState.CurrentPhase == TimerPhase.Ended)
                    {
                        Client.LocalUser.SendMessage(LiveSplitChannel, string.Format("!done RealTime {0}", timeRTA));
                        Client.LocalUser.SendMessage(LiveSplitChannel, string.Format("!done GameTime {0}", timeIGT));
                    }
                    else
                    {
                        Client.LocalUser.SendMessage(LiveSplitChannel, string.Format("!time RealTime \"{0}\" {1}", Escape(split.Name), timeRTA));
                        Client.LocalUser.SendMessage(LiveSplitChannel, string.Format("!time GameTime \"{0}\" {1}", Escape(split.Name), timeIGT));
                    }
                }
            }

            if (RaceChannel != null)
            {
                if (Model.CurrentState.CurrentPhase == TimerPhase.Ended && RaceState == RaceState.RaceStarted)
                    Client.LocalUser.SendMessage(RaceChannel, ".done");
            }
        }