2024-05-25 19:12:30 +02:00
|
|
|
|
using System.Globalization;
|
2024-05-01 17:13:47 +02:00
|
|
|
|
using Microsoft.JSInterop;
|
2024-08-13 17:07:39 +02:00
|
|
|
|
using SharedProject.Models;
|
2024-05-01 17:13:47 +02:00
|
|
|
|
|
|
|
|
|
namespace TaikoWebUI.Pages;
|
|
|
|
|
|
|
|
|
|
public partial class PlayHistory
|
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int Baid { get; set; }
|
|
|
|
|
|
|
|
|
|
private const string IconStyle = "width:25px; height:25px;";
|
|
|
|
|
|
|
|
|
|
private string Search { get; set; } = string.Empty;
|
|
|
|
|
|
2024-05-27 00:06:51 +02:00
|
|
|
|
private string? songNameLanguage;
|
2024-05-01 17:13:47 +02:00
|
|
|
|
|
|
|
|
|
private SongHistoryResponse? response;
|
2024-08-13 17:07:39 +02:00
|
|
|
|
private UserSetting? userSetting;
|
2024-05-01 17:13:47 +02:00
|
|
|
|
|
|
|
|
|
private Dictionary<DateTime, List<SongHistoryData>> songHistoryDataMap = new();
|
|
|
|
|
|
2024-05-25 19:12:30 +02:00
|
|
|
|
private Dictionary<uint, MusicDetail> musicDetailDictionary = new();
|
|
|
|
|
|
2024-05-01 17:13:47 +02: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-05-01 17:13:47 +02:00
|
|
|
|
response = await Client.GetFromJsonAsync<SongHistoryResponse>($"api/PlayHistory/{(uint)Baid}");
|
|
|
|
|
response.ThrowIfNull();
|
2024-08-13 17:07:39 +02:00
|
|
|
|
|
|
|
|
|
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
|
|
|
|
|
|
2024-05-27 00:06:51 +02:00
|
|
|
|
songNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
|
2024-05-25 19:12:30 +02:00
|
|
|
|
|
|
|
|
|
musicDetailDictionary = await GameDataService.GetMusicDetailDictionary();
|
2024-05-01 17:13:47 +02:00
|
|
|
|
|
|
|
|
|
response.SongHistoryData.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-05-25 19:12:30 +02:00
|
|
|
|
data.Stars = GameDataService.GetMusicStarLevel(musicDetailDictionary, songId, data.Difficulty);
|
2024-05-01 17:13:47 +02:00
|
|
|
|
data.ShowDetails = false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
songHistoryDataMap = response.SongHistoryData.GroupBy(data => data.PlayTime).ToDictionary(data => data.Key,data => data.ToList());
|
|
|
|
|
foreach (var songHistoryDataList in songHistoryDataMap.Values)
|
|
|
|
|
{
|
|
|
|
|
songHistoryDataList.Sort((data1, data2) => data1.SongNumber.CompareTo(data2.SongNumber));
|
|
|
|
|
}
|
2024-08-14 11:07:37 +02:00
|
|
|
|
|
|
|
|
|
//breadcrumbs
|
|
|
|
|
BreadcrumbsStateContainer.breadcrumbs.Clear();
|
|
|
|
|
if (AuthService.IsLoggedIn && !AuthService.IsAdmin) BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
|
|
|
|
|
else BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
|
|
|
|
|
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
|
|
|
|
|
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Play History"], href: $"/Users/{Baid}/PlayHistory", disabled: false));
|
|
|
|
|
BreadcrumbsStateContainer.NotifyStateChanged();
|
2024-05-01 17:13:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetCrownText(CrownType crown)
|
|
|
|
|
{
|
|
|
|
|
return crown switch
|
|
|
|
|
{
|
|
|
|
|
CrownType.None => "Fail",
|
|
|
|
|
CrownType.Clear => "Clear",
|
|
|
|
|
CrownType.Gold => "Full Combo",
|
|
|
|
|
CrownType.Dondaful => "Donderful Combo",
|
|
|
|
|
_ => ""
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetRankText(ScoreRank rank)
|
|
|
|
|
{
|
|
|
|
|
return rank switch
|
|
|
|
|
{
|
|
|
|
|
ScoreRank.White => "Stylish",
|
|
|
|
|
ScoreRank.Bronze => "Stylish",
|
|
|
|
|
ScoreRank.Silver => "Stylish",
|
|
|
|
|
ScoreRank.Gold => "Graceful",
|
|
|
|
|
ScoreRank.Sakura => "Graceful",
|
|
|
|
|
ScoreRank.Purple => "Graceful",
|
|
|
|
|
ScoreRank.Dondaful => "Top Class",
|
|
|
|
|
_ => ""
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetDifficultyTitle(Difficulty difficulty)
|
|
|
|
|
{
|
|
|
|
|
return difficulty switch
|
|
|
|
|
{
|
|
|
|
|
Difficulty.Easy => "Easy",
|
|
|
|
|
Difficulty.Normal => "Normal",
|
|
|
|
|
Difficulty.Hard => "Hard",
|
|
|
|
|
Difficulty.Oni => "Oni",
|
|
|
|
|
Difficulty.UraOni => "Ura Oni",
|
|
|
|
|
_ => ""
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetDifficultyIcon(Difficulty difficulty)
|
|
|
|
|
{
|
|
|
|
|
return $"<image href='/images/difficulty_{difficulty}.png' alt='{difficulty}' width='24' height='24'/>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetGenreTitle(SongGenre genre)
|
|
|
|
|
{
|
|
|
|
|
return genre switch
|
|
|
|
|
{
|
|
|
|
|
SongGenre.Pop => "Pop",
|
|
|
|
|
SongGenre.Anime => "Anime",
|
|
|
|
|
SongGenre.Kids => "Kids",
|
|
|
|
|
SongGenre.Vocaloid => "Vocaloid",
|
|
|
|
|
SongGenre.GameMusic => "Game Music",
|
|
|
|
|
SongGenre.NamcoOriginal => "NAMCO Original",
|
|
|
|
|
SongGenre.Variety => "Variety",
|
|
|
|
|
SongGenre.Classical => "Classical",
|
|
|
|
|
_ => ""
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetGenreStyle(SongGenre genre)
|
|
|
|
|
{
|
|
|
|
|
return genre switch
|
|
|
|
|
{
|
|
|
|
|
SongGenre.Pop => "background: #42c0d2; color: #fff",
|
|
|
|
|
SongGenre.Anime => "background: #ff90d3; color: #fff",
|
|
|
|
|
SongGenre.Kids => "background: #fec000; color: #fff",
|
|
|
|
|
SongGenre.Vocaloid => "background: #ddd; color: #000",
|
|
|
|
|
SongGenre.GameMusic => "background: #cc8aea; color: #fff",
|
|
|
|
|
SongGenre.NamcoOriginal => "background: #ff7027; color: #fff",
|
|
|
|
|
SongGenre.Variety => "background: #1dc83b; color: #fff",
|
|
|
|
|
SongGenre.Classical => "background: #bfa356; color: #000",
|
|
|
|
|
_ => ""
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool FilterSongs(List<SongHistoryData> songHistoryDataList)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(Search))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 00:06:51 +02:00
|
|
|
|
var language = songNameLanguage ?? "ja";
|
2024-05-01 17:13:47 +02:00
|
|
|
|
|
|
|
|
|
if (songHistoryDataList[0].PlayTime
|
|
|
|
|
.ToString("dddd d MMMM yyyy - HH:mm", CultureInfo.CreateSpecificCulture(language))
|
|
|
|
|
.Contains(Search, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var songHistoryData in songHistoryDataList)
|
|
|
|
|
{
|
|
|
|
|
if (songHistoryData.MusicName.Contains(Search, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (songHistoryData.MusicArtist.Contains(Search, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnFavoriteToggled(SongHistoryData 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|