Skip to content

Commit

Permalink
Merge pull request #196 from halsafar/release-6.4.0
Browse files Browse the repository at this point in the history
Release 6.4.0
  • Loading branch information
halsafar authored Oct 10, 2022
2 parents 9fa86aa + b812441 commit 9841cb1
Show file tree
Hide file tree
Showing 16 changed files with 505 additions and 433 deletions.
75 changes: 73 additions & 2 deletions SongBrowserPlugin/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using IPA.Config.Stores;
using IPA.Config.Stores.Attributes;
Expand All @@ -7,22 +8,42 @@
[assembly: InternalsVisibleTo(GeneratedStore.AssemblyVisibilityTarget)]
namespace SongBrowser.Configuration
{
public enum SortFilterStates
{
Disabled = 0,
Enabled = 1,
}

internal class PluginConfig
{
public static PluginConfig Instance { get; set; }
public virtual SongSortMode SortMode { get; set; } = default;
public virtual SongFilterMode FilterMode { get; set; } = default;

public virtual SongSortMode SortMode { get; set; } = SongSortMode.Original;

[UseConverter(typeof(DictionaryConverter<SortFilterStates>))]
[NonNullable]
public virtual Dictionary<string, SortFilterStates> FilterModes { get; set; } = new Dictionary<string, SortFilterStates>();

[UseConverter(typeof(ListConverter<string>))]
[NonNullable]
public virtual List<string> SearchTerms { get; set; } = new List<string>();

public virtual string CurrentLevelId { get; set; } = default;

public virtual string CurrentLevelCollectionName { get; set; } = default;

public virtual string CurrentLevelCategoryName { get; set; } = default;

public virtual bool RandomInstantQueueSong { get; set; } = false;

public virtual bool ExperimentalScrapeSongMetaData { get; set; } = true;

public virtual bool DeleteNumberedSongFolder { get; set; } = false;

public virtual bool InvertSortResults { get; set; } = false;

public virtual int RandomSongSeed { get; set; } = default;

public virtual int MaxSearchTerms { get; set; } = 10;

/// <summary>
Expand All @@ -43,5 +64,55 @@ public virtual void CopyFrom(PluginConfig other)
{

}

public void ResetSortMode()
{
SortMode = SongSortMode.Original;
}

public void ResetFilterMode()
{
FilterModes.Clear();
}

public string GetFilterModeString()
{
string filterModeStr = null;
foreach (var kvp in FilterModes)
{
if (kvp.Value == SortFilterStates.Enabled)
{
if (!string.IsNullOrEmpty(filterModeStr))
{
filterModeStr = "Multiple";
break;
}
else
{
filterModeStr = kvp.Key.ToString();
}
}
}

if (string.IsNullOrEmpty(filterModeStr))
{
return SongFilterMode.None.ToString();
}

return filterModeStr;
}

public bool IsFilterEnabled(SongFilterMode f)
{
if (FilterModes.ContainsKey(f.ToString()))
return FilterModes[f.ToString()] == SortFilterStates.Enabled;

return false;
}

public void SetFilterState(SongFilterMode f, SortFilterStates state)
{
FilterModes[f.ToString()] = state;
}
}
}
32 changes: 23 additions & 9 deletions SongBrowserPlugin/Configuration/SongFilterMode.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SongBrowser.Configuration
{
public enum SongFilterMode
{
None,
Favorites,
Playlist,
Search,
Ranked,
Unranked,
Played,
Unplayed,
Requirements,

Easy,
Normal,
Hard,
Expert,
ExpertPlus,
// For other mods that extend SongBrowser
Custom
Custom,
// Deprecated
Favorites
}

static class SongFilterModeMethods
{
public static bool NeedsScoreSaberData(this SongFilterMode s)
{
switch (s)
{
case SongFilterMode.Ranked:
case SongFilterMode.Unranked:
return true;
default:
return false;
}
}
}
}
24 changes: 7 additions & 17 deletions SongBrowserPlugin/Configuration/SongMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using Logger = SongBrowser.Logging.Logger;

namespace SongBrowser.Configuration
{
Expand All @@ -16,9 +15,6 @@ internal class SongMetadataStore
[JsonIgnore]
private string _storePath;

[JsonIgnore]
private bool _dirty = false;

[UseConverter(typeof(DictionaryConverter<SongMetadata>))]
[NonNullable]
public virtual Dictionary<string, SongMetadata> Songs { get; set; } = new Dictionary<string, SongMetadata>();
Expand All @@ -42,16 +38,16 @@ public static void Load()

try
{
Logger.Debug("Loading SongMetaDataStore: {0}", storePath);
Plugin.Log.Debug($"Loading SongMetaDataStore: {storePath}");
using StreamReader file = File.OpenText(storePath);
JsonSerializer serializer = new JsonSerializer();
SongMetadataStore.Instance = (SongMetadataStore)serializer.Deserialize(file, typeof(SongMetadataStore));
SongMetadataStore.Instance._storePath = storePath;
}
catch (JsonReaderException e)
{
Logger.Exception("Could not parse SongMetaDataStore: {0}", e);
Logger.Warning("SongMetaDataStore is corrupted, deleting, creating new store...");
Plugin.Log.Critical($"Could not parse SongMetaDataStore: {e}");
Plugin.Log.Warn("SongMetaDataStore is corrupted, deleting, creating new store...");
File.Delete(storePath);
SongMetadataStore.CreateEmptyStore(storePath);
}
Expand All @@ -62,20 +58,13 @@ public virtual SongMetadata GetMetadataForLevelID(string levelID)
if (!Instance.Songs.ContainsKey(levelID))
{
Instance.Songs.Add(levelID, new SongMetadata());
_dirty = true;
}
return Instance.Songs[levelID];
}

public void Save()
{
// Skip Saving
if (!this._dirty)
{
return;
}

Logger.Debug("Saving SongMetaDataStore: {0}", this._storePath);
Plugin.Log.Debug($"Saving SongMetaDataStore: {this._storePath}");

using StreamWriter file = File.CreateText(this._storePath);

Expand All @@ -86,14 +75,15 @@ public void Save()
JsonSerializer serializer = JsonSerializer.Create(opts);

serializer.Serialize(file, this);

this._dirty = false;
}
}

internal class SongMetadata
{
[UseConverter]
public virtual DateTime? AddedAt { get; set; }

[UseConverter]
public virtual DateTime? LastPlayed { get; set; } = null;
}
}
17 changes: 11 additions & 6 deletions SongBrowserPlugin/Configuration/SongSortMode.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SongBrowser.Configuration
{
public enum SongSortMode
Expand All @@ -25,6 +20,7 @@ public enum SongSortMode
Bpm,
Length,
Vanilla,
LastPlayed,

// Allow mods to extend functionality.
Custom,
Expand Down Expand Up @@ -52,5 +48,14 @@ public static bool NeedsScoreSaberData(this SongSortMode s)
return false;
}
}

public static bool NeedsRefresh(this SongSortMode s)
{
return s switch
{
SongSortMode.LastPlayed => true,
_ => false,
};
}
}
}
Loading

0 comments on commit 9841cb1

Please sign in to comment.