smoke purpp
This commit is contained in:
1 parent
f8e12cf990
commit
9e1a596ebc
9 files changed
+88
-81
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-12
@@ -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 {
|
||||
|
||||
+21
-14
@@ -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
|
||||
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,
|
||||
},
|
||||
null => new TimingNotice { Seconds = s.Seconds }, // there is no pb
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,8 +134,7 @@ PlayerSettings:
|
||||
vulkanEnableCommandBufferRecycling: 1
|
||||
loadStoreDebugModeEnabled: 0
|
||||
bundleVersion: 0.1
|
||||
preloadedAssets:
|
||||
- {fileID: 11400000, guid: 020903acd8b50dd45a683fb9312ba7af, type: 2}
|
||||
preloadedAssets: []
|
||||
metroInputSource: 0
|
||||
wsaTransparentSwapchain: 0
|
||||
m_HolographicPauseOnTrackingLoss: 1
|
||||
|
||||
+16
-18
@@ -13,8 +13,8 @@ using Server;
|
||||
namespace Server.Migrations
|
||||
{
|
||||
[DbContext(typeof(SpaceRaceDbContext))]
|
||||
[Migration("20230829101729_InitSectors")]
|
||||
partial class InitSectors
|
||||
[Migration("20230831064847_Initialisation")]
|
||||
partial class Initialisation
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -29,7 +29,6 @@ namespace Server.Migrations
|
||||
modelBuilder.Entity("Server.Lap", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
@@ -37,7 +36,8 @@ namespace Server.Migrations
|
||||
|
||||
b.Property<string>("Map")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<List<double>>("Sectors")
|
||||
.IsRequired()
|
||||
@@ -61,8 +61,8 @@ namespace Server.Migrations
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Id = new Guid("be3d3d80-a0c3-4aff-b373-711b6eb2c9f3"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8821), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_testtrack",
|
||||
Sectors = new List<double> { 64.0, 24.0, 24.0 },
|
||||
Time = 128.0,
|
||||
@@ -70,20 +70,20 @@ namespace Server.Migrations
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(723), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_testtrack",
|
||||
Sectors = new List<double> { 64.0, 38.0, 24.0 },
|
||||
Time = 132.0,
|
||||
Id = new Guid("a5f5815a-2ba5-4b9f-8f45-fe41f5b20102"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8875), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_junglism",
|
||||
Sectors = new List<double> { 64.0, 64.0, 128.0 },
|
||||
Time = 256.0,
|
||||
UserId = new Guid("22222222-2222-2222-2222-222222222222")
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(745), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_testtrack",
|
||||
Sectors = new List<double> { 64.0, 64.0, 24.0 },
|
||||
Time = 148.0,
|
||||
Id = new Guid("d2a3e508-8a8e-4959-8103-67c60567e294"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8882), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_silverstorage",
|
||||
Sectors = new List<double> { 64.0, 64.0, 128.0 },
|
||||
Time = 256.0,
|
||||
UserId = new Guid("33333333-3333-3333-3333-333333333333")
|
||||
});
|
||||
});
|
||||
@@ -115,8 +115,6 @@ namespace Server.Migrations
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.ToTable((string)null);
|
||||
|
||||
b.ToSqlQuery("WITH ranked AS (\n SELECT *, rank() OVER (ORDER BY \"Time\" ASC) AS \"Position\", COUNT(\"Id\") OVER () AS \"Completions\"\n FROM \"Laps\"\n)\n\nSELECT * FROM ranked");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
+5
-5
@@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
namespace Server.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitSectors : Migration
|
||||
public partial class Initialisation : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@@ -23,7 +23,7 @@ namespace Server.Migrations
|
||||
Created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
Time = table.Column<double>(type: "double precision", nullable: false),
|
||||
Sectors = table.Column<List<double>>(type: "double precision[]", nullable: false),
|
||||
Map = table.Column<string>(type: "text", nullable: false)
|
||||
Map = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@@ -35,9 +35,9 @@ namespace Server.Migrations
|
||||
columns: new[] { "Id", "Created", "Map", "Sectors", "Time", "UserId" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"), new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)), "sr_testtrack", new List<double> { 64.0, 24.0, 24.0 }, 128.0, new Guid("11111111-1111-1111-1111-111111111111") },
|
||||
{ new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"), new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(745), new TimeSpan(0, 0, 0, 0, 0)), "sr_testtrack", new List<double> { 64.0, 64.0, 24.0 }, 148.0, new Guid("33333333-3333-3333-3333-333333333333") },
|
||||
{ new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"), new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(723), new TimeSpan(0, 0, 0, 0, 0)), "sr_testtrack", new List<double> { 64.0, 38.0, 24.0 }, 132.0, new Guid("22222222-2222-2222-2222-222222222222") }
|
||||
{ new Guid("a5f5815a-2ba5-4b9f-8f45-fe41f5b20102"), new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8875), new TimeSpan(0, 0, 0, 0, 0)), "sr_junglism", new List<double> { 64.0, 64.0, 128.0 }, 256.0, new Guid("22222222-2222-2222-2222-222222222222") },
|
||||
{ new Guid("be3d3d80-a0c3-4aff-b373-711b6eb2c9f3"), new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8821), new TimeSpan(0, 0, 0, 0, 0)), "sr_testtrack", new List<double> { 64.0, 24.0, 24.0 }, 128.0, new Guid("11111111-1111-1111-1111-111111111111") },
|
||||
{ new Guid("d2a3e508-8a8e-4959-8103-67c60567e294"), new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8882), new TimeSpan(0, 0, 0, 0, 0)), "sr_silverstorage", new List<double> { 64.0, 64.0, 128.0 }, 256.0, new Guid("33333333-3333-3333-3333-333333333333") }
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
@@ -26,7 +26,6 @@ namespace Server.Migrations
|
||||
modelBuilder.Entity("Server.Lap", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
@@ -34,7 +33,8 @@ namespace Server.Migrations
|
||||
|
||||
b.Property<string>("Map")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<List<double>>("Sectors")
|
||||
.IsRequired()
|
||||
@@ -58,8 +58,8 @@ namespace Server.Migrations
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Id = new Guid("be3d3d80-a0c3-4aff-b373-711b6eb2c9f3"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8821), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_testtrack",
|
||||
Sectors = new List<double> { 64.0, 24.0, 24.0 },
|
||||
Time = 128.0,
|
||||
@@ -67,20 +67,20 @@ namespace Server.Migrations
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(723), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_testtrack",
|
||||
Sectors = new List<double> { 64.0, 38.0, 24.0 },
|
||||
Time = 132.0,
|
||||
Id = new Guid("a5f5815a-2ba5-4b9f-8f45-fe41f5b20102"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8875), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_junglism",
|
||||
Sectors = new List<double> { 64.0, 64.0, 128.0 },
|
||||
Time = 256.0,
|
||||
UserId = new Guid("22222222-2222-2222-2222-222222222222")
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(745), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_testtrack",
|
||||
Sectors = new List<double> { 64.0, 64.0, 24.0 },
|
||||
Time = 148.0,
|
||||
Id = new Guid("d2a3e508-8a8e-4959-8103-67c60567e294"),
|
||||
Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8882), new TimeSpan(0, 0, 0, 0, 0)),
|
||||
Map = "sr_silverstorage",
|
||||
Sectors = new List<double> { 64.0, 64.0, 128.0 },
|
||||
Time = 256.0,
|
||||
UserId = new Guid("33333333-3333-3333-3333-333333333333")
|
||||
});
|
||||
});
|
||||
@@ -112,8 +112,6 @@ namespace Server.Migrations
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.ToTable((string)null);
|
||||
|
||||
b.ToSqlQuery("SELECT *, rank() OVER (ORDER BY \"Time\" ASC) AS \"Position\", COUNT(\"Id\") OVER () AS \"Completions\"\n FROM \"Laps\"\n)\n\n");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@ public class Lap {
|
||||
[Required] public DateTimeOffset Created { get; set; }
|
||||
[Required] public double Time { get; set; }
|
||||
[Required] public List<double> Sectors { get; set; }
|
||||
[Required] public string Map { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(128)]
|
||||
public string Map { get; set; }
|
||||
}
|
||||
|
||||
class SpaceRaceInitialiser {
|
||||
@@ -55,17 +58,17 @@ class SpaceRaceInitialiser {
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = new Guid("22222222-2222-2222-2222-222222222222"),
|
||||
Time = 132f,
|
||||
Sectors = new List<double> { 64f, 38f, 24f },
|
||||
Map = "sr_testtrack",
|
||||
Time = 256f,
|
||||
Sectors = new List<double> { 64f, 64f, 128f },
|
||||
Map = "sr_junglism",
|
||||
},
|
||||
new Lap {
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = new Guid("33333333-3333-3333-3333-333333333333"),
|
||||
Time = 148f,
|
||||
Sectors = new List<double> { 64f, 64f, 24f },
|
||||
Map = "sr_testtrack",
|
||||
Time = 256f,
|
||||
Sectors = new List<double> { 64f, 64f, 128f },
|
||||
Map = "sr_silverstorage",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user