1
0
mirror of synced 2024-11-24 06:50:15 +01:00
This commit is contained in:
asesidaa 2022-09-15 15:27:27 +08:00
parent f8ef701b86
commit e6eb83af2c
5 changed files with 89 additions and 102 deletions

View File

@ -21,18 +21,8 @@
<MudGrid> <MudGrid>
<MudItem xs="12" md="8"> <MudItem xs="12" md="8">
@if (enterTextDirectly) <MudTextField @bind-Value="@response.Title" Label="Title"/>
{ <MudButton></MudButton>
<MudTextField @bind-Value="@response.Title" Label="Title"></MudTextField>
}
else
{
<MudAutocomplete @bind-Value="@response.Title" Label="Title"
Dense="true" Clearable="true" Immediate="true"
SearchFunc="@SearchForTitle" CoerceValue="true" CoerceText="true"
MaxItems="@Constants.PLAYER_TITLE_MAX"/>
}
<MudSwitch @bind-Checked="enterTextDirectly" Class="mud-width-full" Color="Color.Primary">Enter Text Directly</MudSwitch>
</MudItem> </MudItem>
<MudItem xs="12" md="4"> <MudItem xs="12" md="4">
<MudSelect @bind-Value="@response.TitlePlateId" Label="Title Plate"> <MudSelect @bind-Value="@response.TitlePlateId" Label="Title Plate">

View File

@ -1,7 +1,4 @@
using MudBlazor.Utilities; namespace TaikoWebUI.Pages;
using static MudBlazor.Colors;
namespace TaikoWebUI.Pages;
public partial class Profile public partial class Profile
{ {
@ -74,11 +71,10 @@ public partial class Profile
await Client.PostAsJsonAsync($"api/UserSettings/{Baid}", response); await Client.PostAsJsonAsync($"api/UserSettings/{Baid}", response);
isSavingOptions = false; isSavingOptions = false;
} }
#pragma warning disable CS1998
private async Task<IEnumerable<string>> SearchForTitle(string value) private async Task<IEnumerable<string>> SearchForTitle(string value)
#pragma warning restore CS1998
{ {
await Task.Delay(1);
var titles = GameDataService.GetTitles(); var titles = GameDataService.GetTitles();
return string.IsNullOrWhiteSpace(value) ? titles : titles.Where(x => x.Contains(value, StringComparison.OrdinalIgnoreCase)); return string.IsNullOrWhiteSpace(value) ? titles : titles.Where(x => x.Contains(value, StringComparison.OrdinalIgnoreCase));

View File

@ -1,5 +1,4 @@
using System.Collections.Immutable; using System.Collections.Immutable;
using MudBlazor.Utilities;
using Swan.Mapping; using Swan.Mapping;
using TaikoWebUI.Shared.Models; using TaikoWebUI.Shared.Models;
@ -7,20 +6,20 @@ namespace TaikoWebUI.Services;
public class GameDataService : IGameDataService public class GameDataService : IGameDataService
{ {
private readonly string[] bodyTitles = new string[Constants.COSTUME_BODY_MAX];
private readonly HttpClient client; private readonly HttpClient client;
private readonly string[] faceTitles = new string[Constants.COSTUME_FACE_MAX];
private readonly Dictionary<uint, MusicDetail> musicMap = new();
private ImmutableDictionary<uint, DanData> danMap = ImmutableDictionary<uint, DanData>.Empty;
private ImmutableHashSet<string> titles = ImmutableHashSet<string>.Empty;
private readonly string[] headTitles = new string[Constants.COSTUME_HEAD_MAX]; private readonly string[] headTitles = new string[Constants.COSTUME_HEAD_MAX];
private readonly string[] faceTitles = new string[Constants.COSTUME_FACE_MAX];
private readonly string[] bodyTitles = new string[Constants.COSTUME_BODY_MAX];
private readonly string[] kigurumiMTitles = new string[Constants.COSTUME_KIGURUMI_MAX]; private readonly string[] kigurumiMTitles = new string[Constants.COSTUME_KIGURUMI_MAX];
private readonly Dictionary<uint, MusicDetail> musicMap = new();
private readonly string[] puchiTitles = new string[Constants.COSTUME_PUCHI_MAX]; private readonly string[] puchiTitles = new string[Constants.COSTUME_PUCHI_MAX];
private ImmutableDictionary<uint, DanData> danMap = ImmutableDictionary<uint, DanData>.Empty;
private ImmutableHashSet<string> titles = ImmutableHashSet<string>.Empty;
public GameDataService(HttpClient client) public GameDataService(HttpClient client)
{ {
this.client = client; this.client = client;
@ -39,11 +38,11 @@ public class GameDataService : IGameDataService
danData.ThrowIfNull(); danData.ThrowIfNull();
danMap = danData.ToImmutableDictionary(data => data.DanId); danMap = danData.ToImmutableDictionary(data => data.DanId);
// To prevent duplicate entries in wordlist // To prevent duplicate entries in wordlist
var dict = wordList.WordListEntries.GroupBy(entry => entry.Key) var dict = wordList.WordListEntries.GroupBy(entry => entry.Key)
.ToImmutableDictionary(group => group.Key, group => group.First()); .ToImmutableDictionary(group => group.Key, group => group.First());
await Task.Run(()=>InitializeMusicMap(musicInfo, dict, musicOrder)); await Task.Run(() => InitializeMusicMap(musicInfo, dict, musicOrder));
await Task.Run(() => InitializeHeadTitles(dict)); await Task.Run(() => InitializeHeadTitles(dict));
await Task.Run(() => InitializeFaceTitles(dict)); await Task.Run(() => InitializeFaceTitles(dict));
@ -53,6 +52,76 @@ public class GameDataService : IGameDataService
await Task.Run(() => InitializeTitles(dict)); await Task.Run(() => InitializeTitles(dict));
} }
public string GetMusicNameBySongId(uint songId)
{
return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.SongName : string.Empty;
}
public string GetMusicArtistBySongId(uint songId)
{
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;
}
public DanData GetDanDataById(uint danId)
{
return danMap.GetValueOrDefault(danId, new DanData());
}
public int GetMusicStarLevel(uint songId, Difficulty difficulty)
{
var success = musicMap.TryGetValue(songId, out var musicDetail);
return difficulty switch
{
Difficulty.None => throw new ArgumentException("Difficulty cannot be none"),
Difficulty.Easy => success ? musicDetail!.StarEasy : 0,
Difficulty.Normal => success ? musicDetail!.StarNormal : 0,
Difficulty.Hard => success ? musicDetail!.StarHard : 0,
Difficulty.Oni => success ? musicDetail!.StarOni : 0,
Difficulty.UraOni => success ? musicDetail!.StarUra : 0,
_ => throw new ArgumentOutOfRangeException(nameof(difficulty), difficulty, null)
};
}
public string GetHeadTitle(uint index)
{
return index < headTitles.Length ? headTitles[index] : string.Empty;
}
public string GetKigurumiTitle(uint index)
{
return index < kigurumiMTitles.Length ? kigurumiMTitles[index] : string.Empty;
}
public string GetBodyTitle(uint index)
{
return index < bodyTitles.Length ? bodyTitles[index] : string.Empty;
}
public string GetFaceTitle(uint index)
{
return index < faceTitles.Length ? faceTitles[index] : string.Empty;
}
public string GetPuchiTitle(uint index)
{
return index < puchiTitles.Length ? puchiTitles[index] : string.Empty;
}
public IEnumerable<string> GetTitles()
{
return titles.ToArray();
}
private void InitializeTitles(ImmutableDictionary<string, WordListEntry> dict) private void InitializeTitles(ImmutableDictionary<string, WordListEntry> dict)
{ {
var set = ImmutableHashSet.CreateBuilder<string>(); var set = ImmutableHashSet.CreateBuilder<string>();
@ -123,7 +192,8 @@ public class GameDataService : IGameDataService
} }
} }
private void InitializeMusicMap(MusicInfo musicInfo, ImmutableDictionary<string, WordListEntry> dict, MusicOrder musicOrder) private void InitializeMusicMap(MusicInfo musicInfo, ImmutableDictionary<string, WordListEntry> dict,
MusicOrder musicOrder)
{ {
foreach (var music in musicInfo.Items) foreach (var music in musicInfo.Items)
{ {
@ -151,72 +221,4 @@ public class GameDataService : IGameDataService
} }
} }
} }
public string GetMusicNameBySongId(uint songId)
{
return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.SongName : string.Empty;
}
public string GetMusicArtistBySongId(uint songId)
{
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;
}
public DanData GetDanDataById(uint danId)
{
return danMap.GetValueOrDefault(danId, new DanData());
}
public int GetMusicStarLevel(uint songId, Difficulty difficulty)
{
var success = musicMap.TryGetValue(songId, out var musicDetail);
return difficulty switch
{
Difficulty.None => throw new ArgumentException("Difficulty cannot be none"),
Difficulty.Easy => success ? musicDetail!.StarEasy : 0,
Difficulty.Normal => success ? musicDetail!.StarNormal : 0,
Difficulty.Hard => success ? musicDetail!.StarHard : 0,
Difficulty.Oni => success ? musicDetail!.StarOni : 0,
Difficulty.UraOni => success ? musicDetail!.StarUra : 0,
_ => throw new ArgumentOutOfRangeException(nameof(difficulty), difficulty, null)
};
}
public string GetHeadTitle(uint index)
{
return index < headTitles.Length ? headTitles[index] : string.Empty;
}
public string GetKigurumiTitle(uint index)
{
return index < kigurumiMTitles.Length ? kigurumiMTitles[index] : string.Empty;
}
public string GetBodyTitle(uint index)
{
return index < bodyTitles.Length ? bodyTitles[index] : string.Empty;
}
public string GetFaceTitle(uint index)
{
return index < faceTitles.Length ? faceTitles[index] : string.Empty;
}
public string GetPuchiTitle(uint index)
{
return index < puchiTitles.Length ? puchiTitles[index] : string.Empty;
}
public IEnumerable<string> GetTitles()
{
return titles.ToArray();
}
} }

View File

@ -1,6 +1,4 @@
using System.Collections.Immutable; namespace TaikoWebUI.Services;
namespace TaikoWebUI.Services;
public interface IGameDataService public interface IGameDataService
{ {

View File

@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Autocomplete.Clients" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" />
<PackageReference Include="MudBlazor" Version="6.0.15" /> <PackageReference Include="MudBlazor" Version="6.0.15" />