2024-05-27 00:06:51 +02:00
|
|
|
|
namespace TaikoWebUI.Pages;
|
2024-03-17 20:46:47 +01:00
|
|
|
|
|
|
|
|
|
public partial class HighScores
|
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int Baid { get; set; }
|
|
|
|
|
|
|
|
|
|
private SongBestResponse? response;
|
|
|
|
|
private UserSetting? userSetting;
|
|
|
|
|
private Dictionary<Difficulty, List<SongBestData>> songBestDataMap = new();
|
2024-05-25 19:12:30 +02:00
|
|
|
|
private int selectedDifficultyTab;
|
|
|
|
|
private Dictionary<uint, MusicDetail> musicDetailDictionary = new();
|
2024-03-17 20:46:47 +01:00
|
|
|
|
|
2024-10-31 12:40:30 +01:00
|
|
|
|
private string Search { get; set; } = string.Empty;
|
|
|
|
|
private string GenreFilter { get; set; } = string.Empty;
|
|
|
|
|
|
2024-03-17 20:46:47 +01:00
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
await base.OnInitializedAsync();
|
2024-05-25 19:12:30 +02:00
|
|
|
|
|
|
|
|
|
if (AuthService.LoginRequired && !AuthService.IsLoggedIn)
|
|
|
|
|
{
|
|
|
|
|
await AuthService.LoginWithAuthToken();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 20:46:47 +01:00
|
|
|
|
response = await Client.GetFromJsonAsync<SongBestResponse>($"api/PlayData/{Baid}");
|
|
|
|
|
response.ThrowIfNull();
|
|
|
|
|
|
|
|
|
|
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
|
|
|
|
|
|
2024-05-27 00:06:51 +02:00
|
|
|
|
var songNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
|
2024-05-25 19:12:30 +02:00
|
|
|
|
musicDetailDictionary = await GameDataService.GetMusicDetailDictionary();
|
2024-03-17 20:46:47 +01:00
|
|
|
|
|
|
|
|
|
response.SongBestData.ForEach(data =>
|
|
|
|
|
{
|
|
|
|
|
var songId = data.SongId;
|
2024-05-25 19:12:30 +02:00
|
|
|
|
data.Genre = GameDataService.GetMusicGenreBySongId(musicDetailDictionary, songId);
|
2024-05-27 00:06:51 +02:00
|
|
|
|
data.MusicName = GameDataService.GetMusicNameBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage);
|
|
|
|
|
data.MusicArtist = GameDataService.GetMusicArtistBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage);
|
2024-03-17 20:46:47 +01:00
|
|
|
|
});
|
|
|
|
|
|
2024-10-29 14:33:03 +01:00
|
|
|
|
//We get rid of entries with empty song names
|
|
|
|
|
//This can happen if the database has been used with a different version of the songlist (Omnimix/Version update)
|
|
|
|
|
response.SongBestData = response.SongBestData.FindAll(x => x.MusicName != "");
|
|
|
|
|
|
2024-03-17 20:46:47 +01:00
|
|
|
|
songBestDataMap = response.SongBestData.GroupBy(data => data.Difficulty)
|
|
|
|
|
.ToDictionary(data => data.Key,
|
|
|
|
|
data => data.ToList());
|
2024-10-29 14:33:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-17 20:46:47 +01:00
|
|
|
|
foreach (var songBestDataList in songBestDataMap.Values)
|
|
|
|
|
{
|
2024-05-25 19:12:30 +02:00
|
|
|
|
songBestDataList.Sort((data1, data2) => GameDataService.GetMusicIndexBySongId(musicDetailDictionary, data1.SongId)
|
|
|
|
|
.CompareTo(GameDataService.GetMusicIndexBySongId(musicDetailDictionary, data2.SongId)));
|
2024-03-17 20:46:47 +01:00
|
|
|
|
}
|
2024-05-17 00:32:46 +02:00
|
|
|
|
|
2024-03-27 04:08:12 +01:00
|
|
|
|
// Set last selected tab from local storage
|
2024-05-17 00:32:46 +02:00
|
|
|
|
selectedDifficultyTab = await LocalStorage.GetItemAsync<int>($"highScoresTab");
|
2024-03-27 04:08:12 +01:00
|
|
|
|
|
|
|
|
|
// Breadcrumbs
|
2024-08-13 17:07:39 +02:00
|
|
|
|
BreadcrumbsStateContainer.breadcrumbs.Clear();
|
2024-05-17 00:32:46 +02:00
|
|
|
|
if (AuthService.IsLoggedIn && !AuthService.IsAdmin)
|
2024-03-17 20:46:47 +01:00
|
|
|
|
{
|
2024-08-13 17:07:39 +02:00
|
|
|
|
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
|
2024-03-17 20:46:47 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-08-13 17:07:39 +02:00
|
|
|
|
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
|
2024-03-17 20:46:47 +01:00
|
|
|
|
};
|
2024-08-13 17:07:39 +02:00
|
|
|
|
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
|
|
|
|
|
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["High Scores"], href: $"/Users/{Baid}/HighScores", disabled: false));
|
|
|
|
|
BreadcrumbsStateContainer.NotifyStateChanged();
|
2024-03-17 20:46:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnFavoriteToggled(SongBestData data)
|
|
|
|
|
{
|
|
|
|
|
var request = new SetFavoriteRequest
|
|
|
|
|
{
|
|
|
|
|
Baid = (uint)Baid,
|
|
|
|
|
IsFavorite = !data.IsFavorite,
|
|
|
|
|
SongId = data.SongId
|
|
|
|
|
};
|
|
|
|
|
var result = await Client.PostAsJsonAsync("api/FavoriteSongs", request);
|
|
|
|
|
if (result.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
data.IsFavorite = !data.IsFavorite;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 04:08:12 +01:00
|
|
|
|
private async Task OnTabChanged(int index)
|
2024-03-17 20:46:47 +01:00
|
|
|
|
{
|
2024-03-27 04:08:12 +01:00
|
|
|
|
selectedDifficultyTab = index;
|
2024-05-17 00:32:46 +02:00
|
|
|
|
await LocalStorage.SetItemAsync($"highScoresTab", selectedDifficultyTab);
|
2024-03-17 20:46:47 +01:00
|
|
|
|
}
|
2024-10-31 12:40:30 +01:00
|
|
|
|
|
|
|
|
|
private bool FilterSongs(SongBestData songData)
|
|
|
|
|
{
|
|
|
|
|
var stringsToCheck = new List<string>
|
|
|
|
|
{
|
|
|
|
|
songData.MusicName,
|
|
|
|
|
songData.MusicArtist,
|
|
|
|
|
songData.BestScore.ToString(),
|
|
|
|
|
songData.PlayTime.ToString(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (songData.IsFavorite) stringsToCheck.Add("Favorite");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Search) && !stringsToCheck.Any(s => s.Contains(Search, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(GenreFilter) && songData.Genre != Enum.Parse<SongGenre>(GenreFilter))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-03-17 20:46:47 +01:00
|
|
|
|
}
|