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

+22 -21
View File
@@ -30,38 +30,39 @@ 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) {
LapTimesDTO dto = JsonConvert.DeserializeObject<LapTimesDTO>(json);
_pb = dto.Pb;
_lr = dto.LapRecord;
void SetLapTimes(string json) {
try {
LapTimesDTO dto = JsonConvert.DeserializeObject<LapTimesDTO>(json);
_pb = dto.Pb;
_lr = dto.LapRecord;
PB = new Lap {
Map = _pb.Map,
Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(),
};
return dto;
PB = new Lap {
Map = _pb.Map,
Sectors = _pb.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;
}
}
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() {