1
0
mirror of synced 2024-11-24 15:40:22 +01:00
OpenTaiko/TJAPlayer3/Common/Favorites.cs
2022-03-03 02:08:29 +01:00

63 lines
1.4 KiB
C#

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();
}
#region [Auxiliary methods]
public void tToggleFavorite(string chartID)
{
if (tIsFavorite(chartID))
data.favorites[TJAPlayer3.SaveFile].Remove(chartID);
else
data.favorites[TJAPlayer3.SaveFile].Add(chartID);
tSaveFile();
}
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
}
}