Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SongDetails retrieval logic #15

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 50 additions & 30 deletions src/Client/MapEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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);
internal static MapData.JsonData previousStaticData = new MapData.JsonData();
internal static SongDetailsCache songDetailsCacheInstance = null;
private Timer timer = new Timer { Interval = 250 };
private int NoteCount = 0;

Expand Down Expand Up @@ -194,38 +195,57 @@ public void LevelLoaded()

if (isCustomLevel)
{
Task.Run(async () =>
{
SongDetails songDetails = await SongDetails.Init();
if (songDetails.songs.FindByHash(mapHash, out Song song))
bool GetSongDetailsData() {
if (!songDetails.songs.FindByHash(mapHash, out Song song))
{
MapCharacteristic mapType;
switch (gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName)
{
case "Degree360":
mapType = MapCharacteristic.ThreeSixtyDegree;
break;
case "Degree90":
mapType = MapCharacteristic.NinetyDegree;
break;
default:
mapType = (MapCharacteristic)Enum.Parse(typeof(MapCharacteristic),
gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName);
break;
}

if (song.GetDifficulty(
out SongDifficulty difficulty,
(MapDifficulty)gameplayCoreSceneSetupData.difficultyBeatmap.difficulty,
mapType
))
{
MapData.PP = difficulty.approximatePpValue;
MapData.Star = difficulty.stars;
MapData.Send();
}
return false;
}
});

MapCharacteristic mapType;
switch (gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName)
{
case "Degree360":
mapType = MapCharacteristic.ThreeSixtyDegree;
break;
case "Degree90":
mapType = MapCharacteristic.NinetyDegree;
break;
default:
if(!Enum.TryParse(typeof(MapCharacteristic),
gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName,
out mapType))
return false;
break;
}

if (song.GetDifficulty(
out SongDifficulty difficulty,
(MapDifficulty)gameplayCoreSceneSetupData.difficultyBeatmap.difficulty,
mapType
))
{
MapData.PP = difficulty.approximatePpValue;
MapData.Star = difficulty.stars;
return true;
}
return false;
}

if(songDetailsCacheInstance != null) {
GetSongDetailsData();
} else {
SongDetailsCache.Init().ContinueWith(
t => {
if(t.Result != null) {
songDetailsCacheInstance = x.Result;
if(GetSongDetailsData()) {
Task.Run(() => MapData.Send());
}
}
},
TaskContinuationOptions.OnlyOnRanToCompletion
);
}

Task.Run(async () =>
{
Expand Down