From 6d3a13c1fd9f359528f17812e6a4bd81de4e87c6 Mon Sep 17 00:00:00 2001 From: FRUP Date: Mon, 2 Mar 2020 12:04:02 -0800 Subject: [PATCH 1/5] fix game crash when attempting to refresh with no maps in the songs dir Misc code refactors included with this commit. --- CHANGELOG.md | 3 +++ Pulsarc/UI/Screens/SongSelect/SongSelection.cs | 13 ++++++++----- Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs | 13 +++++-------- Pulsarc/Utils/SQLite/BeatmapData.cs | 5 +---- Pulsarc/Utils/Screenshotter.cs | 1 + 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cc52d2..480c1bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- A gamecrash when attemtping to refresh the song select when there are no maps in the song directory. + ## [1.4.1-alpha] - 2020-03-01 ### Fixed diff --git a/Pulsarc/UI/Screens/SongSelect/SongSelection.cs b/Pulsarc/UI/Screens/SongSelect/SongSelection.cs index 1a91cff..33eb4ab 100644 --- a/Pulsarc/UI/Screens/SongSelect/SongSelection.cs +++ b/Pulsarc/UI/Screens/SongSelect/SongSelection.cs @@ -111,7 +111,13 @@ public void RescanBeatmaps() DataManager.BeatmapDB.ClearBeatmaps(); - string[] directories = Directory.GetDirectories("Songs/"); + string[] directories = Array.Empty(); + + try + { + directories = Directory.GetDirectories("Songs/"); + } + catch { } for (int i = 0; i < directories.Length; i++) { @@ -183,10 +189,7 @@ public override void EnteredScreen() GetSongSelectionView().RefocusCurrentCard(); } - public override void UpdateDiscord() - { - PulsarcDiscord.SetStatus("", "Browsing Maps"); - } + public override void UpdateDiscord() => PulsarcDiscord.SetStatus("", "Browsing Maps"); private void HandleKeyboardPresses() { diff --git a/Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs b/Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs index ac1d9b5..e75ea79 100644 --- a/Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs +++ b/Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs @@ -181,15 +181,12 @@ private void StartChangingBackground(Texture2D newBackground) CurrentBackground.ChangeBackground(newBackground); CurrentBackground.Opacity = 0; } - else + else if (CurrentBackground.Texture != DefaultBackground.Texture) { - if (CurrentBackground.Texture != DefaultBackground.Texture) - { - ChangingBackground = true; - OldBackground = CurrentBackground; - CurrentBackground = DefaultBackground; - CurrentBackground.Opacity = 0; - } + ChangingBackground = true; + OldBackground = CurrentBackground; + CurrentBackground = DefaultBackground; + CurrentBackground.Opacity = 0; } } diff --git a/Pulsarc/Utils/SQLite/BeatmapData.cs b/Pulsarc/Utils/SQLite/BeatmapData.cs index 6cd8f9d..0fef76d 100644 --- a/Pulsarc/Utils/SQLite/BeatmapData.cs +++ b/Pulsarc/Utils/SQLite/BeatmapData.cs @@ -70,10 +70,7 @@ public BeatmapData(Beatmap beatmap) /// Format is "Artist - Title [Version] (Mapper)" /// /// - public override string ToString() - { - return $"{artist} - {title} [{version}] ({mapper})"; - } + public override string ToString() => $"{artist} - {title} [{version}] ({mapper})"; /// /// Find if this beatmap matches the search query. diff --git a/Pulsarc/Utils/Screenshotter.cs b/Pulsarc/Utils/Screenshotter.cs index 1b9bab5..da8d393 100644 --- a/Pulsarc/Utils/Screenshotter.cs +++ b/Pulsarc/Utils/Screenshotter.cs @@ -31,6 +31,7 @@ public static void Update() pressedAlready = true; } + // Won't get called until screenshot key is released. else if (pressedAlready) { pressedAlready = false; From 865ac4a7084be91fe039634477ceaa6e8d255c77 Mon Sep 17 00:00:00 2001 From: FRUP Date: Mon, 2 Mar 2020 12:06:35 -0800 Subject: [PATCH 2/5] Changed handling of SongTracks when AudioManager.Stop() is called Tracks now dispose when stop is called. --- Pulsarc/Utils/Audio/AudioManager.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Pulsarc/Utils/Audio/AudioManager.cs b/Pulsarc/Utils/Audio/AudioManager.cs index 248e3f9..9b48a0c 100644 --- a/Pulsarc/Utils/Audio/AudioManager.cs +++ b/Pulsarc/Utils/Audio/AudioManager.cs @@ -31,8 +31,7 @@ public static void StartLazyPlayer() { Stop(); - if (songPath == "") - return; + if (songPath == "") { return; } // Initialize the song try @@ -45,7 +44,7 @@ public static void StartLazyPlayer() } catch (AudioEngineException) { - PulsarcLogger.Debug(ManagedBass.Bass.LastError.ToString(), LogType.Runtime); + PulsarcLogger.Error(ManagedBass.Bass.LastError.ToString(), LogType.Runtime); } song.ApplyRate(Config.GetBool("Audio", "RatePitch")); @@ -80,7 +79,7 @@ public static void GameAudioPlayer() var threadTime = new Stopwatch(); // Initialize the song - song = new AudioTrack(songPath, false) + song = new AudioTrack(songPath, true) { Rate = audioRate, Volume = Config.GetInt("Audio", "MusicVolume"), @@ -183,9 +182,13 @@ public static void Stop() Pause(); if (song.IsPlaying) + { song.Stop(); + } + song.Dispose(); song = null; + Reset(); } } From f76ccf4fb4ce7a5e027f71a8f2fe42db2170bab4 Mon Sep 17 00:00:00 2001 From: FRUP Date: Mon, 2 Mar 2020 12:13:43 -0800 Subject: [PATCH 3/5] fix custom song rates not working --- Pulsarc/Utils/Audio/AudioManager.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Pulsarc/Utils/Audio/AudioManager.cs b/Pulsarc/Utils/Audio/AudioManager.cs index 9b48a0c..d91b927 100644 --- a/Pulsarc/Utils/Audio/AudioManager.cs +++ b/Pulsarc/Utils/Audio/AudioManager.cs @@ -72,14 +72,13 @@ public static void GameAudioPlayer() threadLimiterWatch.Start(); activeThreadLimiterWatch = true; - if (songPath == "") - return; + if (songPath == "") { return; } running = true; var threadTime = new Stopwatch(); // Initialize the song - song = new AudioTrack(songPath, true) + song = new AudioTrack(songPath) { Rate = audioRate, Volume = Config.GetInt("Audio", "MusicVolume"), From dcdb96f251f529dc763b35fd614a7b7129a31929 Mon Sep 17 00:00:00 2001 From: FRUP Date: Mon, 2 Mar 2020 12:20:10 -0800 Subject: [PATCH 4/5] add delete map functionality to game --- CHANGELOG.md | 3 + .../UI/Screens/SongSelect/SongSelection.cs | 78 +++++++++++++++---- 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 480c1bb..69b7d19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- The ability to delete maps from within game. Press and hold delete for 3 seconds and the currently selected map will be deleted. + ### Fixed - A gamecrash when attemtping to refresh the song select when there are no maps in the song directory. diff --git a/Pulsarc/UI/Screens/SongSelect/SongSelection.cs b/Pulsarc/UI/Screens/SongSelect/SongSelection.cs index 33eb4ab..d97ad87 100644 --- a/Pulsarc/UI/Screens/SongSelect/SongSelection.cs +++ b/Pulsarc/UI/Screens/SongSelect/SongSelection.cs @@ -1,16 +1,15 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using Pulsarc.Beatmaps; -using Pulsarc.UI.Screens.Gameplay; using Pulsarc.UI.Screens.SongSelect.UI; using Pulsarc.Utils; +using Pulsarc.Utils.Audio; using Pulsarc.Utils.Input; using Pulsarc.Utils.SQLite; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using Wobble.Input; using Wobble.Screens; namespace Pulsarc.UI.Screens.SongSelect @@ -43,28 +42,39 @@ public float SelectedFocus public BeatmapCard FocusedCard { get; set; } // The time when the last key was pressed - private double lastKeyPressTime; - - // Returns true once a second has passed since the last RestartKeyPressTimer = true call - private bool OneSecondSinceLastKeyPress - => PulsarcTime.CurrentElapsedTime >= (lastKeyPressTime + 1000); + private double lastSearchBoxKeyPressTime; + private const int SEARCHBOX_REFRESH_TIME = 1000; // When this is set to true, the timer resets. - private bool restartKeyPressTimer; - private bool RestartKeyPressTimer + private bool restartSearchBoxKeyPressTimer; + private bool RestartSearchBoxKeyPressTimer { - get => restartKeyPressTimer; + get => restartSearchBoxKeyPressTimer; set { if (value) { - lastKeyPressTime = PulsarcTime.CurrentElapsedTime; + lastSearchBoxKeyPressTime = PulsarcTime.CurrentElapsedTime; } - restartKeyPressTimer = value; + restartSearchBoxKeyPressTimer = value; } } + // Returns true once a second has passed since the last RestartKeyPressTimer = true call + private bool OneSecondSinceLastSearchBoxKeyPress + => PulsarcTime.CurrentElapsedTime >= (lastSearchBoxKeyPressTime + SEARCHBOX_REFRESH_TIME); + + // The last time "Delete" was pressed + private double lastDeleteKeyPress; + private const int DELETE_MAP_HOLD_TIME = 3000; + + private bool IsTimeUpSinceLastDeleteKeyPress + => PulsarcTime.CurrentElapsedTime >= (lastDeleteKeyPress + DELETE_MAP_HOLD_TIME); + + // Whether or not the user has already deleted the map with the current delete hold + private bool alreadyDeletedMap = false; + public SongSelection() { } @@ -169,6 +179,24 @@ public List SortBeatmaps(List beatmaps, string sort, bool asce } } + public void DeleteMap(in BeatmapCard card) + { + AudioManager.Stop(); + + string folder = new DirectoryInfo(card.Beatmap.Path).FullName; + try + { + Directory.Delete(folder, true); + } + catch (Exception e) + { + PulsarcLogger.Warning($"Couldn't delete all files in {folder}!" + + $"\n\nError:\n\n{e}"); + } + + RescanBeatmaps(); + } + public override void Update(GameTime gameTime) { HandleKeyboardPresses(); @@ -219,6 +247,8 @@ private void HandleKeyboardPresses() goto case Keys.Delete; // If Delete is pressed, clear the search bar case Keys.Delete: + lastDeleteKeyPress = PulsarcTime.CurrentElapsedTime; + // If there's nothing in the box, don't refresh. if (GetSongSelectionView().SearchBox.GetText().Length <= 0) { break; } @@ -226,7 +256,7 @@ private void HandleKeyboardPresses() RefreshBeatmaps(); // Stop the timer to prevent a second refresh - RestartKeyPressTimer = false; + RestartSearchBoxKeyPressTimer = false; break; // If the backspace is pressed, delete the last character case Keys.Back: @@ -237,7 +267,7 @@ private void HandleKeyboardPresses() } // Reset the timer - RestartKeyPressTimer = true; + RestartSearchBoxKeyPressTimer = true; GetSongSelectionView().SearchBox.DeleteLastCharacter(); break; @@ -248,7 +278,7 @@ private void HandleKeyboardPresses() if (!XnaKeyHelper.IsTypingCharacter(press.Value)) { break; } // Reset the timer - RestartKeyPressTimer = true; + RestartSearchBoxKeyPressTimer = true; string key = XnaKeyHelper.GetStringFromKey(press.Value); @@ -264,13 +294,27 @@ private void HandleKeyboardPresses() } // If one second has passed since the last search box key press, refresh the maps. - if (RestartKeyPressTimer && OneSecondSinceLastKeyPress) + if (RestartSearchBoxKeyPressTimer && OneSecondSinceLastSearchBoxKeyPress) { // Don't call this block every frame - RestartKeyPressTimer = false; + RestartSearchBoxKeyPressTimer = false; RefreshBeatmaps(GetSongSelectionView().SearchBox.GetText()); } + // If the user has been holding on to Delete for more than a second, + // delete the currently focused map + else if (InputManager.PressedKeys.Contains(Keys.Delete)) + { + if (IsTimeUpSinceLastDeleteKeyPress && !alreadyDeletedMap) + { + DeleteMap(FocusedCard); + alreadyDeletedMap = true; + } + } + else if (alreadyDeletedMap) + { + alreadyDeletedMap = false; + } } private void HandleMouseInput() From 949dcd3a40932c788f4b93070f7ae2778499b2f7 Mon Sep 17 00:00:00 2001 From: FRUP Date: Mon, 2 Mar 2020 14:59:22 -0800 Subject: [PATCH 5/5] prepare for release --- CHANGELOG.md | 5 ++++- Pulsarc/Pulsarc.csproj | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69b7d19..1e60425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.4.2-alpha] - 2020-03-02 + ### Added - The ability to delete maps from within game. Press and hold delete for 3 seconds and the currently selected map will be deleted. @@ -135,7 +137,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Leaderboard for past scores -[unreleased]: https://github.com/PulsarcGame/Pulsarc/compare/v1.4.1-alpha...HEAD +[unreleased]: https://github.com/PulsarcGame/Pulsarc/compare/v1.4.2-alpha...HEAD +[1.4.2-alpha]: https://github.com/PulsarcGame/Pulsarc/compare/v1.4.1-alpha...v1.4.2-alpha [1.4.1-alpha]: https://github.com/PulsarcGame/Pulsarc/compare/v1.4.0-alpha...v1.4.1-alpha [1.4.0-alpha]: https://github.com/PulsarcGame/Pulsarc/compare/v1.3.2-alpha...v1.4.0-alpha [1.3.2-alpha]: https://github.com/PulsarcGame/Pulsarc/compare/v1.3.1-alpha...v1.3.2-alpha diff --git a/Pulsarc/Pulsarc.csproj b/Pulsarc/Pulsarc.csproj index 6b03e7a..faad6b0 100644 --- a/Pulsarc/Pulsarc.csproj +++ b/Pulsarc/Pulsarc.csproj @@ -9,8 +9,8 @@ Pulsarc Icon.ico - 1.4.1.0 - 1.4.1.0 + 1.4.2.0 + 1.4.2.0