Files
spacerace/Assets/Src/Laps.cs
T
2023-08-29 21:05:43 +10:00

79 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using UnityEngine;
using UnityEngine.UIElements;
public enum NoticeCategory {
Initial,
Slower,
Faster,
Fastest,
}
public class TimingNotice {
public 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 Label ToLabel() {
Label l = Category switch {
NoticeCategory.Initial => new Label($"{TimeSpan.FromSeconds(Seconds):m\\:ss\\.fff}"),
NoticeCategory.Slower => new Label($"+{Seconds:0.000}"),
NoticeCategory.Faster => new Label($"-{Seconds:0.000}"),
NoticeCategory.Fastest => new Label($"-{Seconds:0.000}"),
_ => new Label($"-{Seconds:0.000}"),
};
string colourClass = Category switch {
NoticeCategory.Initial => "",
NoticeCategory.Slower => "yellow",
NoticeCategory.Faster => "green",
NoticeCategory.Fastest => "purple",
_ => "",
};
l.AddToClassList(colourClass);
return l;
}
}
public enum DiffColour {
Green,
Purple,
White,
Yellow,
}
public class SectorTime {
public int Sector;
public double Seconds;
public override string ToString() => $"{Seconds:0.000}";
}
public class Lap {
public string Map;
public List<SectorTime> Sectors;
// 0:1:39
public override string ToString() {
return $"{TimeSpan.FromSeconds(TotalTime):m\\:ss\\.fff}";
}
public double TotalTime => Sectors.Sum(s => s.Seconds);
}