server post wip
This commit is contained in:
1 parent
ef95f63d14
commit
d6445332be
13 files changed
+239
-30
No files matched your search
@@ -0,0 +1,84 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -131,7 +131,7 @@ static class LapStorageService {
|
||||
public static int NumberOfCompletions() { return 0; }
|
||||
|
||||
// finds your PB in all completions
|
||||
public static int Rank() { return 1; }
|
||||
public static int Position() { return 1; }
|
||||
|
||||
public static void PersistLap(Lap lap) {
|
||||
LapJSON lapJson = GetPlayerLaps(lap.Map);
|
||||
|
||||
Reference in new issue
Block a user