From 128f2834fe7425db8f7875130e666bb2653cec33 Mon Sep 17 00:00:00 2001 From: shiibe Date: Wed, 14 Sep 2022 17:20:55 -0400 Subject: [PATCH] Add autocomplete for player title --- TaikoWebUI/Pages/Profile.razor | 2 +- TaikoWebUI/Pages/Profile.razor.cs | 12 ++++++++++ TaikoWebUI/Services/GameDataService.cs | 33 ++++++++++++++++++++------ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/TaikoWebUI/Pages/Profile.razor b/TaikoWebUI/Pages/Profile.razor index 8e3ba5e..7991626 100644 --- a/TaikoWebUI/Pages/Profile.razor +++ b/TaikoWebUI/Pages/Profile.razor @@ -20,7 +20,7 @@ - + diff --git a/TaikoWebUI/Pages/Profile.razor.cs b/TaikoWebUI/Pages/Profile.razor.cs index dc5c5bb..9c37a68 100644 --- a/TaikoWebUI/Pages/Profile.razor.cs +++ b/TaikoWebUI/Pages/Profile.razor.cs @@ -1,4 +1,5 @@ using MudBlazor.Utilities; +using static MudBlazor.Colors; namespace TaikoWebUI.Pages; @@ -72,4 +73,15 @@ public partial class Profile isSavingOptions = false; } + private async Task> SearchForTitle(string value) + { + var titles = GameDataService.titleMap; + + if (string.IsNullOrWhiteSpace(value)) + { + return titles.Values; + } + + return titles.Values.Where(x => x.Contains(value, StringComparison.OrdinalIgnoreCase)); + } } \ No newline at end of file diff --git a/TaikoWebUI/Services/GameDataService.cs b/TaikoWebUI/Services/GameDataService.cs index f421683..fcf9380 100644 --- a/TaikoWebUI/Services/GameDataService.cs +++ b/TaikoWebUI/Services/GameDataService.cs @@ -13,19 +13,22 @@ public class GameDataService : IGameDataService private ImmutableDictionary danMap = null!; - public const uint COSTUME_HEAD_MAX = 140; - public const uint COSTUME_FACE_MAX = 59; - public const uint COSTUME_BODY_MAX = 156; - public const uint COSTUME_KIGURUMI_MAX = 154; - public const uint COSTUME_PUCHI_MAX = 129; - public const uint COSTUME_COLOR_MAX = 63; - + public const int COSTUME_HEAD_MAX = 140; + public const int COSTUME_FACE_MAX = 59; + 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 = 749; + public static string[] headMap = new string[COSTUME_HEAD_MAX]; public static string[] faceMap = new string[COSTUME_FACE_MAX]; public static string[] bodyMap = new string[COSTUME_BODY_MAX]; public static string[] kigurumiMap = new string[COSTUME_KIGURUMI_MAX]; public static string[] puchiMap = new string[COSTUME_PUCHI_MAX]; + public static Dictionary titleMap = new(); + public GameDataService(HttpClient client) { this.client = client; @@ -118,6 +121,22 @@ public class GameDataService : IGameDataService var costumeWordlistItem = dict.GetValueOrDefault(key, new WordListEntry()); puchiMap[index] = costumeWordlistItem.JapaneseText; } + + for (var i = 1; i < PLAYER_TITLE_MAX; i++) + { + var index = i; + var key = $"syougou_{index}"; + + var titleWordlistItem = dict.GetValueOrDefault(key, new WordListEntry()); + + // prevent duplicate values with different keys + if (titleMap.ContainsValue(titleWordlistItem.JapaneseText)) + { + continue; + } + + titleMap.TryAdd(index, titleWordlistItem.JapaneseText); + } } public string GetMusicNameBySongId(uint songId)