diff --git a/TaikoWebUI/Pages/Profile.razor b/TaikoWebUI/Pages/Profile.razor index 3420ae5..dc8db34 100644 --- a/TaikoWebUI/Pages/Profile.razor +++ b/TaikoWebUI/Pages/Profile.razor @@ -104,7 +104,7 @@ - @for (var i = 0; i < Constants.COSTUME_HEAD_MAX; i++) + @for (var i = 0; i < costumeFlagArraySizes[1]; i++) { var index = (uint)i; var costumeTitle = GameDataService.GetHeadTitle(index); @@ -113,7 +113,7 @@ - @for (var i = 0; i < Constants.COSTUME_BODY_MAX; i++) + @for (var i = 0; i < costumeFlagArraySizes[2]; i++) { var index = (uint)i; var costumeTitle = GameDataService.GetBodyTitle(index); @@ -122,7 +122,7 @@ - @for (var i = 0; i < Constants.COSTUME_FACE_MAX; i++) + @for (var i = 0; i < costumeFlagArraySizes[3]; i++) { var index = (uint)i; var costumeTitle = GameDataService.GetFaceTitle(index); @@ -131,7 +131,7 @@ - @for (var i = 0; i < Constants.COSTUME_KIGURUMI_MAX; i++) + @for (var i = 0; i < costumeFlagArraySizes[0]; i++) { var index = (uint)i; var costumeTitle = GameDataService.GetKigurumiTitle(index); @@ -140,7 +140,7 @@ - @for (var i = 0; i < Constants.COSTUME_PUCHI_MAX; i++) + @for (var i = 0; i < costumeFlagArraySizes[4]; i++) { var index = (uint)i; var costumeTitle = GameDataService.GetPuchiTitle(index); diff --git a/TaikoWebUI/Pages/Profile.razor.cs b/TaikoWebUI/Pages/Profile.razor.cs index 082aff9..ef30ef4 100644 --- a/TaikoWebUI/Pages/Profile.razor.cs +++ b/TaikoWebUI/Pages/Profile.razor.cs @@ -77,6 +77,8 @@ public partial class Profile { new BreadcrumbItem("Cards", href: "/Cards"), }; + + private List costumeFlagArraySizes = new(); protected override async Task OnInitializedAsync() { @@ -86,6 +88,8 @@ public partial class Profile breadcrumbs.Add(new BreadcrumbItem($"Card: {Baid}", href: null, disabled: true)); breadcrumbs.Add(new BreadcrumbItem("Profile", href: $"/Cards/{Baid}/Profile", disabled: false)); + + costumeFlagArraySizes = GameDataService.GetCostumeFlagArraySizes(); } private async Task SaveOptions() diff --git a/TaikoWebUI/Services/GameDataService.cs b/TaikoWebUI/Services/GameDataService.cs index 0f16824..e1c0197 100644 --- a/TaikoWebUI/Services/GameDataService.cs +++ b/TaikoWebUI/Services/GameDataService.cs @@ -1,9 +1,4 @@ using System.Collections.Immutable; -using System.IO.Compression; -using System.Net; -using System.Security.Cryptography; -using System.Text.Json; -using ICSharpCode.SharpZipLib.GZip; using Swan.Mapping; using TaikoWebUI.Shared.Models; @@ -11,15 +6,19 @@ namespace TaikoWebUI.Services; public class GameDataService : IGameDataService { - private readonly string[] bodyTitles = new string[Constants.COSTUME_BODY_MAX]; + private string[] bodyTitles; private readonly HttpClient client; - private readonly string[] faceTitles = new string[Constants.COSTUME_FACE_MAX]; + private string[] faceTitles; - private readonly string[] headTitles = new string[Constants.COSTUME_HEAD_MAX]; - private readonly string[] kigurumiMTitles = new string[Constants.COSTUME_KIGURUMI_MAX]; + private string[] headTitles; + private string[] kigurumiTitles; private readonly Dictionary musicMap = new(); - private readonly string[] puchiTitles = new string[Constants.COSTUME_PUCHI_MAX]; + private string[] puchiTitles; + + private List costumeFlagArraySizes = new(); + + private int titleFlagArraySize; private ImmutableDictionary danMap = ImmutableDictionary.Empty; @@ -34,8 +33,10 @@ public class GameDataService : IGameDataService { dataBaseUrl = dataBaseUrl.TrimEnd('/'); var musicInfo = await GetData(dataBaseUrl, Constants.MUSIC_INFO_BASE_NAME); - var wordList = await GetData(dataBaseUrl, Constants.WORD_LIST_BASE_NAME); + var wordList = await GetData(dataBaseUrl, Constants.WORDLIST_BASE_NAME); var musicOrder = await GetData(dataBaseUrl, Constants.MUSIC_ORDER_BASE_NAME); + var donCosRewardData = await GetData(dataBaseUrl, Constants.DON_COS_REWARD_BASE_NAME); + var shougouData = await GetData(dataBaseUrl, Constants.SHOUGOU_BASE_NAME); var danData = await client.GetFromJsonAsync>($"{dataBaseUrl}/data/dan_data.json"); danData.ThrowIfNull(); @@ -45,6 +46,9 @@ public class GameDataService : IGameDataService var dict = wordList.WordListEntries.GroupBy(entry => entry.Key) .ToImmutableDictionary(group => group.Key, group => group.First()); await Task.Run(() => InitializeMusicMap(musicInfo, dict, musicOrder)); + + InitializeCostumeFlagArraySizes(donCosRewardData); + InitializeTitleFlagArraySize(shougouData); await Task.Run(() => InitializeHeadTitles(dict)); await Task.Run(() => InitializeFaceTitles(dict)); @@ -108,7 +112,7 @@ public class GameDataService : IGameDataService public string GetKigurumiTitle(uint index) { - return index < kigurumiMTitles.Length ? kigurumiMTitles[index] : string.Empty; + return index < kigurumiTitles.Length ? kigurumiTitles[index] : string.Empty; } public string GetBodyTitle(uint index) @@ -130,11 +134,22 @@ public class GameDataService : IGameDataService { return titles; } + + public List GetCostumeFlagArraySizes() + { + return costumeFlagArraySizes; + } + + private void InitializeTitleFlagArraySize(Shougous? shougouData) + { + shougouData.ThrowIfNull("Shouldn't happen!"); + titleFlagArraySize = (int)shougouData.ShougouEntries.Max(entry => entry.uniqueId) + 1; + } private void InitializeTitles(ImmutableDictionary dict) { var set = ImmutableHashSet.CreateBuilder(); - for (var i = 1; i < Constants.PLAYER_TITLE_MAX; i++) + for (var i = 1; i < titleFlagArraySize; i++) { var key = $"syougou_{i}"; @@ -148,32 +163,67 @@ public class GameDataService : IGameDataService titles = set.ToImmutable(); } - - private void InitializePuchiTitles(ImmutableDictionary<string, WordListEntry> dict) + + private void InitializeCostumeFlagArraySizes(DonCosRewards? donCosRewardData) { - for (var i = 0; i < Constants.COSTUME_PUCHI_MAX; i++) + donCosRewardData.ThrowIfNull("Shouldn't happen!"); + var kigurumiUniqueIdList = donCosRewardData.DonCosRewardEntries + .Where(entry => entry.cosType == "kigurumi") + .Select(entry => entry.uniqueId); + var headUniqueIdList = donCosRewardData.DonCosRewardEntries + .Where(entry => entry.cosType == "head") + .Select(entry => entry.uniqueId); + var bodyUniqueIdList = donCosRewardData.DonCosRewardEntries + .Where(entry => entry.cosType == "body") + .Select(entry => entry.uniqueId); + var faceUniqueIdList = donCosRewardData.DonCosRewardEntries + .Where(entry => entry.cosType == "face") + .Select(entry => entry.uniqueId); + var puchiUniqueIdList = donCosRewardData.DonCosRewardEntries + .Where(entry => entry.cosType == "puchi") + .Select(entry => entry.uniqueId); + + costumeFlagArraySizes = new List<int> { - var key = $"costume_puchi_{i}"; - - var costumeWordlistItem = dict.GetValueOrDefault(key, new WordListEntry()); - puchiTitles[i] = costumeWordlistItem.JapaneseText; - } + (int)kigurumiUniqueIdList.Max() + 1, + (int)headUniqueIdList.Max() + 1, + (int)bodyUniqueIdList.Max() + 1, + (int)faceUniqueIdList.Max() + 1, + (int)puchiUniqueIdList.Max() + 1 + }; } - + private void InitializeKigurumiTitles(ImmutableDictionary<string, WordListEntry> dict) { - for (var i = 0; i < Constants.COSTUME_KIGURUMI_MAX; i++) + var costumeKigurumiMax = costumeFlagArraySizes[0]; + kigurumiTitles = new string[costumeKigurumiMax]; + for (var i = 0; i < costumeKigurumiMax; i++) { var key = $"costume_kigurumi_{i}"; var costumeWordlistItem = dict.GetValueOrDefault(key, new WordListEntry()); - kigurumiMTitles[i] = costumeWordlistItem.JapaneseText; + kigurumiTitles[i] = costumeWordlistItem.JapaneseText; } } + + private void InitializeHeadTitles(ImmutableDictionary<string, WordListEntry> dict) + { + var costumeHeadMax = costumeFlagArraySizes[1]; + headTitles = new string[costumeHeadMax]; + for (var i = 0; i < costumeHeadMax; i++) + { + var key = $"costume_head_{i}"; + var costumeWordlistItem = dict.GetValueOrDefault(key, new WordListEntry()); + headTitles[i] = costumeWordlistItem.JapaneseText; + } + } + private void InitializeBodyTitles(ImmutableDictionary<string, WordListEntry> dict) { - for (var i = 0; i < Constants.COSTUME_BODY_MAX; i++) + var costumeBodyMax = costumeFlagArraySizes[2]; + bodyTitles = new string[costumeBodyMax]; + for (var i = 0; i < costumeBodyMax; i++) { var key = $"costume_body_{i}"; @@ -181,10 +231,12 @@ public class GameDataService : IGameDataService bodyTitles[i] = costumeWordlistItem.JapaneseText; } } - + private void InitializeFaceTitles(ImmutableDictionary<string, WordListEntry> dict) { - for (var i = 0; i < Constants.COSTUME_FACE_MAX; i++) + var costumeFaceMax = costumeFlagArraySizes[3]; + faceTitles = new string[costumeFaceMax]; + for (var i = 0; i < costumeFaceMax; i++) { var key = $"costume_face_{i}"; @@ -193,14 +245,16 @@ public class GameDataService : IGameDataService } } - private void InitializeHeadTitles(ImmutableDictionary<string, WordListEntry> dict) + private void InitializePuchiTitles(ImmutableDictionary<string, WordListEntry> dict) { - for (var i = 0; i < Constants.COSTUME_HEAD_MAX; i++) + var costumePuchiMax = costumeFlagArraySizes[4]; + puchiTitles = new string[costumePuchiMax]; + for (var i = 0; i < costumePuchiMax; i++) { - var key = $"costume_head_{i}"; + var key = $"costume_puchi_{i}"; var costumeWordlistItem = dict.GetValueOrDefault(key, new WordListEntry()); - headTitles[i] = costumeWordlistItem.JapaneseText; + puchiTitles[i] = costumeWordlistItem.JapaneseText; } } diff --git a/TaikoWebUI/Services/IGameDataService.cs b/TaikoWebUI/Services/IGameDataService.cs index b5a7310..4d1946c 100644 --- a/TaikoWebUI/Services/IGameDataService.cs +++ b/TaikoWebUI/Services/IGameDataService.cs @@ -24,6 +24,8 @@ public interface IGameDataService public string GetBodyTitle(uint index); public string GetFaceTitle(uint index); public string GetPuchiTitle(uint index); + + public List<int> GetCostumeFlagArraySizes(); public ImmutableHashSet<Title> GetTitles(); } \ No newline at end of file diff --git a/TaikoWebUI/Shared/Constants.cs b/TaikoWebUI/Shared/Constants.cs index c795ffe..c77be7d 100644 --- a/TaikoWebUI/Shared/Constants.cs +++ b/TaikoWebUI/Shared/Constants.cs @@ -2,15 +2,11 @@ public static class Constants { - public const int COSTUME_HEAD_MAX = 140; - public const int COSTUME_FACE_MAX = 58; - public const int COSTUME_BODY_MAX = 156; - public const int COSTUME_KIGURUMI_MAX = 154; - public const int COSTUME_PUCHI_MAX = 129; public const int COSTUME_COLOR_MAX = 63; - public const int PLAYER_TITLE_MAX = 750; public const string MUSIC_INFO_BASE_NAME = "musicinfo"; - public const string WORD_LIST_BASE_NAME = "wordlist"; - public const string MUSIC_ORDER_BASE_NAME = "music_order"; + public const string WORDLIST_BASE_NAME = "wordlist"; + public const string MUSIC_ORDER_BASE_NAME = "music_order"; + public const string DON_COS_REWARD_BASE_NAME = "don_cos_reward"; + public const string SHOUGOU_BASE_NAME = "shougou"; } \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/DonCosRewardEntry.cs b/TaikoWebUI/Shared/Models/DonCosRewardEntry.cs new file mode 100644 index 0000000..57db82e --- /dev/null +++ b/TaikoWebUI/Shared/Models/DonCosRewardEntry.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace TaikoWebUI.Shared.Models; + +public class DonCosRewardEntry +{ + [JsonPropertyName("cosType")] + public string cosType { get; set; } = null!; + + [JsonPropertyName("uniqueId")] + public uint uniqueId { get; set; } +} \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/DonCosRewards.cs b/TaikoWebUI/Shared/Models/DonCosRewards.cs new file mode 100644 index 0000000..95bbf7b --- /dev/null +++ b/TaikoWebUI/Shared/Models/DonCosRewards.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace TaikoWebUI.Shared.Models; + +public class DonCosRewards +{ + [JsonPropertyName("items")] + public List<DonCosRewardEntry> DonCosRewardEntries { get; set; } = new(); +} \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/NeiroEntry.cs b/TaikoWebUI/Shared/Models/NeiroEntry.cs new file mode 100644 index 0000000..852e972 --- /dev/null +++ b/TaikoWebUI/Shared/Models/NeiroEntry.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace TaikoWebUI.Shared.Models; + +public class NeiroEntry +{ + [JsonPropertyName("uniqueId")] + public uint uniqueId { get; set; } +} \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/Neiros.cs b/TaikoWebUI/Shared/Models/Neiros.cs new file mode 100644 index 0000000..728ba8b --- /dev/null +++ b/TaikoWebUI/Shared/Models/Neiros.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace TaikoWebUI.Shared.Models; + +public class Neiros +{ + [JsonPropertyName("items")] + public List<NeiroEntry> NeiroEntries { get; set; } = new(); +} \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/ShougouEntry.cs b/TaikoWebUI/Shared/Models/ShougouEntry.cs new file mode 100644 index 0000000..1f1270e --- /dev/null +++ b/TaikoWebUI/Shared/Models/ShougouEntry.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace TaikoWebUI.Shared.Models; + +public class ShougouEntry +{ + [JsonPropertyName("uniqueId")] + public uint uniqueId { get; set; } +} \ No newline at end of file diff --git a/TaikoWebUI/Shared/Models/Shougous.cs b/TaikoWebUI/Shared/Models/Shougous.cs new file mode 100644 index 0000000..4a27738 --- /dev/null +++ b/TaikoWebUI/Shared/Models/Shougous.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace TaikoWebUI.Shared.Models; + +public class Shougous +{ + [JsonPropertyName("items")] + public List<ShougouEntry> ShougouEntries { get; set; } = new(); +} \ No newline at end of file