sector diffs
This commit is contained in:
1 parent
7c6c6902c5
commit
bef194280e
4 files changed
+52
-45
No files matched your search
+11
-12
@@ -14,16 +14,15 @@ public enum SectorColour {
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct SectorTime {
|
||||
public class SectorTime {
|
||||
public int Sector;
|
||||
public double Seconds;
|
||||
public override string ToString() => $"{Seconds:0.000}";
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct Lap {
|
||||
public class Lap {
|
||||
public string Map;
|
||||
public int Number;
|
||||
public List<SectorTime> Sectors;
|
||||
|
||||
// 0:1:39
|
||||
@@ -69,11 +68,16 @@ static class LapStorageService {
|
||||
public static LapJSON GetPlayerLaps(string mapName) {
|
||||
LapJSON currentLaps;
|
||||
bool found = lapsByMap.TryGetValue(mapName, out currentLaps);
|
||||
if (!found)
|
||||
return new LapJSON { Map = mapName, Laps = new List<Lap>() };
|
||||
if (!found) return EnsureMap(mapName);
|
||||
return currentLaps;
|
||||
}
|
||||
|
||||
public static LapJSON EnsureMap(string mapName) {
|
||||
LapJSON lapJson = new LapJSON { Map = mapName, Laps = new List<Lap>() };
|
||||
lapsByMap[mapName] = lapJson;
|
||||
return lapJson;
|
||||
}
|
||||
|
||||
static void Persist() {
|
||||
LapStorage lapStorage = new LapStorage { Laps = lapsByMap.Values.ToList() };
|
||||
File.WriteAllText(lapStoragePath, JsonUtility.ToJson(lapStorage));
|
||||
@@ -86,14 +90,9 @@ static class LapStorageService {
|
||||
public static int Rank() { return 1; }
|
||||
|
||||
public static void PersistLap(Lap lap) {
|
||||
LapJSON lapJson;
|
||||
bool found = lapsByMap.TryGetValue(lap.Map, out lapJson);
|
||||
if (!found)
|
||||
lapJson = new LapJSON { Map = lap.Map, Laps = new List<Lap>() };
|
||||
|
||||
// Add lap and persist
|
||||
LapJSON lapJson = GetPlayerLaps(lap.Map);
|
||||
lapJson.Laps.Add(lap);
|
||||
lapsByMap[lap.Map] = lapJson;
|
||||
lapsByMap[lap.Map] = lapJson; // not needed?
|
||||
Persist();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user