diff --git a/SharedProject/Enums/SongGenre.cs b/SharedProject/Enums/SongGenre.cs new file mode 100644 index 0000000..2b0400f --- /dev/null +++ b/SharedProject/Enums/SongGenre.cs @@ -0,0 +1,13 @@ +namespace SharedProject.Enums; + +public enum SongGenre +{ + Pop = 0, + Anime = 1, + Kids = 2, + Vocaloid = 3, + GameMusic = 4, + NamcoOriginal = 5, + Variety = 7, + Classical = 8 +} \ No newline at end of file diff --git a/TaikoLocalServer.sln.DotSettings b/TaikoLocalServer.sln.DotSettings index 4153d9b..eea663e 100644 --- a/TaikoLocalServer.sln.DotSettings +++ b/TaikoLocalServer.sln.DotSettings @@ -1,2 +1,4 @@  - True \ No newline at end of file + True + True + True \ No newline at end of file diff --git a/TaikoWebUI/Pages/PlayResults.razor b/TaikoWebUI/Pages/PlayResults.razor index 2fa8550..9beaea4 100644 --- a/TaikoWebUI/Pages/PlayResults.razor +++ b/TaikoWebUI/Pages/PlayResults.razor @@ -3,6 +3,7 @@ @using SharedProject.Models @using SharedProject.Models.Requests @using SharedProject.Enums +@using Throw @inject IGameDataService GameDataService @inject HttpClient Client @@ -14,65 +15,72 @@ Card: @Baid -@if (response is null) -{ - - - No data. - - -} -else -{ - - - - - - @GameDataService.GetMusicNameBySongId(context.Item.SongId) - @GameDataService.GetMusicArtistBySongId(context.Item.SongId) - - - - - - @(context.Item.Difficulty) - - - - - - - - @(context.Item.BestCrown) - - - - - - - - - - - - - - - - - - - - - - -} + @if (response is null) + { + + + No data. + + + } + else + { + + + @foreach (var genre in Enum.GetValues()) + { + + + + + + @GameDataService.GetMusicNameBySongId(context.Item.SongId) + @GameDataService.GetMusicArtistBySongId(context.Item.SongId) + + + + + + @(context.Item.Difficulty) + + + + + + + + @(context.Item.BestCrown) + + + + + + + + + + + + + + + + + + + + + + + } + + + } @@ -82,7 +90,7 @@ else public int Baid { get; set; } private SongBestResponse? response; - + private const string ICON_STYLE = "width:25px; height:25px;"; private readonly List breadcrumbs = new() @@ -94,7 +102,13 @@ else { await base.OnInitializedAsync(); response = await Client.GetFromJsonAsync($"api/PlayData/{Baid}"); - + response.ThrowIfNull(); + response.SongBestData.Sort((data1, data2) => + { + return GameDataService.GetMusicIndexBySongId(data1.SongId) + .CompareTo(GameDataService.GetMusicIndexBySongId(data2.SongId)); + }); + breadcrumbs.Add(new BreadcrumbItem($"Card: {Baid}", href: null, disabled: true)); breadcrumbs.Add(new BreadcrumbItem("Play Data", href: $"/Cards/{Baid}/PlayResults", disabled: false)); } @@ -123,7 +137,7 @@ else CrownType.Gold => "Full Combo", CrownType.Dondaful => "Donderful Combo", _ => "" - }; + }; } } \ No newline at end of file diff --git a/TaikoWebUI/Services/GameDataService.cs b/TaikoWebUI/Services/GameDataService.cs index 4163d8f..7a7f94a 100644 --- a/TaikoWebUI/Services/GameDataService.cs +++ b/TaikoWebUI/Services/GameDataService.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using System.Net.Http.Json; +using SharedProject.Enums; using TaikoWebUI.Shared.Models; using Throw; @@ -9,9 +10,7 @@ public class GameDataService : IGameDataService { private readonly HttpClient client; - private readonly Dictionary musicNameMap = new(); - - private readonly Dictionary musicArtistMap = new(); + private readonly Dictionary musicMap = new(); public GameDataService(HttpClient client) { @@ -22,10 +21,13 @@ public class GameDataService : IGameDataService { var musicInfo = await client.GetFromJsonAsync($"{dataBaseUrl}/data/musicinfo.json"); var wordList = await client.GetFromJsonAsync($"{dataBaseUrl}/data/wordlist.json"); + var musicOrder = await client.GetFromJsonAsync($"{dataBaseUrl}/data/music_order.json"); musicInfo.ThrowIfNull(); wordList.ThrowIfNull(); + musicOrder.ThrowIfNull(); + // To prevent duplicate entries in wordlist var dict = wordList.WordListEntries.GroupBy(entry => entry.Key) .ToImmutableDictionary(group => group.Key, group => group.First()); foreach (var music in musicInfo.Items) @@ -35,19 +37,47 @@ public class GameDataService : IGameDataService var musicName = dict.GetValueOrDefault(songNameKey, new WordListEntry()); var musicArtist = dict.GetValueOrDefault(songArtistKey, new WordListEntry()); - - musicNameMap.TryAdd(music.SongId, musicName.JapaneseText); - musicArtistMap.TryAdd(music.SongId, musicArtist.JapaneseText); + + var musicSongId = music.SongId; + var musicDetail = new MusicDetail + { + SongId = musicSongId, + SongName = musicName.JapaneseText, + ArtistName = musicArtist.JapaneseText, + Genre = music.Genre + }; + + musicMap.TryAdd(musicSongId, musicDetail); + } + + for (var index = 0; index < musicOrder.Order.Count; index++) + { + var musicOrderEntry = musicOrder.Order[index]; + var songId = musicOrderEntry.SongId; + if (musicMap.ContainsKey(songId)) + { + musicMap[songId].Index = index; + } } } public string GetMusicNameBySongId(uint songId) { - return musicNameMap.GetValueOrDefault(songId, string.Empty); + return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.SongName : string.Empty; } public string GetMusicArtistBySongId(uint songId) { - return musicArtistMap.GetValueOrDefault(songId, string.Empty); + return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.ArtistName : string.Empty; } + public SongGenre GetMusicGenreBySongId(uint songId) + { + return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.Genre : SongGenre.Variety; + } + + public int GetMusicIndexBySongId(uint songId) + { + return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.Index : int.MaxValue; + } + } \ No newline at end of file diff --git a/TaikoWebUI/Services/IGameDataService.cs b/TaikoWebUI/Services/IGameDataService.cs index d5a1410..fa8d49f 100644 --- a/TaikoWebUI/Services/IGameDataService.cs +++ b/TaikoWebUI/Services/IGameDataService.cs @@ -1,4 +1,7 @@ -namespace TaikoWebUI.Services; +using SharedProject.Enums; +using TaikoWebUI.Shared.Models; + +namespace TaikoWebUI.Services; public interface IGameDataService { @@ -7,4 +10,8 @@ public interface IGameDataService public string GetMusicNameBySongId(uint songId); public string GetMusicArtistBySongId(uint songId); + + public SongGenre GetMusicGenreBySongId(uint songId); + + public int GetMusicIndexBySongId(uint songId); } \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/MusicDetail.cs b/TaikoWebUI/Shared/Models/MusicDetail.cs new file mode 100644 index 0000000..402e2eb --- /dev/null +++ b/TaikoWebUI/Shared/Models/MusicDetail.cs @@ -0,0 +1,16 @@ +using SharedProject.Enums; + +namespace TaikoWebUI.Shared.Models; + +public class MusicDetail +{ + public uint SongId { get; set; } + + public int Index { get; set; } + + public string SongName { get; set; } = string.Empty; + + public string ArtistName { get; set; } = string.Empty; + + public SongGenre Genre { get; set; } +} \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/MusicInfoEntry.cs b/TaikoWebUI/Shared/Models/MusicInfoEntry.cs index 0eda2de..c2b1dec 100644 --- a/TaikoWebUI/Shared/Models/MusicInfoEntry.cs +++ b/TaikoWebUI/Shared/Models/MusicInfoEntry.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using SharedProject.Enums; namespace TaikoWebUI.Shared.Models; @@ -11,5 +12,5 @@ public class MusicInfoEntry public uint SongId { get; set; } [JsonPropertyName("genreNo")] - public uint Genre { get; set; } + public SongGenre Genre { get; set; } } \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/MusicOrder.cs b/TaikoWebUI/Shared/Models/MusicOrder.cs new file mode 100644 index 0000000..1a8016c --- /dev/null +++ b/TaikoWebUI/Shared/Models/MusicOrder.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace TaikoWebUI.Shared.Models; + +public class MusicOrder +{ + [JsonPropertyName("items")] + public List Order { get; set; } = new(); +} \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/MusicOrderEntry.cs b/TaikoWebUI/Shared/Models/MusicOrderEntry.cs new file mode 100644 index 0000000..5d9a694 --- /dev/null +++ b/TaikoWebUI/Shared/Models/MusicOrderEntry.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; +using SharedProject.Enums; + +namespace TaikoWebUI.Shared.Models; + +public class MusicOrderEntry +{ + [JsonPropertyName("uniqueId")] + public uint SongId { get; set; } +} \ No newline at end of file diff --git a/TaikoWebUI/TaikoWebUI.csproj b/TaikoWebUI/TaikoWebUI.csproj index ef4626d..fda0f91 100644 --- a/TaikoWebUI/TaikoWebUI.csproj +++ b/TaikoWebUI/TaikoWebUI.csproj @@ -28,5 +28,9 @@ + + + + \ No newline at end of file