summaryrefslogtreecommitdiffstats
path: root/gui/src
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/crash.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/gui/src/crash.rs b/gui/src/crash.rs
index 08113a8..a73c3bd 100644
--- a/gui/src/crash.rs
+++ b/gui/src/crash.rs
@@ -2,9 +2,18 @@
2 2
3use eframe::egui::{Align2, Color32, Pos2, Rect, Sense, Shape, Stroke, StrokeKind, Ui, pos2, vec2}; 3use eframe::egui::{Align2, Color32, Pos2, Rect, Sense, Shape, Stroke, StrokeKind, Ui, pos2, vec2};
4use zagan_bet::client::view::{Command, CrashView}; 4use zagan_bet::client::view::{Command, CrashView};
5use zagan_bet::crash::{crash_point_from_seed, seed_from_hex, verify_seed};
5 6
6use crate::{theme, widgets}; 7use crate::{theme, widgets};
7 8
9fn short_hash(hash: &str) -> String {
10 hash.char_indices()
11 .nth(12)
12 .map(|(index, _)| &hash[..index])
13 .unwrap_or(hash)
14 .to_string()
15}
16
8/// One sample of the running curve. 17/// One sample of the running curve.
9struct Sample { 18struct Sample {
10 seconds: f32, 19 seconds: f32,
@@ -136,6 +145,31 @@ fn sidebar(ui: &mut Ui, view: &CrashView, fx: &mut Fx) -> Option<Command> {
136 theme::GOLD, 145 theme::GOLD,
137 ); 146 );
138 147
148 if let Some(commit) = &view.commit {
149 widgets::row(ui, "Commit", &short_hash(commit), theme::TEXT_FAINT);
150 }
151 if let Some(seed) = &view.seed {
152 let commit_ok = view
153 .commit
154 .as_deref()
155 .map(|commit| verify_seed(seed, commit))
156 .unwrap_or(false);
157 let point_ok = seed_from_hex(seed)
158 .map(|bytes| {
159 view.crash_point
160 .map(|point| {
161 (crash_point_from_seed(&bytes) - point).abs() < 1e-9
162 })
163 .unwrap_or(false)
164 })
165 .unwrap_or(false);
166 if commit_ok && point_ok {
167 widgets::row(ui, "Seed ✓", &short_hash(seed), theme::WIN);
168 } else {
169 widgets::row(ui, "Seed ✗", &short_hash(seed), theme::LOSS);
170 }
171 }
172
139 ui.add_space(theme::SPACE_3); 173 ui.add_space(theme::SPACE_3);
140 status(ui, view); 174 status(ui, view);
141 175