awake todo

This commit is contained in:
ntr committed 2023-08-29 21:26:03 +10:00
1 parent cebc2ef588
commit 6450d3b093
3 files changed
+16 -10

No files matched your search

+12 -3
View File
@@ -39,6 +39,9 @@ public class Timing: MonoBehaviour {
Debug.Log("Track Sector Count - " + sectors.Length);
lapService = new LapService(mapName);
}
void Start() {
StartCoroutine(lapService.GetPb());
}
@@ -131,9 +134,15 @@ public class Timing: MonoBehaviour {
ui.HideRecentLap();
}
public Lap PB => lapService.PB;
public Lap PB() {
if (lapService == null) {
Debug.LogWarning("null lapservice");
return null;
}
return lapService.PB;
}
public TimingNotice PBSectorDiff(SectorTime s) => PB switch {
public TimingNotice PBSectorDiff(SectorTime s) => PB() switch {
Lap pb => pb.Sectors.SingleOrDefault(fls => fls.Sector == s.Sector) switch {
SectorTime fastestSector => (new TimingNotice { Seconds = s.Seconds }).Compare(fastestSector.Seconds),
null => new TimingNotice { Seconds = s.Seconds }, // this one should never happen
@@ -141,7 +150,7 @@ public class Timing: MonoBehaviour {
null => new TimingNotice { Seconds = s.Seconds }, // there is no pb
};
public TimingNotice PBLapDiff(Lap lap) => PB switch {
public TimingNotice PBLapDiff(Lap lap) => PB() switch {
Lap pb => (new TimingNotice { Seconds = lap.TotalTime }).Compare(pb.TotalTime),
null => new TimingNotice { Seconds = lap.TotalTime },
};
+2 -6
View File
@@ -48,7 +48,7 @@ public class TimingUI : MonoBehaviour {
}
void FixedUpdate() {
if (timer == null) {
if (timer == null || timing == null) {
Debug.LogWarning("no timer");
Init();
return;
@@ -64,7 +64,7 @@ public class TimingUI : MonoBehaviour {
if (timerSectors == null)
Debug.LogWarning("null timerSectors");
Lap timerPbLap = timing.PB;
Lap timerPbLap = timing.PB();
if (timerPbLap != null)
timerPb.text = $"{timerPbLap.ToString()}";
@@ -85,11 +85,7 @@ public class TimingUI : MonoBehaviour {
timer.AddToClassList("hidden");
notice.RemoveFromClassList("hidden");
// fine
noticeTime.text = lap.ToString();
// should show the diff to the PB
// or - if there is only 1 lap
noticeDiff.Clear();
noticeDiff.Add(timing.PBLapDiff(lap).ToLabel());