85 lines
2.0 KiB
C#
85 lines
2.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.IO;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UIElements;
|
|
|
|
[Serializable]
|
|
public class SectorTime {
|
|
public int Sector;
|
|
public double Seconds;
|
|
public override string ToString() => $"{Seconds:0.000}";
|
|
}
|
|
|
|
[Serializable]
|
|
public class Lap {
|
|
public string Map;
|
|
public List<SectorTime> Sectors;
|
|
|
|
// 0:1:39
|
|
public override string ToString() {
|
|
return $"{TimeSpan.FromSeconds(TotalTime):m\\:ss\\.fff}";
|
|
}
|
|
|
|
public double TotalTime => Sectors.Sum(s => s.Seconds);
|
|
}
|
|
|
|
[Serializable]
|
|
public class PlayerData {
|
|
public Guid Id;
|
|
}
|
|
|
|
public class LapStorage {
|
|
public string Map = "unset";
|
|
public List<Lap> Laps = new();
|
|
public int Completions = 0;
|
|
public int Position = 0;
|
|
}
|
|
|
|
static class LapStorageService {
|
|
static string playerDataPath = Path.Combine(Application.persistentDataPath, "playerData.json");
|
|
PlayerData player;
|
|
|
|
LapStorage lapStorage;
|
|
|
|
static LapStorageService() {
|
|
try {
|
|
string json = File.ReadAllText(playerDataPath);
|
|
JsonUtility.FromJsonOverwrite(json, player);
|
|
} catch {
|
|
Debug.Log("No existing playerData.json");
|
|
CreatePlayerData();
|
|
}
|
|
}
|
|
|
|
public static LapJSON GetPlayerLaps(string mapName) {
|
|
// get
|
|
return new Lap;
|
|
}
|
|
|
|
// laps.count
|
|
public static int NumberOfCompletions() { return 0; }
|
|
|
|
// finds your PB in all completions
|
|
public static int Position() { return 1; }
|
|
|
|
public static void PersistLap(Lap lap) {
|
|
Debug.Log(JsonUtility.ToJson(lap));
|
|
}
|
|
|
|
PlayerData CreatePlayerData() {
|
|
player = new PlayerData { Id = Guid.NewGuid() }
|
|
File.WriteAllText(playerDataPath, JsonUtility.ToJson(data));
|
|
return player;
|
|
}
|
|
|
|
public static Lap PB(string mapName) {
|
|
return lapsByMap[mapName].Laps
|
|
.MinBy(l => l.TotalTime);
|
|
}
|
|
}
|