This commit is contained in:
ntr committed 2023-08-04 16:00:10 +10:00
1 parent d97efd0e88
commit c61fd84f90
4 files changed
+57 -50

No files matched your search

+41 -19
View File
@@ -4,6 +4,7 @@ using System.Linq;
using System.IO;
using UnityEngine;
using UnityEngine.UIElements;
public enum NoticeCategory {
Initial,
@@ -12,27 +13,42 @@ public enum NoticeCategory {
Fastest,
}
// public record TimingNotice(
// double Seconds,
// NoticeCategory Category,
// ) {
// Label ToLabel() {
// Label l = Category switch {
// DiffType.Slower => new Label($"+{diff:0.000}"),
// DiffType.Faster => new Label($"-{diff:0.000}"),
// DiffType.Fastest => new Label($"-{diff:0.000}"),
// };
public class TimingNotice {
public double Seconds;
NoticeCategory Category = NoticeCategory.Initial;
// string colourClass = Category Switch {
// DiffType.Slower => "yellow",
// DiffType.Faster => "green",
// DiffType.Fastest => "purple",
// };
public TimingNotice Compare(double comparison) {
double s = Math.Abs(comparison - Seconds);
NoticeCategory cat = comparison switch {
double c when Seconds < c => NoticeCategory.Faster,
_ => NoticeCategory.Slower,
};
// l.AddToClassList(colourClass);
// return l;
// }
// }
return new TimingNotice {
Seconds = s,
Category = cat,
};
}
public Label ToLabel() {
Label l = Category switch {
NoticeCategory.Slower => new Label($"+{Seconds:0.000}"),
NoticeCategory.Faster => new Label($"-{Seconds:0.000}"),
NoticeCategory.Fastest => new Label($"-{Seconds:0.000}"),
NoticeCategory.Initial => new Label($"{TimeSpan.FromSeconds(Seconds):m\\:ss\\.fff}"),
};
string colourClass = Category switch {
NoticeCategory.Slower => "yellow",
NoticeCategory.Faster => "green",
NoticeCategory.Fastest => "purple",
NoticeCategory.Initial => "",
};
l.AddToClassList(colourClass);
return l;
}
}
public enum DiffColour {
Green,
@@ -126,4 +142,10 @@ static class LapStorageService {
return lapsByMap[mapName].Laps
.MinBy(l => l.TotalTime);
}
}
// Add this magic code, you will be able to use record and init.
// I only tested in editor, not sure whether it would work on other platforms.
namespace System.Runtime.CompilerServices {
class IsExternalInit {}
}