diff --git a/Assets/Src/LapService.cs b/Assets/Src/LapService.cs index 72fc8e8..107ba14 100644 --- a/Assets/Src/LapService.cs +++ b/Assets/Src/LapService.cs @@ -26,6 +26,16 @@ public class LapService { public Lap Pb; public Lap LapRecord; + public string Position => _pb switch { + PbDTO pb => pb.Position.ToString(), + null => "-", + }; + + public string Completions => _lr switch { + PbDTO lr => lr.Completions.ToString(), + null => "-", + }; + public LapService(string mapName) { _mapName = mapName; LoadPlayerData(); @@ -54,15 +64,17 @@ public class LapService { _pb = dto.Pb; _lr = dto.LapRecord; - Pb = new Lap { - Map = _pb.Map, - Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), - }; + if (dto.Pb != null) + Pb = new Lap { + Map = _pb.Map, + Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), + }; - LapRecord = new Lap { - Map = _lr.Map, - Sectors = _lr.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), - }; + if (dto.LapRecord != null) + LapRecord = new Lap { + Map = _lr.Map, + Sectors = _lr.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), + }; } catch (Exception e) { Debug.LogWarning($"Failed to set lap times {e}"); _pb = null; diff --git a/Assets/Src/Laps.cs b/Assets/Src/Laps.cs index 13ace3b..2c2ba82 100644 --- a/Assets/Src/Laps.cs +++ b/Assets/Src/Laps.cs @@ -18,10 +18,10 @@ public class TimingNotice { NoticeCategory Category = NoticeCategory.Initial; public static TimingNotice Compare(double seconds, double? pbSeconds = null, double? lrSeconds = null) => lrSeconds switch { - double lr when seconds < lr => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Fastest }, + double lr when seconds < lr => new TimingNotice { Seconds = Math.Abs(lr - seconds), Category = NoticeCategory.Fastest }, _ => pbSeconds switch { - double pb when seconds < pb => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Faster }, - double pb when seconds >= pb => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Slower }, + double pb when seconds < pb => new TimingNotice { Seconds = Math.Abs(pb - seconds), Category = NoticeCategory.Faster }, + double pb when seconds >= pb => new TimingNotice { Seconds = Math.Abs(pb - seconds), Category = NoticeCategory.Slower }, _ => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Initial }, } }; diff --git a/Assets/Src/ShipControls.cs b/Assets/Src/ShipControls.cs index e72320c..787a81c 100755 --- a/Assets/Src/ShipControls.cs +++ b/Assets/Src/ShipControls.cs @@ -200,6 +200,20 @@ public class ShipControls : MonoBehaviour { input.ship.powerUnit4.started += OnPowerUnit4; } + void OnDestroy() { + input.ship.strafe.started -= OnStrafe; + input.ship.strafe.performed -= OnStrafe; + input.ship.strafe.canceled -= OnStrafe; + + // these we only care about the initial press + input.ship.respawn.started -= OnRespawn; + input.ship.quit.started -= OnQuit; + input.ship.powerUnit1.started -= OnPowerUnit1; + input.ship.powerUnit2.started -= OnPowerUnit2; + input.ship.powerUnit3.started -= OnPowerUnit3; + input.ship.powerUnit4.started -= OnPowerUnit4; + } + void OnStrafe(InputAction.CallbackContext ctx) { Vector2 str = ctx.ReadValue(); strafe = new Vector3(str.x, str.y, 0f) * powerUnit.Strafing; diff --git a/Assets/Src/Timing.cs b/Assets/Src/Timing.cs index 74aa656..0fab064 100644 --- a/Assets/Src/Timing.cs +++ b/Assets/Src/Timing.cs @@ -26,6 +26,8 @@ public class Timing: MonoBehaviour { IEnumerator noticeLifecycle; + public string Position => $"{lapService.Position} / {lapService.Completions}"; + void Awake() { ui = GetComponent(); sectorTimes = new List(); @@ -42,6 +44,7 @@ public class Timing: MonoBehaviour { } void Start() { + Debug.Log("Timing Starting..."); StartCoroutine(lapService.GetLapTimes()); } diff --git a/Assets/Src/UI/Timing.uxml b/Assets/Src/UI/Timing.uxml index 027b153..827c48c 100644 --- a/Assets/Src/UI/Timing.uxml +++ b/Assets/Src/UI/Timing.uxml @@ -1,14 +1,18 @@