smoke purpp

This commit is contained in:
ntr committed 2023-08-31 16:55:31 +10:00
1 parent dba4e3fe2b
commit d086069e18
9 files changed
+92 -85

No files matched your search

+9 -3
View File
@@ -23,7 +23,8 @@ public class LapService {
PbDTO _pb;
PbDTO _lr;
public Lap PB;
public Lap Pb;
public Lap LapRecord;
public LapService(string mapName) {
_mapName = mapName;
@@ -53,15 +54,20 @@ public class LapService {
_pb = dto.Pb;
_lr = dto.LapRecord;
PB = new Lap {
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(),
};
} catch (Exception e) {
Debug.LogWarning($"Failed to set lap times {e}");
_pb = null;
_lr = null;
PB = null;
Pb = null;
}
}
+9 -13
View File
@@ -14,21 +14,17 @@ public enum NoticeCategory {
}
public class TimingNotice {
public double Seconds;
double Seconds;
NoticeCategory Category = NoticeCategory.Initial;
public TimingNotice Compare(double comparison) {
double s = Math.Abs(comparison - Seconds);
NoticeCategory cat = comparison switch {
double c when Seconds < c => NoticeCategory.Faster,
_ => NoticeCategory.Slower,
};
return new TimingNotice {
Seconds = s,
Category = cat,
};
}
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 },
_ => 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 },
_ => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Initial },
}
};
public Label ToLabel() {
Label l = Category switch {
+24 -17
View File
@@ -134,26 +134,33 @@ public class Timing: MonoBehaviour {
ui.HideRecentLap();
}
public Lap PB() {
if (lapService == null) {
Debug.LogWarning("null lapservice");
return null;
}
return lapService.PB;
public Lap LapRecord => lapService.LapRecord;
public Lap Pb => lapService.Pb;
public TimingNotice CompareLap(Lap lap) {
double? lrSeconds = LapRecord != null ? LapRecord.TotalTime : null;
double? pbSeconds = Pb != null ? Pb.TotalTime : null;
return TimingNotice.Compare(lap.TotalTime, pbSeconds, lrSeconds);
}
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
},
null => new TimingNotice { Seconds = s.Seconds }, // there is no pb
};
public TimingNotice CompareSector(SectorTime s) {
double? lrSeconds = LapRecord switch {
null => null,
Lap lr => lr.Sectors.SingleOrDefault(lrs => lrs.Sector == s.Sector) switch {
SectorTime lrSector => lrSector.Seconds,
_ => null,
},
};
public TimingNotice PBLapDiff(Lap lap) => PB() switch {
Lap pb => (new TimingNotice { Seconds = lap.TotalTime }).Compare(pb.TotalTime),
null => new TimingNotice { Seconds = lap.TotalTime },
};
double? pbSeconds = Pb switch {
null => null,
Lap pb => pb.Sectors.SingleOrDefault(pbs => pbs.Sector == s.Sector) switch {
SectorTime pbSector => pbSector.Seconds,
_ => null,
},
};
return TimingNotice.Compare(s.Seconds, pbSeconds, lrSeconds);
}
}
+4 -4
View File
@@ -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()}";
@@ -73,7 +73,7 @@ public class TimingUI : MonoBehaviour {
foreach (Sector sector in timing.sectors) {
Label l = timing.sectorTimes
.Where(s => s.Sector == sector.sector)
.Select(s => timing.PBSectorDiff(s).ToLabel())
.Select(s => timing.CompareSector(s).ToLabel())
.DefaultIfEmpty(new Label("-"))
.Single();
@@ -87,11 +87,11 @@ public class TimingUI : MonoBehaviour {
noticeTime.text = lap.ToString();
noticeDiff.Clear();
noticeDiff.Add(timing.PBLapDiff(lap).ToLabel());
noticeDiff.Add(timing.CompareLap(lap).ToLabel());
noticeSectors.Clear();
foreach (SectorTime sector in lap.Sectors) {
Label l = timing.PBSectorDiff(sector).ToLabel();
Label l = timing.CompareSector(sector).ToLabel();
noticeSectors.Add(l);
}
}