private void Finished(object sender, FinishedEventArgs e) { if (e.Type != RaceEndType.Finished) { return; } _finished = true; var finished = new SplitTime(_previousCheckpointTimes.LastOrDefault(), TimeSpan.FromMilliseconds(e.FinalTime), -1); _previousCheckpointTimes.Add(finished); if (Settings.GetItem <bool>("SaveTimes")) { if (_bestTime == TimeSpan.Zero || finished.Total < _bestTime) { WriteTimes("pb.txt"); } if (Settings.GetItem <bool>("SaveAllTimes")) { WriteTimes(finished.RenderFilename()); } } }
public void SetTimeBarText(SplitTime previousBest, float delay) { if (previousBest.Rounded.Total < Rounded.Total) { LocalVehicle.Screen.SetTimeBarText("+" + Render(Rounded.Total - previousBest.Rounded.Total, 2, ':') + " ", "#FF0000", delay); } else if (previousBest.Rounded.Total > Rounded.Total) { LocalVehicle.Screen.SetTimeBarText("-" + Render(previousBest.Rounded.Total - Rounded.Total, 2, ':') + " ", "#00FF00", delay); } else { SetTimeBarText(delay); } }
public SplitTime(SplitTime oldTime, TimeSpan newTime, int checkpointId) { _old = oldTime.Total; _new = newTime; CheckpointId = checkpointId; if (_old == TimeSpan.Zero) { LastCheckpointId = -1; } else { LastCheckpointId = oldTime.CheckpointId; } }
public string RenderHud(SplitTime previousBest) { var output = new System.Text.StringBuilder(); output.Append("<size=25>"); if (previousBest.Rounded.Total < Rounded.Total) { output.Append("<color=#de6262ff>"); } else if (previousBest.Rounded.Total > Rounded.Total) { output.Append("<color=#6be584ff>"); } output.Append(Render(Total)); if (previousBest.Rounded.Total != Rounded.Total) { output.Append("</color>"); } output.Append("</size> "); if (LastCheckpointId == previousBest.LastCheckpointId) { if (previousBest.Rounded.Split < Rounded.Split) { output.Append("<color=#de6262ff>"); } else if (previousBest.Rounded.Split > Rounded.Split) { output.Append("<color=#6be584ff>"); } } output.Append(Render(Split)); if (LastCheckpointId == previousBest.LastCheckpointId && previousBest.Rounded.Split != Rounded.Split) { output.Append("</color>"); } return(output.ToString()); }
private void CheckpointPassed(object sender, CheckpointHitEventArgs e) { var now = new SplitTime(_previousCheckpointTimes.LastOrDefault(), Race.ElapsedTime, e.CheckpointIndex); _previousCheckpointTimes.Add(now); if (_bestCheckpointTimes.ContainsKey(e.CheckpointIndex)) { now.SetTimeBarText(_bestCheckpointTimes[e.CheckpointIndex], 1.25f); } else { now.SetTimeBarText(1.25f); } var times = GetTimeStrings(); times.Insert(0, "<size=57><color=#6be584ff>Regenerating</color></size>"); HudLinesDownward(2.0f, times); }
private void Started(object sender, EventArgs e) { _finished = false; _previousCheckpointTimes.Clear(); _bestCheckpointTimes?.Clear(); _bestTime = TimeSpan.Zero; if (Settings.GetItem <bool>("SaveTimes")) { _trackFolder = SplitTime.GetSavePath( G.Sys.GameManager_.Level_, G.Sys.GameManager_.Mode_, G.Sys.PlayerManager_.Current_.profile_ ); _bestCheckpointTimes = ReadTimes("pb.txt"); if (_bestCheckpointTimes.ContainsKey(-1)) { _bestTime = _bestCheckpointTimes[-1].Total; } } }
private Dictionary <int, SplitTime> ReadTimes(string filename) { var output = new Dictionary <int, SplitTime>(); try { if (File.Exists(Path.Combine(FileSystem.DirectoryPath, Path.Combine(_trackFolder, filename)))) { using (var sr = new StreamReader(Path.Combine(FileSystem.DirectoryPath, Path.Combine(_trackFolder, filename)))) { string[] line; var oldCheckpoint = -1; while ((line = sr.ReadLine()?.Split('\t')) != null) { var total = TimeSpan.Parse("00:" + line[0]); var split = TimeSpan.Parse("00:" + line[1]); var checkpoint = -1; if (line.Length == 3) { checkpoint = int.Parse(line[2]); } output[checkpoint] = new SplitTime(total - split, total, checkpoint, oldCheckpoint); oldCheckpoint = checkpoint; } } } } catch (Exception ex) { Console.WriteLine($"Spectrum.Plugins.SplitTimes: Couldn't load times. Exception below:\n{ex}"); } return(output); }