diff --git a/Assets/Src/LapService.cs b/Assets/Src/LapService.cs
index 561a095..72fc8e8 100644
--- a/Assets/Src/LapService.cs
+++ b/Assets/Src/LapService.cs
@@ -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;
}
}
diff --git a/Assets/Src/Laps.cs b/Assets/Src/Laps.cs
index 761b9b6..4a27d03 100644
--- a/Assets/Src/Laps.cs
+++ b/Assets/Src/Laps.cs
@@ -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 {
diff --git a/Assets/Src/Timing.cs b/Assets/Src/Timing.cs
index 64ec625..74aa656 100644
--- a/Assets/Src/Timing.cs
+++ b/Assets/Src/Timing.cs
@@ -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);
+ }
}
diff --git a/Assets/Src/UI/TimingUI.cs b/Assets/Src/UI/TimingUI.cs
index f22e1a7..5cb5b74 100644
--- a/Assets/Src/UI/TimingUI.cs
+++ b/Assets/Src/UI/TimingUI.cs
@@ -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);
}
}
diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset
index dcbe2de..77e4ef3 100644
--- a/ProjectSettings/ProjectSettings.asset
+++ b/ProjectSettings/ProjectSettings.asset
@@ -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
diff --git a/Server/Migrations/20230829101729_InitSectors.Designer.cs b/Server/Migrations/20230831064847_Initialisation.Designer.cs
similarity index 75%
rename from Server/Migrations/20230829101729_InitSectors.Designer.cs
rename to Server/Migrations/20230831064847_Initialisation.Designer.cs
index 1e454bc..bd8a436 100644
--- a/Server/Migrations/20230829101729_InitSectors.Designer.cs
+++ b/Server/Migrations/20230831064847_Initialisation.Designer.cs
@@ -13,8 +13,8 @@ using Server;
namespace Server.Migrations
{
[DbContext(typeof(SpaceRaceDbContext))]
- [Migration("20230829101729_InitSectors")]
- partial class InitSectors
+ [Migration("20230831064847_Initialisation")]
+ partial class Initialisation
{
///
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -29,7 +29,6 @@ namespace Server.Migrations
modelBuilder.Entity("Server.Lap", b =>
{
b.Property("Id")
- .ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property("Created")
@@ -37,7 +36,8 @@ namespace Server.Migrations
b.Property("Map")
.IsRequired()
- .HasColumnType("text");
+ .HasMaxLength(128)
+ .HasColumnType("character varying(128)");
b.Property>("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 { 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 { 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 { 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 { 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 { 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
}
diff --git a/Server/Migrations/20230829101729_InitSectors.cs b/Server/Migrations/20230831064847_Initialisation.cs
similarity index 66%
rename from Server/Migrations/20230829101729_InitSectors.cs
rename to Server/Migrations/20230831064847_Initialisation.cs
index 57daade..d8fdf66 100644
--- a/Server/Migrations/20230829101729_InitSectors.cs
+++ b/Server/Migrations/20230831064847_Initialisation.cs
@@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Server.Migrations
{
///
- public partial class InitSectors : Migration
+ public partial class Initialisation : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
@@ -23,7 +23,7 @@ namespace Server.Migrations
Created = table.Column(type: "timestamp with time zone", nullable: false),
Time = table.Column(type: "double precision", nullable: false),
Sectors = table.Column>(type: "double precision[]", nullable: false),
- Map = table.Column(type: "text", nullable: false)
+ Map = table.Column(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 { 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 { 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 { 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 { 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 { 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 { 64.0, 64.0, 128.0 }, 256.0, new Guid("33333333-3333-3333-3333-333333333333") }
});
migrationBuilder.CreateIndex(
diff --git a/Server/Migrations/SpaceRaceDbContextModelSnapshot.cs b/Server/Migrations/SpaceRaceDbContextModelSnapshot.cs
index acfc3af..1a06e04 100644
--- a/Server/Migrations/SpaceRaceDbContextModelSnapshot.cs
+++ b/Server/Migrations/SpaceRaceDbContextModelSnapshot.cs
@@ -26,7 +26,6 @@ namespace Server.Migrations
modelBuilder.Entity("Server.Lap", b =>
{
b.Property("Id")
- .ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property("Created")
@@ -34,7 +33,8 @@ namespace Server.Migrations
b.Property("Map")
.IsRequired()
- .HasColumnType("text");
+ .HasMaxLength(128)
+ .HasColumnType("character varying(128)");
b.Property>("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 { 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 { 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 { 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 { 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 { 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
}
diff --git a/Server/Repositories/SpaceRaceDbContext.cs b/Server/Repositories/SpaceRaceDbContext.cs
index 172f1e4..8cbb731 100644
--- a/Server/Repositories/SpaceRaceDbContext.cs
+++ b/Server/Repositories/SpaceRaceDbContext.cs
@@ -31,7 +31,10 @@ public class Lap {
[Required] public DateTimeOffset Created { get; set; }
[Required] public double Time { get; set; }
[Required] public List 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 { 64f, 38f, 24f },
- Map = "sr_testtrack",
+ Time = 256f,
+ Sectors = new List { 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 { 64f, 64f, 24f },
- Map = "sr_testtrack",
+ Time = 256f,
+ Sectors = new List { 64f, 64f, 128f },
+ Map = "sr_silverstorage",
}
);
}