From c4d9cf341adc70b6240ed0f06bc58f5c4c028915 Mon Sep 17 00:00:00 2001 From: Scott Pruett Date: Tue, 24 May 2022 21:40:48 -0400 Subject: [PATCH] clean up car/track lists --- src/data/car-classes.txt | 1 - src/data/tracklist.txt | 1 - src/main.rs | 67 +++++++++++++++++++++++----------------- suggestions.md | 6 ++-- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/data/car-classes.txt b/src/data/car-classes.txt index a8312d5..b2f66e9 100644 --- a/src/data/car-classes.txt +++ b/src/data/car-classes.txt @@ -1,4 +1,3 @@ - Piccino Superlight Eurotruck diff --git a/src/data/tracklist.txt b/src/data/tracklist.txt index ef50cbb..3e1d3c0 100644 --- a/src/data/tracklist.txt +++ b/src/data/tracklist.txt @@ -1,4 +1,3 @@ - Whistle Valley Sugar Hill Maple Ridge diff --git a/src/main.rs b/src/main.rs index 3c85b11..094509e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,16 +81,22 @@ fn format_time(time: Duration) -> String { fn label_time_delta(ui: &mut Ui, time: Duration, old: Option) { if let Some(old) = old { - if time > old { - ui.colored_label( - Color32::LIGHT_RED, - "+".to_owned() + &format_time(time - old), - ); - } else { - ui.colored_label( - Color32::LIGHT_GREEN, - "-".to_owned() + &format_time(old - time), - ); + match time.cmp(&old) { + std::cmp::Ordering::Less => { + ui.colored_label( + Color32::LIGHT_GREEN, + "-".to_owned() + &format_time(old - time), + ); + } + std::cmp::Ordering::Equal => { + ui.colored_label( + Color32::LIGHT_RED, + "+".to_owned() + &format_time(time - old), + ); + } + std::cmp::Ordering::Greater => { + ui.label("--"); + } } } else { ui.label("--"); @@ -119,11 +125,20 @@ struct UiData { } fn split_lines(data: &str) -> Vec { - data.split('\n').map(|line| line.trim().to_owned()).collect() + let mut lines: Vec = data + .split('\n') + .map(|line| line.trim().to_owned()) + .collect(); + lines.push("".to_owned()); + lines.reverse(); + lines } impl UiData { fn load() -> Self { - Self { cars: split_lines(include_str!("data/car-classes.txt")), tracks: split_lines(include_str!("data/tracklist.txt")) } + Self { + cars: split_lines(include_str!("data/car-classes.txt")), + tracks: split_lines(include_str!("data/tracklist.txt")), + } } } @@ -169,7 +184,7 @@ fn show_race_state( ui.label(format!("#{}", lap.lap.unwrap_or(i + 1))); if Some(lap_time) == fastest_lap { - ui.colored_label(Color32::from_rgb(255, 0, 255), format_time(lap_time)); + ui.colored_label(Color32::GREEN, format_time(lap_time)); } else { ui.label(format_time(lap_time)); }; @@ -281,12 +296,7 @@ fn open_debug_lap( ocr_cache: Arc, ) { if let Some(screenshot) = &lap.screenshot { - let ocr_results = ocr::ocr_all_regions( - screenshot, - config.clone(), - learned, - ocr_cache, - ); + let ocr_results = ocr::ocr_all_regions(screenshot, config.clone(), learned, ocr_cache); let debug_lap = DebugLap { screenshot: RetainedImage::from_image_bytes("debug-lap", &to_png_bytes(screenshot)) .unwrap(), @@ -297,15 +307,10 @@ fn open_debug_lap( } } -fn show_combo_box( - ui: &mut Ui, - name: &str, - label: &str, - options: &[String], - value: &mut String -) { +fn show_combo_box(ui: &mut Ui, name: &str, label: &str, options: &[String], value: &mut String) { let mut index = options.iter().position(|e| e == value).unwrap_or(0); - egui::ComboBox::new(name, label).show_index(ui, &mut index, options.len(), |i| options[i].clone()); + egui::ComboBox::new(name, label) + .show_index(ui, &mut index, options.len(), |i| options[i].clone()); *value = options[index].clone(); } @@ -397,7 +402,13 @@ impl eframe::App for AppUi { } if !race.exported { show_combo_box(ui, "car-combo", "Car", &self.data.cars, &mut race.car); - show_combo_box(ui, "track-combo", "Track", &self.data.tracks, &mut race.track); + show_combo_box( + ui, + "track-combo", + "Track", + &self.data.tracks, + &mut race.track, + ); ui.label("Comments:"); ui.text_edit_singleline(&mut race.comments); if ui.button("Export").clicked() { diff --git a/suggestions.md b/suggestions.md index 5a1c418..82b3375 100644 --- a/suggestions.md +++ b/suggestions.md @@ -1,5 +1,7 @@ - Recognize - Penalties - Pit stops - - ComboBox for car/track - - [DONE] Global best time not current best \ No newline at end of file + - [DONE] ComboBox for car/track + - [DONE] Global best time not current best + - Best time from other racers + - Editable lap stats \ No newline at end of file