sector diffs
This commit is contained in:
1 parent
7c6c6902c5
commit
bef194280e
4 files changed
+52
-45
No files matched your search
+12
-26
@@ -9,24 +9,17 @@ using UnityEditor;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Timing: MonoBehaviour {
|
||||
[SerializeField]
|
||||
public List<Lap> lapTimes;
|
||||
[SerializeField]
|
||||
public List<SectorTime> sectorTimes;
|
||||
public bool timerEnabled;
|
||||
|
||||
public string mapName;
|
||||
public double sectorTime;
|
||||
public double lapTime;
|
||||
double sectorStart;
|
||||
double lapStart;
|
||||
public Sector[] sectors;
|
||||
|
||||
public LapStorage lapStorage;
|
||||
|
||||
public string mapName;
|
||||
|
||||
void Awake() {
|
||||
lapTimes = new();
|
||||
sectorTimes = new List<SectorTime>();
|
||||
sectorStart = 0.0;
|
||||
sectorTime = 0.0;
|
||||
@@ -36,6 +29,8 @@ public class Timing: MonoBehaviour {
|
||||
Scene scene = SceneManager.GetActiveScene();
|
||||
mapName = scene.name;
|
||||
Debug.Log("Track Sector Count - " + sectors.Length);
|
||||
|
||||
LapStorageService.GetPlayerLaps(mapName);
|
||||
}
|
||||
|
||||
void Update() {
|
||||
@@ -98,7 +93,6 @@ public class Timing: MonoBehaviour {
|
||||
}
|
||||
|
||||
void NextLap() {
|
||||
Debug.Log("NextLap" + lapTimes.Count);
|
||||
sectorTimes = new List<SectorTime>();
|
||||
StartTimer();
|
||||
}
|
||||
@@ -108,27 +102,19 @@ public class Timing: MonoBehaviour {
|
||||
if (sectorTimes == null)
|
||||
Awake();
|
||||
|
||||
Debug.Log($"Ending lap Sectors={sectorTimes.Count} Name={mapName} Lap={lapTimes.Count}");
|
||||
Lap l = new Lap { Map = mapName, Number = lapTimes.Count, Sectors = sectorTimes };
|
||||
Debug.Log($"Ending lap Sectors={sectorTimes.Count} Name={mapName}");
|
||||
Lap l = new Lap { Map = mapName, Sectors = sectorTimes };
|
||||
Debug.Log($"EndLap {l}");
|
||||
lapTimes.Add(l);
|
||||
|
||||
LapStorageService.PersistLap(l);
|
||||
Debug.Log($"Laps Stored {LapStorageService.GetPlayerLaps(mapName)}");
|
||||
}
|
||||
|
||||
public SectorColour GetSectorColour(SectorTime s) {
|
||||
if (lapTimes.Count == 0)
|
||||
return SectorColour.Green;
|
||||
|
||||
var fastestLap = lapTimes.MinBy(l => l.TotalTime());
|
||||
var fastestSector = fastestLap.Sectors.Single(fls => fls.Sector == s.Sector);
|
||||
|
||||
return (s.Seconds < fastestSector.Seconds) switch {
|
||||
true => SectorColour.Green,
|
||||
false => SectorColour.Yellow,
|
||||
};
|
||||
}
|
||||
public double PBSectorDiff(SectorTime s) => PB() switch {
|
||||
Lap pb => pb.Sectors.SingleOrDefault(fls => fls.Sector == s.Sector) switch {
|
||||
SectorTime fastestSector => s.Seconds - fastestSector.Seconds,
|
||||
null => -1d,
|
||||
},
|
||||
null => -1d,
|
||||
};
|
||||
|
||||
public Lap PB() {
|
||||
return LapStorageService.PB(mapName);
|
||||
|
||||
Reference in new issue
Block a user