LapService

This commit is contained in:
ntr committed 2023-08-29 21:05:43 +10:00
1 parent 18ee18f78f
commit 2980cb9e4e
8 files changed
+63 -125

No files matched your search

+7 -11
View File
@@ -11,6 +11,7 @@ using UnityEngine.SceneManagement;
public class Timing: MonoBehaviour {
TimingUI ui;
LapService lapService;
public List<SectorTime> sectorTimes;
public bool timerEnabled;
@@ -25,8 +26,6 @@ public class Timing: MonoBehaviour {
IEnumerator noticeLifecycle;
LapFetchService lapFetchService;
void Awake() {
ui = GetComponent<TimingUI>();
sectorTimes = new List<SectorTime>();
@@ -39,10 +38,8 @@ public class Timing: MonoBehaviour {
mapName = scene.name;
Debug.Log("Track Sector Count - " + sectors.Length);
LapStorageService.GetPlayerLaps(mapName);
lapFetchService = new LapFetchService(mapName);
StartCoroutine(lapFetchService.GetPb());
lapService = new LapService(mapName);
StartCoroutine(lapService.GetPb());
}
void Update() {
@@ -125,8 +122,7 @@ public class Timing: MonoBehaviour {
noticeLifecycle = RecentLapLifecycle(l);
StartCoroutine(noticeLifecycle);
LapStorageService.PersistLap(l);
StartCoroutine(lapFetchService.PostLap(l));
StartCoroutine(lapService.PostLap(l));
}
IEnumerator RecentLapLifecycle(Lap l) {
@@ -135,9 +131,9 @@ public class Timing: MonoBehaviour {
ui.HideRecentLap();
}
public Lap PB() => LapStorageService.PB(mapName);
public Lap PB => 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
@@ -145,7 +141,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 },
};