From 44eaff41ab199128fd03b0736e81997db190a01d Mon Sep 17 00:00:00 2001 From: Tristan Read <60425965+kOFReadie@users.noreply.github.com> Date: Sat, 1 Jan 2022 17:45:36 +0000 Subject: [PATCH] #15 --- beatmods.md | 2 +- src/Client/MapEvents.cs | 34 ++++++++++++++++++++++------------ src/Properties/AssemblyInfo.cs | 4 ++-- src/manifest.json | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/beatmods.md b/beatmods.md index 4a8067a..83fd064 100644 --- a/beatmods.md +++ b/beatmods.md @@ -2,7 +2,7 @@ DataPuller ## Mod Version -2.0.10 +2.0.11 ## Game Version 1.19.0 diff --git a/src/Client/MapEvents.cs b/src/Client/MapEvents.cs index d0627ae..289a67b 100644 --- a/src/Client/MapEvents.cs +++ b/src/Client/MapEvents.cs @@ -21,6 +21,7 @@ class MapEvents : IInitializable, IDisposable { //I think I need to fix my refrences as VS does not notice when I update them. private static BeatSaver beatSaver = new BeatSaver("BSDataPuller", Assembly.GetExecutingAssembly().GetName().Version); + private static SongDetails songDetailsCache = null; internal static MapData.JsonData previousStaticData = new MapData.JsonData(); private Timer timer = new Timer { Interval = 250 }; private int NoteCount = 0; @@ -191,13 +192,11 @@ public void LevelLoaded() MapData.NJS = gameplayCoreSceneSetupData.difficultyBeatmap.noteJumpMovementSpeed; MapData.CustomDifficultyLabel = difficultyData?._difficultyLabel ?? null; - if (isCustomLevel) { - Task.Run(async () => + void SetSongDetails() { - SongDetails songDetails = await SongDetails.Init(); - if (songDetails.songs.FindByHash(mapHash, out Song song)) + if (songDetailsCache.songs.FindByHash(mapHash, out Song song)) { MapCharacteristic mapType; switch (gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName) @@ -209,8 +208,10 @@ public void LevelLoaded() mapType = MapCharacteristic.NinetyDegree; break; default: - mapType = (MapCharacteristic)Enum.Parse(typeof(MapCharacteristic), - gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName); + if (!Enum.TryParse( + gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName, + out mapType + )) { return; } break; } @@ -225,17 +226,26 @@ public void LevelLoaded() MapData.Send(); } } - }); + } - Task.Run(async () => + if (songDetailsCache == null) { - BeatSaverSharp.Models.Beatmap beatmap = await beatSaver.BeatmapByHash(mapHash); - if (beatmap != null) + SongDetails.Init().ContinueWith((task) => { - MapData.BSRKey = beatmap.ID; + if (task.Result == null) { return; } + songDetailsCache = task.Result; + SetSongDetails(); + }); + } + else { SetSongDetails(); } + beatSaver.BeatmapByHash(mapHash).ContinueWith((task) => + { + if (task.Result != null) + { + MapData.BSRKey = task.Result.ID; BeatSaverSharp.Models.BeatmapVersion mapDetails = null; - try { mapDetails = beatmap.Versions.First(map => map.Hash.ToLower() == mapHash.ToLower()); } catch (Exception ex) { Plugin.Logger.Error(ex); } + try { mapDetails = task.Result.Versions.First(map => map.Hash.ToLower() == mapHash.ToLower()); } catch (Exception ex) { Plugin.Logger.Error(ex); } MapData.coverImage = mapDetails != null ? mapDetails.CoverURL : null; } else diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index b4fa0e6..dee1ec3 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.10")] -[assembly: AssemblyFileVersion("2.0.10")] +[assembly: AssemblyVersion("2.0.11")] +[assembly: AssemblyFileVersion("2.0.11")] diff --git a/src/manifest.json b/src/manifest.json index e1b0250..66e4f57 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -3,7 +3,7 @@ "id": "DataPuller", "name": "DataPuller", "author": "Readie", - "version": "2.0.10", + "version": "2.0.11", "description": "Gathers data about the current map you are playing to then be sent out over a websocket for other software to use, e.g. A web overlay like BSDP-Overlay. This mod works with multi PC setups!", "gameVersion": "1.19.0", "dependsOn": {