various bugfixes

This commit is contained in:
ntr committed 2023-08-30 12:36:23 +10:00
1 parent 900ee4412d
commit b7ad479ead
12 files changed
+39 -38

No files matched your search

File renamed without changes.
+22 -21
View File
@@ -30,38 +30,39 @@ public class LapService {
LoadPlayerData(); LoadPlayerData();
} }
public IEnumerator GetPb() { public IEnumerator GetLapTimes() {
string uri = $"localhost:40080/Pb?userId={_player.Id}&mapName={_mapName}"; string uri = $"localhost:40080/LapTimes?userId={_player.Id}&mapName={_mapName}";
using (UnityWebRequest req = UnityWebRequest.Get(uri)) { using (UnityWebRequest req = UnityWebRequest.Get(uri)) {
yield return req.SendWebRequest(); yield return req.SendWebRequest();
switch (req.result) { switch (req.result) {
case UnityWebRequest.Result.ConnectionError:
case UnityWebRequest.Result.DataProcessingError:
Debug.LogError("Error: " + req.error);
break;
case UnityWebRequest.Result.ProtocolError:
Debug.LogError("HTTP Error: " + req.error);
break;
case UnityWebRequest.Result.Success: case UnityWebRequest.Result.Success:
Debug.Log("Received: " + req.downloadHandler.text); Debug.Log("Received: " + req.downloadHandler.text);
SetPb(req.downloadHandler.text); SetLapTimes(req.downloadHandler.text);
break;
default:
Debug.LogError("Error: " + req.error);
break; break;
} }
} }
} }
LapTimesDTO SetPb(string json) { void SetLapTimes(string json) {
LapTimesDTO dto = JsonConvert.DeserializeObject<LapTimesDTO>(json); try {
_pb = dto.Pb; LapTimesDTO dto = JsonConvert.DeserializeObject<LapTimesDTO>(json);
_lr = dto.LapRecord; _pb = dto.Pb;
_lr = dto.LapRecord;
PB = new Lap { PB = new Lap {
Map = _pb.Map, Map = _pb.Map,
Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(),
}; };
} catch (Exception e) {
return dto; Debug.LogWarning($"Failed to set lap times {e}");
_pb = null;
_lr = null;
PB = null;
}
} }
public IEnumerator PostLap(Lap lap) { public IEnumerator PostLap(Lap lap) {
@@ -91,7 +92,7 @@ public class LapService {
try { try {
string json = File.ReadAllText(playerDataPath); string json = File.ReadAllText(playerDataPath);
_player = JsonConvert.DeserializeObject<PlayerData>(json); _player = JsonConvert.DeserializeObject<PlayerData>(json);
Debug.Log($"Loaded player data {_player}"); Debug.Log($"Loaded player data {json}");
} catch { } catch {
Debug.Log("No existing playerData.json"); Debug.Log("No existing playerData.json");
CreatePlayerData(); CreatePlayerData();
+1 -1
View File
@@ -42,7 +42,7 @@ public class Timing: MonoBehaviour {
} }
void Start() { void Start() {
StartCoroutine(lapService.GetPb()); StartCoroutine(lapService.GetLapTimes());
} }
void Update() { void Update() {
@@ -7,17 +7,17 @@ namespace Server.Controllers;
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]
public class PbController : ControllerBase { public class LapTimesController : ControllerBase {
private readonly ILogger<PbController> _logger; private readonly ILogger<LapTimesController> _logger;
private SpaceRaceDbContext _db; private SpaceRaceDbContext _db;
public PbController(ILogger<PbController> logger, SpaceRaceDbContext db) { public LapTimesController(ILogger<LapTimesController> logger, SpaceRaceDbContext db) {
_logger = logger; _logger = logger;
_db = db; _db = db;
} }
[HttpGet()] [HttpGet()]
public LapTimesDTO Pb(Guid userId, string mapName) { public LapTimesDTO LapTimes(Guid userId, string mapName) {
_logger.LogInformation($"{userId} {mapName}"); _logger.LogInformation($"{userId} {mapName}");
PbDTO pb = _db.PbDTO PbDTO pb = _db.PbDTO
+3 -3
View File
@@ -63,7 +63,7 @@ namespace Server.Migrations
{ {
Id = new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"), 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)), Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack", Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 24.0, 24.0 }, Sectors = new List<double> { 64.0, 24.0, 24.0 },
Time = 128.0, Time = 128.0,
UserId = new Guid("11111111-1111-1111-1111-111111111111") UserId = new Guid("11111111-1111-1111-1111-111111111111")
@@ -72,7 +72,7 @@ namespace Server.Migrations
{ {
Id = new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"), 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)), 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", Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 38.0, 24.0 }, Sectors = new List<double> { 64.0, 38.0, 24.0 },
Time = 132.0, Time = 132.0,
UserId = new Guid("22222222-2222-2222-2222-222222222222") UserId = new Guid("22222222-2222-2222-2222-222222222222")
@@ -81,7 +81,7 @@ namespace Server.Migrations
{ {
Id = new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"), 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)), 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", Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 64.0, 24.0 }, Sectors = new List<double> { 64.0, 64.0, 24.0 },
Time = 148.0, Time = 148.0,
UserId = new Guid("33333333-3333-3333-3333-333333333333") UserId = new Guid("33333333-3333-3333-3333-333333333333")
@@ -35,9 +35,9 @@ namespace Server.Migrations
columns: new[] { "Id", "Created", "Map", "Sectors", "Time", "UserId" }, columns: new[] { "Id", "Created", "Map", "Sectors", "Time", "UserId" },
values: new object[,] 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("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("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("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") }
}); });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
@@ -60,7 +60,7 @@ namespace Server.Migrations
{ {
Id = new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"), 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)), Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack", Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 24.0, 24.0 }, Sectors = new List<double> { 64.0, 24.0, 24.0 },
Time = 128.0, Time = 128.0,
UserId = new Guid("11111111-1111-1111-1111-111111111111") UserId = new Guid("11111111-1111-1111-1111-111111111111")
@@ -69,7 +69,7 @@ namespace Server.Migrations
{ {
Id = new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"), 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)), 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", Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 38.0, 24.0 }, Sectors = new List<double> { 64.0, 38.0, 24.0 },
Time = 132.0, Time = 132.0,
UserId = new Guid("22222222-2222-2222-2222-222222222222") UserId = new Guid("22222222-2222-2222-2222-222222222222")
@@ -78,7 +78,7 @@ namespace Server.Migrations
{ {
Id = new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"), 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)), 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", Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 64.0, 24.0 }, Sectors = new List<double> { 64.0, 64.0, 24.0 },
Time = 148.0, Time = 148.0,
UserId = new Guid("33333333-3333-3333-3333-333333333333") UserId = new Guid("33333333-3333-3333-3333-333333333333")
+3 -3
View File
@@ -57,7 +57,7 @@ class SpaceRaceInitialiser {
UserId = new Guid("11111111-1111-1111-1111-111111111111"), UserId = new Guid("11111111-1111-1111-1111-111111111111"),
Time = 128f, Time = 128f,
Sectors = new List<double> { 64f, 24f, 24f }, Sectors = new List<double> { 64f, 24f, 24f },
Map = "sr_TestTrack", Map = "sr_testtrack",
}, },
new Lap { new Lap {
Created = DateTimeOffset.UtcNow, Created = DateTimeOffset.UtcNow,
@@ -65,7 +65,7 @@ class SpaceRaceInitialiser {
UserId = new Guid("22222222-2222-2222-2222-222222222222"), UserId = new Guid("22222222-2222-2222-2222-222222222222"),
Time = 132f, Time = 132f,
Sectors = new List<double> { 64f, 38f, 24f }, Sectors = new List<double> { 64f, 38f, 24f },
Map = "sr_TestTrack", Map = "sr_testtrack",
}, },
new Lap { new Lap {
Created = DateTimeOffset.UtcNow, Created = DateTimeOffset.UtcNow,
@@ -73,7 +73,7 @@ class SpaceRaceInitialiser {
UserId = new Guid("33333333-3333-3333-3333-333333333333"), UserId = new Guid("33333333-3333-3333-3333-333333333333"),
Time = 148f, Time = 148f,
Sectors = new List<double> { 64f, 64f, 24f }, Sectors = new List<double> { 64f, 64f, 24f },
Map = "sr_TestTrack", Map = "sr_testtrack",
} }
); );
} }