From 6450d3b0937f6b855a4b850b3b201a8ede76e149 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 29 Aug 2023 21:26:03 +1000 Subject: [PATCH] awake todo --- Assets/Src/Timing.cs | 15 ++++++++++++--- Assets/Src/UI/TimingUI.cs | 8 ++------ TODO.md | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Assets/Src/Timing.cs b/Assets/Src/Timing.cs index fbd7bdb..cb12bc1 100644 --- a/Assets/Src/Timing.cs +++ b/Assets/Src/Timing.cs @@ -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 }, }; diff --git a/Assets/Src/UI/TimingUI.cs b/Assets/Src/UI/TimingUI.cs index 191d369..f22e1a7 100644 --- a/Assets/Src/UI/TimingUI.cs +++ b/Assets/Src/UI/TimingUI.cs @@ -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()); diff --git a/TODO.md b/TODO.md index 89479e8..0caeeb2 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,13 @@ # SpaceRace! - post times to server + - update on scene change - check time is lower when posting - return pb and lap record - convert laps to lapDTO? - include sectors -- controls diagram +- controls - mouse / controller sens - invert y