diff --git a/Assets/Scenes/sr_star_fraenkel_zermelo/sr_star_fraenkel_zermelo.unity b/Assets/Scenes/sr_star_fraenkel_zermelo/sr_star_fraenkel_zermelo.unity index c61f8d0..b3287a0 100644 --- a/Assets/Scenes/sr_star_fraenkel_zermelo/sr_star_fraenkel_zermelo.unity +++ b/Assets/Scenes/sr_star_fraenkel_zermelo/sr_star_fraenkel_zermelo.unity @@ -198,19 +198,19 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalPosition.x - value: -1288.6 + value: -1063.3 objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalPosition.y - value: 177.8 + value: 123 objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalPosition.z - value: 3777.4 + value: 3196.1 objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalRotation.w - value: 0.9992902 + value: 0.99997115 objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalRotation.x @@ -218,7 +218,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalRotation.y - value: -0.037671022 + value: -0.0075994497 objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalRotation.z @@ -230,7 +230,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalEulerAnglesHint.y - value: -4.318 + value: -0.871 objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalEulerAnglesHint.z @@ -305,15 +305,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 64b045a17d258ce37b459b444db394d4, type: 3} propertyPath: m_LocalScale.x - value: 3 + value: 2.5 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 64b045a17d258ce37b459b444db394d4, type: 3} propertyPath: m_LocalScale.y - value: 3 + value: 2.5 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 64b045a17d258ce37b459b444db394d4, type: 3} propertyPath: m_LocalScale.z - value: 3 + value: 2.5 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 64b045a17d258ce37b459b444db394d4, type: 3} propertyPath: m_LocalPosition.x @@ -321,7 +321,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 64b045a17d258ce37b459b444db394d4, type: 3} propertyPath: m_LocalPosition.y - value: -1229 + value: -1030 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 64b045a17d258ce37b459b444db394d4, type: 3} propertyPath: m_LocalPosition.z @@ -843,7 +843,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalPosition.x - value: 2269 + value: 1976.1 objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalPosition.y @@ -851,7 +851,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalPosition.z - value: 3942 + value: 3195.2 objectReference: {fileID: 0} - target: {fileID: 273700024047119412, guid: 87a51212e10250274a8feda6be865b7c, type: 3} propertyPath: m_LocalRotation.w diff --git a/Assets/Scenes/testTrack/TestTrack.unity b/Assets/Scenes/testTrack/TestTrack.unity index 52889e1..b8f0520 100644 --- a/Assets/Scenes/testTrack/TestTrack.unity +++ b/Assets/Scenes/testTrack/TestTrack.unity @@ -370,6 +370,17 @@ Transform: m_CorrespondingSourceObject: {fileID: 7588376663361902483, guid: 73ab56de058af21389c312279181f856, type: 3} m_PrefabInstance: {fileID: 383038820} m_PrefabAsset: {fileID: 0} +--- !u!114 &454666965 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 3196322292278199376, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + m_PrefabInstance: {fileID: 6345872851367721384} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a6214f498273bf702b0ad56b756b4e93, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &546969762 PrefabInstance: m_ObjectHideFlags: 0 @@ -436,6 +447,79 @@ Transform: m_CorrespondingSourceObject: {fileID: 7588376663361902483, guid: 73ab56de058af21389c312279181f856, type: 3} m_PrefabInstance: {fileID: 546969762} m_PrefabAsset: {fileID: 0} +--- !u!1001 &585045537 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 3221660762140721390, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_Name + value: Menu + objectReference: {fileID: 0} + - target: {fileID: 5313449993149091347, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: shipUi + value: + objectReference: {fileID: 1292078235} + - target: {fileID: 5313449993149091347, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: timingDoc + value: + objectReference: {fileID: 1292078237} + - target: {fileID: 5313449993149091347, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: shipControls + value: + objectReference: {fileID: 1972710421} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_RootOrder + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} --- !u!1001 &646057803 PrefabInstance: m_ObjectHideFlags: 0 @@ -1021,6 +1105,28 @@ Transform: m_CorrespondingSourceObject: {fileID: 7588376663361902483, guid: 73ab56de058af21389c312279181f856, type: 3} m_PrefabInstance: {fileID: 1287343202} m_PrefabAsset: {fileID: 0} +--- !u!114 &1292078235 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 5975136821837370545, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + m_PrefabInstance: {fileID: 6345872851367721384} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 14d590d5e541e871cb4b472e9e009128, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &1292078237 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 957429026670911964, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + m_PrefabInstance: {fileID: 6345872851367721384} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &1297026289 PrefabInstance: m_ObjectHideFlags: 0 @@ -1819,6 +1925,17 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2080261968 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 1367906234716419496, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + m_PrefabInstance: {fileID: 6345872851367721384} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a6214f498273bf702b0ad56b756b4e93, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &2096232366 PrefabInstance: m_ObjectHideFlags: 0 @@ -2183,6 +2300,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 1367906234716419496, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + propertyPath: sector + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2603084029878042569, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} propertyPath: m_Name value: Timing @@ -2191,6 +2312,10 @@ PrefabInstance: propertyPath: m_IsActive value: 1 objectReference: {fileID: 0} + - target: {fileID: 3196322292278199376, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + propertyPath: sector + value: 2 + objectReference: {fileID: 0} - target: {fileID: 4743817676494260426, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} propertyPath: m_RootOrder value: 4 @@ -2247,8 +2372,22 @@ PrefabInstance: propertyPath: m_Enabled value: 1 objectReference: {fileID: 0} + - target: {fileID: 8438506523596255020, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + propertyPath: sectors.Array.size + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 8438506523596255020, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + propertyPath: sectors.Array.data[0] + value: + objectReference: {fileID: 2080261968} + - target: {fileID: 8438506523596255020, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + propertyPath: sectors.Array.data[1] + value: + objectReference: {fileID: 454666965} m_RemovedComponents: [] - m_RemovedGameObjects: [] + m_RemovedGameObjects: + - {fileID: 968610525847117003, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + - {fileID: 711392991746672853, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} diff --git a/Assets/Src/Timing.cs b/Assets/Src/Timing.cs index f570c5f..19a4a94 100644 --- a/Assets/Src/Timing.cs +++ b/Assets/Src/Timing.cs @@ -4,6 +4,7 @@ using System.Linq; using UnityEngine; using UnityEditor; +using UnityEngine.SceneManagement; public enum SectorColour { Green, @@ -12,31 +13,18 @@ public enum SectorColour { Yellow, } -public readonly struct SectorTime { - public SectorTime(int i, double t) { - Sector = i; - Seconds = t; - Colour = SectorColour.White; - } - - public int Sector { get; } - public double Seconds { get; } - public SectorColour Colour { get; } - +[Serializable] +public struct SectorTime { + public int Sector; + public double Seconds; public override string ToString() => $"{Seconds:0.000}"; - - // public string ColourClass() => Colour switch { - // SectorColour.Green => "green", - // SectorColour.Purple => "purple", - // SectorColour.White => "white", - // SectorColour.Yellow => "yellow", - // _ => throw new Exception("unknown colour"), - // }; } +[Serializable] public struct Lap { - public int Number { get; set; } - public List Sectors { get; set; } + public string Map; + public int Number; + public List Sectors; // 0:1:39 public override string ToString() { @@ -48,6 +36,45 @@ public struct Lap { } } +static class LapStorageService { + static Dictionary lapsByMap; + static string lapStoragePath = Path.Combine(Application.persistentDataPath, "lapStorage.json"); + + static void GetPlayerLaps() { + // read json + // assign it to lapStorage + } + + // laps.count + static int NumberOfCompletions() {} + + // finds your PB in all completions + static int Rank() {} + + // open json + public static void PersistLap(Lap lap) { + bool found = lapsByMap.TryGetValue(lap.Map, out var lapJson); + if (!found) + lapJson = new LapJSON { Map = lap.Map, Laps = new List() }; + LapJson.Laps.Add(lap); + lapsByMap[lap.Map] = lapJson; + + LapStorage lapStorage = new LapStorage { Laps = lapsByMap.Values.ToList() }; + File.WriteAllText(lapStoragePath, JsonUtility.ToJson(lapStorage)); + } + +} + +[Serializable] +public class LapJSON { + public string Map; + public List Laps; +} + +public class LapStorage { + public List Laps; +} + public class Timing: MonoBehaviour { [SerializeField] public List lapTimes; @@ -61,13 +88,23 @@ public class Timing: MonoBehaviour { double lapStart; public Sector[] sectors; + public LapStorage lapStorage; + + string mapName; + void Awake() { lapTimes = new(); sectorTimes = new List(); sectorStart = 0.0; sectorTime = 0.0; sectors = GetComponentsInChildren().OrderBy(s => s.sector).ToArray(); + + // set map name + Scene scene = SceneManager.GetActiveScene(); + mapName = scene.name; + Debug.Log("Track Sector Count - " + sectors.Length); + Persist(); } void Update() { @@ -96,8 +133,6 @@ public class Timing: MonoBehaviour { sectorTime = 0; lapTime = 0; Debug.Log("Timer Stopped"); - - EndLap(); } public void NextSector(int sector) { @@ -119,11 +154,12 @@ public class Timing: MonoBehaviour { double sTime = Time.timeAsDouble - sectorStart; - SectorTime s = new SectorTime(sector, sTime); + SectorTime s = new SectorTime { Sector = sector, Seconds = sTime }; sectorTimes.Add(s); - sectorStart = Time.timeAsDouble; + Debug.Log($"{sectorTimes.Count} / {sectors.Length}"); + if (sectorTimes.Count == sectors.Length) { EndLap(); NextLap(); @@ -141,11 +177,12 @@ public class Timing: MonoBehaviour { if (sectorTimes == null) Awake(); - if (sectorTimes.Count > 0) { - Lap l = new Lap { Number = lapTimes.Count, Sectors = sectorTimes }; - Debug.Log($"EndLap {l}"); - lapTimes.Add(l); - } + Debug.Log($"Ending lap Sectors={sectorTimes.Count} Name={mapName} Lap={lapTimes.Count}"); + + Lap l = new Lap { Map = mapName, Number = lapTimes.Count, Sectors = sectorTimes }; + Debug.Log($"EndLap {l}"); + lapTimes.Add(l); + Persist(); } public SectorColour GetSectorColour(SectorTime s) { @@ -160,5 +197,21 @@ public class Timing: MonoBehaviour { false => SectorColour.Yellow, }; } + + void Load() { + try { + string json = File.ReadAllText(lapStoragePath); + JsonUtility.FromJsonOverwrite(json, lapStorage); + } catch { + // file doesn't exist yet + return Persist(); + } + } + + void Persist() { + LapJSON lapJson = new LapJSON { Map = mapName, Laps = lapTimes }; + string lapJsonStr = JsonUtility.ToJson(lapJson); + Debug.Log($"Lap JSON {lapJsonStr}"); + } } diff --git a/Assets/Src/UI/MenuUi.cs b/Assets/Src/UI/MenuUi.cs index 9f0214c..69699e3 100644 --- a/Assets/Src/UI/MenuUi.cs +++ b/Assets/Src/UI/MenuUi.cs @@ -38,7 +38,6 @@ public class MenuUi : MonoBehaviour { void SetupExit() { exit = uiDocument.rootVisualElement.Q