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(); }
private void CheckBet(TwitchChat.User user, string argument) { if (SplitIndex < 0) { SendMessage(Settings.msgTimerNotRunning); return; } if (SplitIndex >= State.Run.Count) { SendMessage(Settings.msgCheckTimerEnd); return; } if (Bets[SplitIndex].ContainsKey(user.Name)) { var timeFormatter = new ShortTimeFormatter(); var time = Bets[SplitIndex][user.Name].Item1; var formattedTime = timeFormatter.Format(time); SendMessage(user.Name + ": Your bet for " + State.Run[SplitIndex].Name + " is " + formattedTime); } else { SendMessage(user.Name + ": You didn't bet for this split yet!"); } }
private void CalculateScore(object sender, EventArgs e) { if (CanBet) { try { var segment = State.CurrentTime - SegmentBeginning; var timeFormatter = new ShortTimeFormatter(); SendMessage("Time for this split was " + timeFormatter.Format(GetTime(segment))); Scores[State.CurrentSplitIndex - 1] = Scores[State.CurrentSplitIndex - 1] ?? (State.CurrentSplitIndex > 1 ? new Dictionary <string, int>(Scores[State.CurrentSplitIndex - 2]) : new Dictionary <string, int>()); foreach (KeyValuePair <string, Tuple <TimeSpan, double> > entry in Bets[State.CurrentSplitIndex - 1]) { if (Scores[State.CurrentSplitIndex - 1].ContainsKey(entry.Key)) { Scores[State.CurrentSplitIndex - 1][entry.Key] += (int)(entry.Value.Item2 * (int)GetTime(segment).Value.TotalSeconds *Math.Exp(-(Math.Pow((int)GetTime(segment).Value.TotalSeconds - (int)entry.Value.Item1.TotalSeconds, 2) / (int)GetTime(segment).Value.TotalSeconds))); } else { Scores[State.CurrentSplitIndex - 1].Add(entry.Key, (int)(entry.Value.Item2 * (int)GetTime(segment).Value.TotalSeconds *Math.Exp(-(Math.Pow((int)GetTime(segment).Value.TotalSeconds - (int)entry.Value.Item1.TotalSeconds, 2) / (int)GetTime(segment).Value.TotalSeconds)))); } } ShowScore(); if (State.CurrentSplitIndex < Scores.Count()) { Scores[State.CurrentSplitIndex] = new Dictionary <string, int>(Scores[State.CurrentSplitIndex - 1]); StartBets(sender, e); } } catch (Exception ex) { LogException(ex); } } }
private void CheckBet(TwitchChat.User user, string argument) { if (!CanBet) { return; } switch (State.CurrentPhase) { case TimerPhase.NotRunning: SendMessage("Timer is not running, bets are closed"); return; case TimerPhase.Ended: SendMessage("The run has ended, nothing to check!"); return; } if (Bets[State.CurrentSplitIndex].ContainsKey(user.Name)) { var timeFormatter = new ShortTimeFormatter(); var time = Bets[State.CurrentSplitIndex][user.Name].Item1; var formattedTime = timeFormatter.Format(time); SendMessage(user.Name + ", Your bet for " + State.CurrentSplit.Name + " is " + formattedTime); } else { SendMessage(user.Name + ", You didn't bet for this split yet!"); } }
public BinaryBackgroundTimer() { BigTextLabel = new SimpleLabel() { HorizontalAlignment = StringAlignment.Far, VerticalAlignment = StringAlignment.Near, Width = 493, Text = "0", }; SmallTextLabel = new SimpleLabel() { HorizontalAlignment = StringAlignment.Near, VerticalAlignment = StringAlignment.Near, Width = 257, Text = "0", }; BigMeasureLabel = new SimpleLabel() { Text = "88:88:88", IsMonospaced = true }; Formatter = new ShortTimeFormatter(); Settings = new BinaryBackgroundTimerSettings(); UpdateTimeFormat(); Cache = new GraphicsCache(); TimerColor = Color.Transparent; }
private void newSplit() { EndOfRun = false; if (!Commands.ContainsKey("bet")) { Commands.Add("bet", Bet); //Prevents players from betting between a !start and the next split, if !start is made during the run. } try { SegmentBeginning[BetIndex] = State.CurrentTime; Bets[BetIndex] = new Dictionary <string, Tuple <TimeSpan, double> >(); var timeFormatter = new ShortTimeFormatter(); var comparison = State.Run.Comparisons.Contains(Settings.TimeToShow) ? Settings.TimeToShow : Run.PersonalBestComparisonName; var previousTime = lastParent(SplitIndex) >= 0 ? GetTime(State.Run[lastParent(SplitIndex)].Comparisons[comparison]) : TimeSpan.Zero; Time timeToFormat = new Time(new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 0)); timeToFormat += State.Run[nextParent(SplitIndex)].Comparisons[comparison]; var timeFormatted = timeFormatter.Format(GetTime(timeToFormat) - previousTime); string ret = "Place your bets for " + State.Run[nextParent(SplitIndex)].Name + "! "; if (TimeSpanParser.Parse(timeFormatted) > TimeSpan.Zero && comparison != "None") { ret += CompositeComparisons.GetShortComparisonName(comparison) + " segment for this split is " + timeFormatted + " "; } if (Settings.UseGlobalTime) { ret += "And remember that global time is used to bet!"; } SendMessage(ret); } catch (Exception ex) { LogException(ex); } }
public void FormatsTimeCorrectly_WhenTimeIsNullAndNoFormatIsSupplied() { var sut = new ShortTimeFormatter(); var formattedTime = sut.Format(null); Assert.Equal("0.00", formattedTime); }
public void FormatsNullTimeInGivenFormatCorrectly(TimeFormat givenFormat) { var sut = new ShortTimeFormatter(); var formattedTime = sut.Format(null, givenFormat); Assert.Equal("0.00", formattedTime); }
public void FormatsTimeCorrectly_WhenTimeIsValidAndNoFormatIsSupplied(string timespanText, string expectedTime) { var sut = new ShortTimeFormatter(); var time = TimeSpan.Parse(timespanText); var formattedTime = sut.Format(time); Assert.Equal(expectedTime, formattedTime); }
public void FormatsTimeInSecondsByDefault_WhenTimeIsNullAndNoFormatIsSupplied() { var sut = new ShortTimeFormatter(); var defaultFormat = sut.Format(null); var formattedValueInSeconds = sut.Format(null, TimeFormat.Seconds); Assert.Equal(defaultFormat, formattedValueInSeconds); }
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 void FormatsTimeInSecondsByDefault_WhenTimeIsValidAndNoFormatIsSupplied(string timespanText) { var sut = new ShortTimeFormatter(); var time = TimeSpan.Parse(timespanText); var defaultFormat = sut.Format(time); var formattedTimeInSeconds = sut.Format(time, TimeFormat.Seconds); Assert.Equal(defaultFormat, formattedTimeInSeconds); }
private void CalculateScore(object sender, EventArgs e) { BackgroundWorker invoker = new BackgroundWorker(); invoker.DoWork += delegate { Thread.Sleep(TimeSpan.FromSeconds(Settings.Delay)); try { Winners = new Dictionary <string, Tuple <int, string> >(); //TODO Hide the "Time for this split was..." message if the segment time is <= 0 (yes it can happen) var segment = State.CurrentTime - SegmentBeginning[BetIndex]; //Add delay time to the last split if (SplitIndex >= State.Run.Count()) { segment += new Time(new TimeSpan(0, 0, Settings.Delay), new TimeSpan(0, 0, Settings.Delay)); } var timeFormatter = new ShortTimeFormatter(); TimeSpan?segmentTimeSpan = GetTime(segment); SendMessage("The time for this split was " + timeFormatter.Format(segmentTimeSpan)); Scores[BetIndex] = Scores[BetIndex] ?? (BetIndex > 0 ? new Dictionary <string, int>(Scores[BetIndex - 1]) : new Dictionary <string, int>()); foreach (KeyValuePair <string, Tuple <TimeSpan, double> > entry in Bets[BetIndex]) { double score = getScore(entry, segmentTimeSpan); if (Scores[BetIndex].ContainsKey(entry.Key)) { Scores[BetIndex][entry.Key] += (int)score; } else { Scores[BetIndex].Add(entry.Key, (int)score); } var timeformat = new ShortTimeFormatter(); var time = entry.Value.Item1; var formattedTime = timeFormatter.Format(time); Winners.Add(entry.Key, new Tuple <int, string>((int)score, formattedTime)); } ShowScore(); if (++BetIndex < Scores.Count()) { newSplit(); } else { EndOfRun = true; } } catch (Exception ex) { LogException(ex); } }; invoker.RunWorkerAsync(); }
public VideoSettings() { InitializeComponent(); TimeFormatter = new ShortTimeFormatter(); VideoPath = ""; Width = 200; Height = 200; Offset = TimeSpan.Zero; txtVideoPath.DataBindings.Add("Text", this, "VideoPath", false, DataSourceUpdateMode.OnPropertyChanged); txtOffset.DataBindings.Add("Text", this, "OffsetString"); }
public void TestShortTimeFormatterWithTimeFormat(string timespanText, TimeFormat format, string expected) { var formatter = new ShortTimeFormatter(); TimeSpan?time = null; if (timespanText != null) { time = TimeSpan.Parse(timespanText); } string formatted = formatter.Format(time, format); Assert.AreEqual(expected, formatted); }
private static string formatTime(Time time) { var formatter = new ShortTimeFormatter(); if (time.RealTime.HasValue && !time.GameTime.HasValue) { return(formatter.Format(time.RealTime)); } if (!time.RealTime.HasValue && time.GameTime.HasValue) { return(formatter.Format(time.GameTime)); } return(formatter.Format(time.RealTime) + " / " + formatter.Format(time.GameTime)); }
public Timer() { BigTextLabel = new SimpleLabel() { HorizontalAlignment = StringAlignment.Far, VerticalAlignment = StringAlignment.Near, Width = 493, Text = "0", }; SmallTextLabel = new SimpleLabel() { HorizontalAlignment = StringAlignment.Near, VerticalAlignment = StringAlignment.Near, Width = 257, Text = "0", }; DeathsLabel = new DeathCountLabel() { Text = "0", Width = 400, IsMonospaced = true, HorizontalAlignment = StringAlignment.Near, VerticalAlignment = StringAlignment.Near }; MeasureDeathsLabel = new DeathCountLabel() { Text = "9999", IsMonospaced = true }; BigMeasureLabel = new SimpleLabel() { Text = "88:88:88", IsMonospaced = true }; Formatter = new ShortTimeFormatter(); Settings = new TimerSettings(); UpdateTimeFormat(); Cache = new GraphicsCache(); TimerColor = Color.Transparent; DeathCountColor = Color.Transparent; DeathsLabelVisible = true; }
/*The CanBet check might break stuff if you enable the bets in the middle of a run. If someone has a better solution, go for it*/ private void StartBets(object sender, EventArgs e) { if (CanBet) { try { SegmentBeginning = State.CurrentTime; Bets[State.CurrentSplitIndex] = new Dictionary <string, Tuple <TimeSpan, double> >(); var timeFormatter = new ShortTimeFormatter(); var timeFormatted = timeFormatter.Format(GetTime(State.CurrentSplit.BestSegmentTime)); SendMessage("Place your bets for " + State.CurrentSplit.Name + "!" + (TimeSpanParser.Parse(timeFormatted) > new TimeSpan(0, 0, 0) ? (" Best segment for this split is " + timeFormatted + (Settings.UseGlobalTime?" but remember that global time is used!":"")) : " No best segment for this split :(")); } catch (Exception ex) { LogException(ex); } } }
public void TestShortTimeFormatter(string timespanText, string expected) { var formatter = new ShortTimeFormatter(); TimeSpan?time = null; if (timespanText != null) { time = TimeSpan.Parse(timespanText); } string formatted = formatter.Format(time); Assert.AreEqual(expected, formatted); // test if it's the same as using TimeFormat.Seconds too string formatted2 = formatter.Format(time, TimeFormat.Seconds); Assert.AreEqual(formatted2, formatted); }
//Commands usually have self explaining names /** * Register a bet for the player "user" */ private void Bet(TwitchChat.User user, string argument) { //Check the state of the timer. It must be running to set a bet if (SplitIndex < 0) { SendMessage(Settings.msgTimerNotRunning); return; } if (State.CurrentPhase == TimerPhase.Paused) { SendMessage(Settings.msgTimerPaused); return; } if (SplitIndex >= State.Run.Count) { SendMessage(Settings.msgTimerEnded); return; } //You can't bet again if you have already bet once, unless you type !unbet, which erases your bet (and some of your points) if (Bets[BetIndex].ContainsKey(user.Name)) { SendMessage(user.Name + ": You already bet!"); return; } double percentage; var timeFormatted = new ShortTimeFormatter().Format(GetTime(State.Run[SplitIndex].BestSegmentTime)); //If no glod is set, percentage is kept to 0. There's no way to set a limit so better not fix an arbitrary one. if (TimeSpanParser.Parse(timeFormatted) > TimeSpan.Zero) { percentage = (GetTime(State.CurrentTime - SegmentBeginning[BetIndex])).Value.TotalSeconds / GetTime(State.Run[BetIndex].BestSegmentTime).Value.TotalSeconds; } else { percentage = 0; } //Forbids the bets if the time of the segment reaches over 75% of the best segment if (percentage > 0.75) { SendMessage(Settings.msgTooLateToBet); return; } try { //nice meme if (argument.ToLower().StartsWith("kappa")) { argument = "4:20.69"; SendMessage(user.Name + " bet 4:20.69 Kappa"); } //Parsing the time and checking if it's valid var time = TimeSpanParser.Parse(argument); if (Settings.UseGlobalTime) { time -= GetTime(SegmentBeginning[SplitIndex]).Value; } if (time.CompareTo(Settings.MinimumTime) <= 0) { SendMessage(user.Name + ": Invalid time, please retry."); return; } //Add the bet to its Dictionary var t = new Tuple <TimeSpan, double>(time, Math.Exp(-2 * Math.Pow(percentage, 4))); Bets[BetIndex].Add(user.Name, t); } catch { SendMessage(user.Name + ": Invalid time, please retry."); } }
public SplitEventsEditorForm(LiveSplitState splitStates, SplitsToEvents splitToEvents) { this.splitStates = splitStates; this.splitToEvents = splitToEvents; InitializeComponent(); this.DialogResult = DialogResult.Cancel; var verficationResult = splitToEvents.Verify(splitStates); if (verficationResult != "") { //MessageBox.Show("Verification found following issues:\n" + verficationResult, "Notification", MessageBoxButtons.OK); } #region Setting up grid TimeFormatter = new ShortTimeFormatter(); splitToEventList = new BindingList <ISplitEvent>(splitToEvents.EventList.Cast <ISplitEvent>().ToList()) { AllowNew = false, AllowRemove = false }; grid_SplitSettings.AutoGenerateColumns = false; grid_SplitSettings.AutoSize = true; grid_SplitSettings.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; grid_SplitSettings.DataSource = splitToEventList; grid_SplitSettings.CellClick += Grid_SplitSettings_CellClick; grid_SplitSettings.CellFormatting += Grid_SplitSettings_CellFormatting; grid_SplitSettings.CellParsing += Grid_SplitSettings_CellParsing; grid_SplitSettings.CellValidating += Grid_SplitSettings_CellValidating; grid_SplitSettings.CellEndEdit += Grid_SplitSettings_CellEndEdit; grid_SplitSettings.SelectionChanged += Grid_SplitSettings_SelectionChanged; var segmentNameColumn = new DataGridViewTextBoxColumn(); segmentNameColumn.Name = "Segment Name"; segmentNameColumn.Width = 350; segmentNameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; segmentNameColumn.SortMode = DataGridViewColumnSortMode.NotSortable; grid_SplitSettings.Columns.Add(segmentNameColumn); var eventTypeColumn = new DataGridViewComboBoxColumn(); //Hide your children eventTypeColumn.Items.AddRange(Enum.GetValues(typeof(SplitEventType)).Cast <Enum>().Select(value => new { (Attribute.GetCustomAttribute(value.GetType().GetField(value.ToString()), typeof(DescriptionAttribute)) as DescriptionAttribute).Description }.Description).ToArray()); eventTypeColumn.Name = "Event Type"; eventTypeColumn.Width = 200; eventTypeColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; eventTypeColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; eventTypeColumn.SortMode = DataGridViewColumnSortMode.NotSortable; grid_SplitSettings.Columns.Add(eventTypeColumn); var eventDelayColumn = new DataGridViewTextBoxColumn(); eventDelayColumn.Name = "Event delay"; eventDelayColumn.Width = 80; eventDelayColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; eventDelayColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; eventDelayColumn.SortMode = DataGridViewColumnSortMode.NotSortable; grid_SplitSettings.Columns.Add(eventDelayColumn); var eventActionColumn = new DataGridViewButtonColumn(); eventActionColumn.Name = "Action"; eventActionColumn.Width = 50; eventActionColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; eventActionColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; eventActionColumn.SortMode = DataGridViewColumnSortMode.NotSortable; grid_SplitSettings.Columns.Add(eventActionColumn); grid_SplitSettings.EditingControlShowing += Grid_SplitSettings_EditingControlShowing; #endregion AddComboboxDataSources(); CBox_OnRunReset.DataBindings.Add("SelectedValue", this.splitToEvents, "OnTimerResetBehaviour", false, DataSourceUpdateMode.OnPropertyChanged); CBox_RunCompletion.DataBindings.Add("SelectedValue", this.splitToEvents, "OnRunCompletion", false, DataSourceUpdateMode.OnPropertyChanged); CB_UsePBPrediction.DataBindings.Add("Checked", this.splitToEvents, "UsePBPrediction", false, DataSourceUpdateMode.OnPropertyChanged); CB_NotifyOfErrorsInChat.DataBindings.Add("Checked", this.splitToEvents, "NotifyOfErrorsInChat", false, DataSourceUpdateMode.OnPropertyChanged); TB_OnCompletionDelay.DataBindings.Add("Text", this, "EndSplitOffset"); }