1
0
mirror of synced 2024-12-12 15:51:16 +01:00
OpenTaiko/TJAPlayer3/Common/Favorites.cs

63 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace TJAPlayer3
{
internal class Favorites
{
public void tFavorites() {
if (!File.Exists("Favorite.json"))
tSaveFile();
tLoadFile();
}
2022-03-03 02:08:29 +01:00
#region [Auxiliary methods]
public void tToggleFavorite(string chartID)
{
2022-03-03 02:08:29 +01:00
if (tIsFavorite(chartID))
data.favorites[TJAPlayer3.SaveFile].Remove(chartID);
else
data.favorites[TJAPlayer3.SaveFile].Add(chartID);
tSaveFile();
}
2022-03-03 02:08:29 +01:00
public bool tIsFavorite(string chartID)
{
return (data.favorites[TJAPlayer3.SaveFile].Contains(chartID));
}
#endregion
public class Data
{
public HashSet<string>[] favorites = new HashSet<string>[2] { new HashSet<string>(), new HashSet<string>() };
}
public Data data = new Data();
#region [private]
private void tSaveFile()
{
ConfigManager.SaveConfig(data, "Favorite.json");
}
private void tLoadFile()
{
data = ConfigManager.GetConfig<Data>(@"Favorite.json");
}
#endregion
}
}