diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4cc52d2..1e60425 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,14 @@ 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.
+
+### 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
@@ -129,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
diff --git a/Pulsarc/UI/Screens/SongSelect/SongSelection.cs b/Pulsarc/UI/Screens/SongSelect/SongSelection.cs
index 1a91cff..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()
{ }
@@ -111,7 +121,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++)
{
@@ -163,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();
@@ -183,10 +217,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()
{
@@ -216,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; }
@@ -223,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:
@@ -234,7 +267,7 @@ private void HandleKeyboardPresses()
}
// Reset the timer
- RestartKeyPressTimer = true;
+ RestartSearchBoxKeyPressTimer = true;
GetSongSelectionView().SearchBox.DeleteLastCharacter();
break;
@@ -245,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);
@@ -261,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()
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/Audio/AudioManager.cs b/Pulsarc/Utils/Audio/AudioManager.cs
index 248e3f9..d91b927 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"));
@@ -73,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, false)
+ song = new AudioTrack(songPath)
{
Rate = audioRate,
Volume = Config.GetInt("Audio", "MusicVolume"),
@@ -183,9 +181,13 @@ public static void Stop()
Pause();
if (song.IsPlaying)
+ {
song.Stop();
+ }
+ song.Dispose();
song = null;
+
Reset();
}
}
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;