From 6434080a993dfaac5eac89e19146d10a5ee09b91 Mon Sep 17 00:00:00 2001 From: Davi3684 Date: Thu, 18 Aug 2022 15:05:16 +0200 Subject: [PATCH] Fixed main thread being blocked on initialization --- .../Managers/SongSuggestManager.cs | 15 ++++---------- TaohSongSuggest/Properties/AssemblyInfo.cs | 4 ++-- .../SongSuggest/Actions/OldestSongs.cs | 20 +++++++++++++++---- .../SongSuggest/DataHandling/SongSuggest.cs | 9 +++++++-- TaohSongSuggest/manifest.json | 2 +- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/TaohSongSuggest/Managers/SongSuggestManager.cs b/TaohSongSuggest/Managers/SongSuggestManager.cs index 562f1ed..c9a1836 100644 --- a/TaohSongSuggest/Managers/SongSuggestManager.cs +++ b/TaohSongSuggest/Managers/SongSuggestManager.cs @@ -29,7 +29,7 @@ static async void UpdateProgessNew() public static void Init() { - Task.Run(async () => + Task.Run(() => { try { @@ -51,14 +51,7 @@ public static void Init() lastSuggestionsPath = configDir }; - - await IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew(async() => - { - var userinf = await BS_Utils.Gameplay.GetUserInfo.GetUserAsync(); - - toolBox = new SongSuggest(fps, userinf.platformUserId); - }); - + toolBox = new SongSuggest(fps, "-1"); } catch (Exception e) { @@ -115,7 +108,7 @@ public static void SuggestSongs(bool p_ignoreNonImprovable = false) toolBox.songSuggest.songSuggestCompletion = 1; - Task.Delay(100); + //Task.Delay(100); await IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew(() => { @@ -186,7 +179,7 @@ public static void Oldest100ActivePlayer() toolBox.GenerateOldestSongs(settings); - Task.Delay(200); + //Task.Delay(200); IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew(() => { diff --git a/TaohSongSuggest/Properties/AssemblyInfo.cs b/TaohSongSuggest/Properties/AssemblyInfo.cs index 35f78b6..7b4bfa3 100644 --- a/TaohSongSuggest/Properties/AssemblyInfo.cs +++ b/TaohSongSuggest/Properties/AssemblyInfo.cs @@ -31,5 +31,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("1.5.18")] -[assembly: AssemblyFileVersion("1.5.18")] +[assembly: AssemblyVersion("1.5.19")] +[assembly: AssemblyFileVersion("1.5.19")] diff --git a/TaohSongSuggest/SongSuggest/Actions/OldestSongs.cs b/TaohSongSuggest/SongSuggest/Actions/OldestSongs.cs index a5f5d22..0bad326 100644 --- a/TaohSongSuggest/SongSuggest/Actions/OldestSongs.cs +++ b/TaohSongSuggest/SongSuggest/Actions/OldestSongs.cs @@ -1,6 +1,9 @@ using PlaylistNS; using SongSuggestNS; using Settings; +using System.Linq; +using System.Collections.Generic; +using System; namespace Actions { @@ -17,13 +20,22 @@ public OldestSongs(SongSuggest songSuggest) public void Oldest100ActivePlayer(OldestSongSettings settings) { - songSuggest.RefreshActivePlayer(); //Create empty playlist, and reset output window. playlist = new Playlist(settings.playlistSettings) {songSuggest = songSuggest}; - - //Add up to 100 oldest song to playlist + + //Add up to 100 oldest song to playlist that has not been banned, and is within given parameters. songSuggest.status = "Finding 100 Oldest"; - playlist.AddSongs(songSuggest.activePlayer.GetOldest(100, settings.ignoreAccuracyEqualAbove, settings.ignorePlayedDays)); + List oldestSongs = songSuggest.activePlayer.scores + .Where(c => c.Value.accuracy < settings.ignoreAccuracyEqualAbove) //Ignore high Acc + .Where(c => c.Value.timeSet < DateTime.UtcNow.AddDays(-settings.ignorePlayedDays)) //Ignore newest plays + .OrderBy(c => c.Value.timeSet) //Sort list by oldest + .Select(c => c.Value.songID) //Get the ID of the songs + .Except(songSuggest.songBanning.GetPermaBannedIDs()) //Remove PermaBanned songs + .Take(100) //Get up to 100 songs + .ToList(); + + //Lets get them into the playlist. + playlist.AddSongs(oldestSongs); //Generate and save a playlist with the selected songs in the playlist. songSuggest.status = "Generating Playlist"; diff --git a/TaohSongSuggest/SongSuggest/DataHandling/SongSuggest.cs b/TaohSongSuggest/SongSuggest/DataHandling/SongSuggest.cs index 3903573..0ddccba 100644 --- a/TaohSongSuggest/SongSuggest/DataHandling/SongSuggest.cs +++ b/TaohSongSuggest/SongSuggest/DataHandling/SongSuggest.cs @@ -102,6 +102,7 @@ public SongSuggest(FilePathSettings filePathSettings, String userID) public void GenerateSongSuggestions(SongSuggestSettings settings) { //Refresh Player Data + activePlayerID = settings.scoreSaberID; RefreshActivePlayer(); //Create the Song Suggestion (so once the creation has been made additional information can be kept and loaded from it. @@ -121,7 +122,7 @@ public void GenerateSongSuggestions(SongSuggestSettings settings) //Requires a RankedSongsSuggest has been performed, then it evaluates the linked songs without updating the user via new settings. //**Consider checks for updates of user, and that RankedSongsSuggest has already been performed** - public void Recalculate (SongSuggestSettings settings) + public void Recalculate(SongSuggestSettings settings) { songSuggest.settings = settings; songSuggest.Recalculate(); @@ -134,6 +135,10 @@ public void ClearSongSuggestions() public void GenerateOldestSongs(OldestSongSettings settings) { + //Refresh Player Data + activePlayerID = settings.scoreSaberID; + RefreshActivePlayer(); + oldestSongs = new OldestSongs(this); oldestSongs.Oldest100ActivePlayer(settings); status = "Ready"; @@ -166,7 +171,7 @@ public String GetSongRankingCount() //Clear all Banned Songs public void ClearBan() { - songBanning = new SongBanning() + songBanning = new SongBanning() { songSuggest = this }; diff --git a/TaohSongSuggest/manifest.json b/TaohSongSuggest/manifest.json index 372759c..e21515d 100644 --- a/TaohSongSuggest/manifest.json +++ b/TaohSongSuggest/manifest.json @@ -3,7 +3,7 @@ "id": "SmartSongSuggest", "name": "SmartSongSuggest", "author": "HypersonicSharkz & Taoh", - "version": "1.5.18", + "version": "1.5.19", "description": "Can make and update a playlist with ranked song suggestions, based on played and liked songs. Option to ban songs temporary or permanent. Can also make a playlist based on oldest ranked scores.", "gameVersion": "1.21.0", "dependsOn": {