Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustdustinthewind committed Mar 2, 2020
2 parents 071db75 + 949dcd3 commit bc077bf
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 43 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Pulsarc/Pulsarc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<AssemblyName>Pulsarc</AssemblyName>
<ApplicationIcon>Icon.ico</ApplicationIcon>
<StartupObject></StartupObject>
<AssemblyVersion>1.4.1.0</AssemblyVersion>
<FileVersion>1.4.1.0</FileVersion>
<AssemblyVersion>1.4.2.0</AssemblyVersion>
<FileVersion>1.4.2.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
91 changes: 69 additions & 22 deletions Pulsarc/UI/Screens/SongSelect/SongSelection.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
{ }

Expand Down Expand Up @@ -111,7 +121,13 @@ public void RescanBeatmaps()

DataManager.BeatmapDB.ClearBeatmaps();

string[] directories = Directory.GetDirectories("Songs/");
string[] directories = Array.Empty<string>();

try
{
directories = Directory.GetDirectories("Songs/");
}
catch { }

for (int i = 0; i < directories.Length; i++)
{
Expand Down Expand Up @@ -163,6 +179,24 @@ public List<Beatmap> SortBeatmaps(List<Beatmap> 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();
Expand All @@ -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()
{
Expand Down Expand Up @@ -216,14 +247,16 @@ 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; }

GetSongSelectionView().SearchBox.Clear();
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:
Expand All @@ -234,7 +267,7 @@ private void HandleKeyboardPresses()
}

// Reset the timer
RestartKeyPressTimer = true;
RestartSearchBoxKeyPressTimer = true;

GetSongSelectionView().SearchBox.DeleteLastCharacter();
break;
Expand All @@ -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);

Expand All @@ -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()
Expand Down
13 changes: 5 additions & 8 deletions Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
14 changes: 8 additions & 6 deletions Pulsarc/Utils/Audio/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public static void StartLazyPlayer()
{
Stop();

if (songPath == "")
return;
if (songPath == "") { return; }

// Initialize the song
try
Expand All @@ -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"));
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -183,9 +181,13 @@ public static void Stop()
Pause();

if (song.IsPlaying)
{
song.Stop();
}

song.Dispose();
song = null;

Reset();
}
}
Expand Down
5 changes: 1 addition & 4 deletions Pulsarc/Utils/SQLite/BeatmapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ public BeatmapData(Beatmap beatmap)
/// Format is "Artist - Title [Version] (Mapper)"
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"{artist} - {title} [{version}] ({mapper})";
}
public override string ToString() => $"{artist} - {title} [{version}] ({mapper})";

/// <summary>
/// Find if this beatmap matches the search query.
Expand Down
1 change: 1 addition & 0 deletions Pulsarc/Utils/Screenshotter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static void Update()

pressedAlready = true;
}
// Won't get called until screenshot key is released.
else if (pressedAlready)
{
pressedAlready = false;
Expand Down

0 comments on commit bc077bf

Please sign in to comment.