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
+32 -31

No files matched your search

File renamed without changes.
+15 -14
View File
@@ -30,28 +30,25 @@ public class LapService {
LoadPlayerData();
}
public IEnumerator GetPb() {
string uri = $"localhost:40080/Pb?userId={_player.Id}&mapName={_mapName}";
public IEnumerator GetLapTimes() {
string uri = $"localhost:40080/LapTimes?userId={_player.Id}&mapName={_mapName}";
using (UnityWebRequest req = UnityWebRequest.Get(uri)) {
yield return req.SendWebRequest();
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:
Debug.Log("Received: " + req.downloadHandler.text);
SetPb(req.downloadHandler.text);
SetLapTimes(req.downloadHandler.text);
break;
default:
Debug.LogError("Error: " + req.error);
break;
}
}
}
LapTimesDTO SetPb(string json) {
void SetLapTimes(string json) {
try {
LapTimesDTO dto = JsonConvert.DeserializeObject<LapTimesDTO>(json);
_pb = dto.Pb;
_lr = dto.LapRecord;
@@ -60,8 +57,12 @@ public class LapService {
Map = _pb.Map,
Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(),
};
return dto;
} catch (Exception e) {
Debug.LogWarning($"Failed to set lap times {e}");
_pb = null;
_lr = null;
PB = null;
}
}
public IEnumerator PostLap(Lap lap) {
@@ -91,7 +92,7 @@ public class LapService {
try {
string json = File.ReadAllText(playerDataPath);
_player = JsonConvert.DeserializeObject<PlayerData>(json);
Debug.Log($"Loaded player data {_player}");
Debug.Log($"Loaded player data {json}");
} catch {
Debug.Log("No existing playerData.json");
CreatePlayerData();
+1 -1
View File
@@ -42,7 +42,7 @@ public class Timing: MonoBehaviour {
}
void Start() {
StartCoroutine(lapService.GetPb());
StartCoroutine(lapService.GetLapTimes());
}
void Update() {
@@ -7,17 +7,17 @@ namespace Server.Controllers;
[ApiController]
[Route("[controller]")]
public class PbController : ControllerBase {
private readonly ILogger<PbController> _logger;
public class LapTimesController : ControllerBase {
private readonly ILogger<LapTimesController> _logger;
private SpaceRaceDbContext _db;
public PbController(ILogger<PbController> logger, SpaceRaceDbContext db) {
public LapTimesController(ILogger<LapTimesController> logger, SpaceRaceDbContext db) {
_logger = logger;
_db = db;
}
[HttpGet()]
public LapTimesDTO Pb(Guid userId, string mapName) {
public LapTimesDTO LapTimes(Guid userId, string mapName) {
_logger.LogInformation($"{userId} {mapName}");
PbDTO pb = _db.PbDTO
+3 -3
View File
@@ -63,7 +63,7 @@ namespace Server.Migrations
{
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)),
Map = "sr_TestTrack",
Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 24.0, 24.0 },
Time = 128.0,
UserId = new Guid("11111111-1111-1111-1111-111111111111")
@@ -72,7 +72,7 @@ namespace Server.Migrations
{
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",
Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 38.0, 24.0 },
Time = 132.0,
UserId = new Guid("22222222-2222-2222-2222-222222222222")
@@ -81,7 +81,7 @@ namespace Server.Migrations
{
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",
Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 64.0, 24.0 },
Time = 148.0,
UserId = new Guid("33333333-3333-3333-3333-333333333333")
@@ -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("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") }
});
migrationBuilder.CreateIndex(
@@ -60,7 +60,7 @@ namespace Server.Migrations
{
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)),
Map = "sr_TestTrack",
Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 24.0, 24.0 },
Time = 128.0,
UserId = new Guid("11111111-1111-1111-1111-111111111111")
@@ -69,7 +69,7 @@ namespace Server.Migrations
{
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",
Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 38.0, 24.0 },
Time = 132.0,
UserId = new Guid("22222222-2222-2222-2222-222222222222")
@@ -78,7 +78,7 @@ namespace Server.Migrations
{
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",
Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 64.0, 24.0 },
Time = 148.0,
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"),
Time = 128f,
Sectors = new List<double> { 64f, 24f, 24f },
Map = "sr_TestTrack",
Map = "sr_testtrack",
},
new Lap {
Created = DateTimeOffset.UtcNow,
@@ -65,7 +65,7 @@ class SpaceRaceInitialiser {
UserId = new Guid("22222222-2222-2222-2222-222222222222"),
Time = 132f,
Sectors = new List<double> { 64f, 38f, 24f },
Map = "sr_TestTrack",
Map = "sr_testtrack",
},
new Lap {
Created = DateTimeOffset.UtcNow,
@@ -73,7 +73,7 @@ class SpaceRaceInitialiser {
UserId = new Guid("33333333-3333-3333-3333-333333333333"),
Time = 148f,
Sectors = new List<double> { 64f, 64f, 24f },
Map = "sr_TestTrack",
Map = "sr_testtrack",
}
);
}