Move functions to TaikoWebUI.Utilities
namespace
This commit is contained in:
parent
254807d9eb
commit
e8f3d50942
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
<MudCard Outlined="true">
|
||||
|
@ -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)
|
||||
{
|
||||
<MudTabPanel Text="@GetDifficultyTitle(difficulty)"
|
||||
Icon="@GetDifficultyIcon(difficulty)">
|
||||
<MudTabPanel Text="@ScoreUtils.GetDifficultyTitle(difficulty)"
|
||||
Icon="@ScoreUtils.GetDifficultyIcon(difficulty)">
|
||||
@if (songBestDataMap.TryGetValue(difficulty, out var value))
|
||||
{
|
||||
<MudDataGrid Items="@value"
|
||||
@ -78,23 +79,23 @@
|
||||
<TemplateColumn T="SongBestData" Title=@Localizer["Genre"]
|
||||
Sortable="false" Filterable="true">
|
||||
<CellTemplate>
|
||||
<MudChip Style="@GetGenreStyle(context.Item.Genre)"
|
||||
<MudChip Style="@ScoreUtils.GetGenreStyle(context.Item.Genre)"
|
||||
Size="Size.Small">
|
||||
@GetGenreTitle(context.Item.Genre)
|
||||
@ScoreUtils.GetGenreTitle(context.Item.Genre)
|
||||
</MudChip>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Property="data => data.BestScore" Title=@Localizer["Best Score"] />
|
||||
<TemplateColumn T="SongBestData" Title=@Localizer["Best Crown"]>
|
||||
<CellTemplate>
|
||||
<img src="@($"/images/crown_{context.Item.BestCrown}.png")" alt="@(GetCrownText(context.Item.BestCrown))" title="@(GetCrownText(context.Item.BestCrown))" style="@IconStyle" />
|
||||
<img src="@($"/images/crown_{context.Item.BestCrown}.png")" alt="@(ScoreUtils.GetCrownText(context.Item.BestCrown))" title="@(ScoreUtils.GetCrownText(context.Item.BestCrown))" style="@IconStyle" />
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn T="SongBestData" Title=@Localizer["Best Rank"] Sortable="false">
|
||||
<CellTemplate>
|
||||
@if (context.Item.BestScoreRank is not ScoreRank.None)
|
||||
{
|
||||
<img src="@($"/images/rank_{context.Item.BestScoreRank}.png")" alt="@(GetRankText(context.Item.BestScoreRank))" title="@(GetRankText(context.Item.BestScoreRank))" style="@IconStyle" />
|
||||
<img src="@($"/images/rank_{context.Item.BestScoreRank}.png")" alt="@(ScoreUtils.GetRankText(context.Item.BestScoreRank))" title="@(ScoreUtils.GetRankText(context.Item.BestScoreRank))" style="@IconStyle" />
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
@ -106,8 +107,8 @@
|
||||
<TemplateColumn T="SongBestData" Title=@Localizer["AI Battle Data"]>
|
||||
<CellTemplate>
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small"
|
||||
OnClick="@(() => ToggleShowAiData(context.Item))"
|
||||
Disabled="@(!IsAiDataPresent(context.Item))">
|
||||
OnClick="@(() => ToggleShowAiData(context.Item))"
|
||||
Disabled="@(!ScoreUtils.IsAiDataPresent(context.Item))">
|
||||
@(context.Item.ShowAiData ? @Localizer["Hide"] : @Localizer["Show"])
|
||||
</MudButton>
|
||||
</CellTemplate>
|
||||
@ -153,7 +154,7 @@
|
||||
</MudTd>
|
||||
<MudTd>@aiSectionContext.Score</MudTd>
|
||||
<MudTd>
|
||||
<img src="@($"/images/ai_crown_{aiSectionContext.Crown}.png")" alt="@(GetCrownText(aiSectionContext.Crown))" title="@(GetCrownText(aiSectionContext.Crown))" style="@IconStyle" />
|
||||
<img src="@($"/images/ai_crown_{aiSectionContext.Crown}.png")" alt="@(ScoreUtils.GetCrownText(aiSectionContext.Crown))" title="@(ScoreUtils.GetCrownText(aiSectionContext.Crown))" style="@IconStyle" />
|
||||
</MudTd>
|
||||
<MudTd>@aiSectionContext.GoodCount</MudTd>
|
||||
<MudTd>@aiSectionContext.OkCount</MudTd>
|
||||
|
@ -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 $"<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",
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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>("#app");
|
||||
@ -20,7 +21,9 @@ builder.Services.Configure<WebUiSettings>(builder.Configuration.GetSection(nameo
|
||||
builder.Services.AddScoped<LoginService>();
|
||||
builder.Services.AddLocalization();
|
||||
builder.Services.AddSingleton<MudLocalizer, ResXMudLocalizer>();
|
||||
builder.Services.AddSingleton<IStringUtil, StringUtil>();
|
||||
builder.Services.AddSingleton<ScoreUtils>();
|
||||
builder.Services.AddSingleton<StringUtil>();
|
||||
|
||||
|
||||
var host = builder.Build();
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
public interface IStringUtil
|
||||
{
|
||||
List<string> SplitIntoGroups(string str, int groupSize);
|
||||
}
|
||||
|
||||
public class StringUtil : IStringUtil
|
||||
{
|
||||
public List<string> SplitIntoGroups(string str, int groupSize)
|
||||
{
|
||||
List<string> groups = new List<string>();
|
||||
for (int i = 0; i < str.Length; i += groupSize)
|
||||
{
|
||||
groups.Add(str.Substring(i, Math.Min(groupSize, str.Length - i)));
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
}
|
90
TaikoWebUI/Utilities/ScoreUtils.cs
Normal file
90
TaikoWebUI/Utilities/ScoreUtils.cs
Normal file
@ -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 $"<image href='/images/difficulty_{difficulty}.png' alt='{difficulty}' width='24' height='24'/>";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
20
TaikoWebUI/Utilities/StringUtil.cs
Normal file
20
TaikoWebUI/Utilities/StringUtil.cs
Normal file
@ -0,0 +1,20 @@
|
||||
namespace TaikoWebUI.Utilities
|
||||
{
|
||||
public interface IStringUtil
|
||||
{
|
||||
List<string> SplitIntoGroups(string str, int groupSize);
|
||||
}
|
||||
|
||||
public class StringUtil : IStringUtil
|
||||
{
|
||||
public List<string> SplitIntoGroups(string str, int groupSize)
|
||||
{
|
||||
List<string> groups = new List<string>();
|
||||
for (int i = 0; i < str.Length; i += groupSize)
|
||||
{
|
||||
groups.Add(str.Substring(i, Math.Min(groupSize, str.Length - i)));
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user