diff --git a/TaikoWebUI/Pages/AccessCode.razor b/TaikoWebUI/Pages/AccessCode.razor index 535c676..9d124d5 100644 --- a/TaikoWebUI/Pages/AccessCode.razor +++ b/TaikoWebUI/Pages/AccessCode.razor @@ -3,7 +3,7 @@ @inject IDialogService DialogService @inject LoginService LoginService @inject NavigationManager NavigationManager -@inject IStringUtil StringUtil +@inject TaikoWebUI.Utilities.StringUtil StringUtil; @if (response is not null) { diff --git a/TaikoWebUI/Pages/Components/UserCard.razor b/TaikoWebUI/Pages/Components/UserCard.razor index 86892c9..d530502 100644 --- a/TaikoWebUI/Pages/Components/UserCard.razor +++ b/TaikoWebUI/Pages/Components/UserCard.razor @@ -1,11 +1,12 @@ @using Microsoft.AspNetCore.Components; @using TaikoWebUI.Pages.Dialogs; +@inject TaikoWebUI.Utilities.StringUtil StringUtil; @inject IDialogService DialogService; -@inject IStringUtil StringUtil; @inject LoginService LoginService; @inject HttpClient Client @inject NavigationManager NavigationManager + @if (user is not null) { diff --git a/TaikoWebUI/Pages/Songs.razor b/TaikoWebUI/Pages/Songs.razor index 6615654..b620ae3 100644 --- a/TaikoWebUI/Pages/Songs.razor +++ b/TaikoWebUI/Pages/Songs.razor @@ -3,6 +3,7 @@ @inject LoginService LoginService @inject IJSRuntime JSRuntime @inject NavigationManager NavigationManager +@using TaikoWebUI.Utilities @page "/Users/{baid:int}/Songs" @@ -39,8 +40,8 @@ { @if (difficulty is not Difficulty.None) { - + @if (songBestDataMap.TryGetValue(difficulty, out var value)) { - - @GetGenreTitle(context.Item.Genre) + @ScoreUtils.GetGenreTitle(context.Item.Genre) - @(GetCrownText(context.Item.BestCrown)) + @(ScoreUtils.GetCrownText(context.Item.BestCrown)) @if (context.Item.BestScoreRank is not ScoreRank.None) { - @(GetRankText(context.Item.BestScoreRank)) + @(ScoreUtils.GetRankText(context.Item.BestScoreRank)) } @@ -106,8 +107,8 @@ + OnClick="@(() => ToggleShowAiData(context.Item))" + Disabled="@(!ScoreUtils.IsAiDataPresent(context.Item))"> @(context.Item.ShowAiData ? @Localizer["Hide"] : @Localizer["Show"]) @@ -153,7 +154,7 @@ @aiSectionContext.Score - @(GetCrownText(aiSectionContext.Crown)) + @(ScoreUtils.GetCrownText(aiSectionContext.Crown)) @aiSectionContext.GoodCount @aiSectionContext.OkCount diff --git a/TaikoWebUI/Pages/Songs.razor.cs b/TaikoWebUI/Pages/Songs.razor.cs index 0ecc8da..0e8140d 100644 --- a/TaikoWebUI/Pages/Songs.razor.cs +++ b/TaikoWebUI/Pages/Songs.razor.cs @@ -70,92 +70,8 @@ public partial class Songs } } - 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 $"{difficulty}"; - } - - 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", - SongGenre.GameMusic => "background: #cc8aea; color: #fff", - SongGenre.NamcoOriginal => "background: #ff7027; color: #fff", - SongGenre.Variety => "background: #1dc83b; color: #fff", - SongGenre.Classical => "background: #bfa356", - _ => "" - }; - } - private static void ToggleShowAiData(SongBestData data) { data.ShowAiData = !data.ShowAiData; } - - private static bool IsAiDataPresent(SongBestData data) - { - var aiData = data.AiSectionBestData; - - return aiData.Count > 0; - } } diff --git a/TaikoWebUI/Program.cs b/TaikoWebUI/Program.cs index d051dcc..2032111 100644 --- a/TaikoWebUI/Program.cs +++ b/TaikoWebUI/Program.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.JSInterop; using MudBlazor.Services; using TaikoWebUI.Settings; +using TaikoWebUI.Utilities; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); @@ -20,7 +21,9 @@ builder.Services.Configure(builder.Configuration.GetSection(nameo builder.Services.AddScoped(); builder.Services.AddLocalization(); builder.Services.AddSingleton(); -builder.Services.AddSingleton(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + var host = builder.Build(); diff --git a/TaikoWebUI/Services/StringUtil.cs b/TaikoWebUI/Services/StringUtil.cs deleted file mode 100644 index b06d6e8..0000000 --- a/TaikoWebUI/Services/StringUtil.cs +++ /dev/null @@ -1,17 +0,0 @@ -public interface IStringUtil -{ - List SplitIntoGroups(string str, int groupSize); -} - -public class StringUtil : IStringUtil -{ - public List SplitIntoGroups(string str, int groupSize) - { - List groups = new List(); - for (int i = 0; i < str.Length; i += groupSize) - { - groups.Add(str.Substring(i, Math.Min(groupSize, str.Length - i))); - } - return groups; - } -} \ No newline at end of file diff --git a/TaikoWebUI/Utilities/ScoreUtils.cs b/TaikoWebUI/Utilities/ScoreUtils.cs new file mode 100644 index 0000000..c3ea454 --- /dev/null +++ b/TaikoWebUI/Utilities/ScoreUtils.cs @@ -0,0 +1,90 @@ + +namespace TaikoWebUI.Utilities +{ + public class ScoreUtils + { + public static string GetCrownText(CrownType crown) + { + return crown switch + { + CrownType.None => "Fail", + CrownType.Clear => "Clear", + CrownType.Gold => "Full Combo", + CrownType.Dondaful => "Donderful Combo", + _ => "" + }; + } + + public 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", + _ => "" + }; + } + + public static string GetDifficultyTitle(Difficulty difficulty) + { + return difficulty switch + { + Difficulty.Easy => "Easy", + Difficulty.Normal => "Normal", + Difficulty.Hard => "Hard", + Difficulty.Oni => "Oni", + Difficulty.UraOni => "Ura Oni", + _ => "" + }; + } + + public static string GetDifficultyIcon(Difficulty difficulty) + { + return $"{difficulty}"; + } + + public 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", + _ => "" + }; + } + + public 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", + SongGenre.GameMusic => "background: #cc8aea; color: #fff", + SongGenre.NamcoOriginal => "background: #ff7027; color: #fff", + SongGenre.Variety => "background: #1dc83b; color: #fff", + SongGenre.Classical => "background: #bfa356", + _ => "" + }; + } + + public static bool IsAiDataPresent(SongBestData data) + { + var aiData = data.AiSectionBestData; + + return aiData.Count > 0; + } + } +} \ No newline at end of file diff --git a/TaikoWebUI/Utilities/StringUtil.cs b/TaikoWebUI/Utilities/StringUtil.cs new file mode 100644 index 0000000..53abedb --- /dev/null +++ b/TaikoWebUI/Utilities/StringUtil.cs @@ -0,0 +1,20 @@ +namespace TaikoWebUI.Utilities +{ + public interface IStringUtil + { + List SplitIntoGroups(string str, int groupSize); + } + + public class StringUtil : IStringUtil + { + public List SplitIntoGroups(string str, int groupSize) + { + List groups = new List(); + for (int i = 0; i < str.Length; i += groupSize) + { + groups.Add(str.Substring(i, Math.Min(groupSize, str.Length - i))); + } + return groups; + } + } +} \ No newline at end of file