sector diffs

This commit is contained in:
ntr committed 2023-08-01 18:04:18 +10:00
1 parent 42fcc9fe1b
commit 758ee8e8b2
4 files changed
+52 -45

No files matched your search

+25 -7
View File
@@ -28,6 +28,8 @@ public class TimingUI : MonoBehaviour {
timer = uiDocument.rootVisualElement.Q<Label>("timer");
pb = uiDocument.rootVisualElement.Q<Label>("pb");
sectors = uiDocument.rootVisualElement.Q<VisualElement>("sectors");
pb.text = "-";
}
void FixedUpdate() {
@@ -47,22 +49,38 @@ public class TimingUI : MonoBehaviour {
if (sectors == null)
Debug.LogWarning("null sectors");
pb.text = $"PB: {timing.PB().ToString()}";
Lap pbLap = timing.PB();
if (pbLap != null)
pb.text = $"{pbLap.ToString()}";
sectors.Clear();
foreach (Sector sector in timing.sectors) {
Label l = timing.sectorTimes
.Where(s => s.Sector == sector.sector)
.Select(s => {
Label l = new Label($"{s}");
string colourClass = timing.GetSectorColour(s).ToString().ToLowerInvariant();
l.AddToClassList(colourClass);
return l;
})
.Select(s => SectorLabel(s))
.DefaultIfEmpty(new Label("-"))
.Single();
sectors.Add(l);
}
}
Label SectorLabel(SectorTime s) {
double diff = timing.PBSectorDiff(s);
string sign = diff switch {
< 0 => "",
_ => "+",
};
SectorColour colour = diff switch {
< 0 => SectorColour.Green,
_ => SectorColour.Yellow,
};
Label l = new Label($"{sign}{diff:0.000}");
string colourClass = colour.ToString().ToLowerInvariant();
l.AddToClassList(colourClass);
return l;
}
}