Make song titles and artists use the active language
* The song titles and artists for the High Score and Dani Dojo screens will show based on the current language selected in the Switcher
This commit is contained in:
parent
dd6859f5a1
commit
51730ce60f
@ -1,6 +1,7 @@
|
||||
@inject IGameDataService GameDataService
|
||||
@inject HttpClient Client
|
||||
@inject LoginService LoginService
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
@page "/Users/{baid:int}/DaniDojo"
|
||||
|
||||
@ -146,8 +147,8 @@ else
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="9" md="4" Style="display:flex;flex-direction:column;" Class="pl-4">
|
||||
<MudText Typo="Typo.body1" Style="font-weight: bold;">@GameDataService.GetMusicNameBySongId(danDataOdaiSong.SongNo)</MudText>
|
||||
<MudText Typo="Typo.caption">@GameDataService.GetMusicArtistBySongId(danDataOdaiSong.SongNo)</MudText>
|
||||
<MudText Typo="Typo.body1" Style="font-weight: bold;">@GameDataService.GetMusicNameBySongId(danDataOdaiSong.SongNo, @CurrentLanguage)</MudText>
|
||||
<MudText Typo="Typo.caption">@GameDataService.GetMusicArtistBySongId(danDataOdaiSong.SongNo, @CurrentLanguage)</MudText>
|
||||
</MudItem>
|
||||
|
||||
|
||||
|
@ -1,10 +1,14 @@
|
||||
namespace TaikoWebUI.Pages;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace TaikoWebUI.Pages;
|
||||
|
||||
public partial class DaniDojo
|
||||
{
|
||||
[Parameter]
|
||||
public int Baid { get; set; }
|
||||
|
||||
public string CurrentLanguage { get; set; } = "ja";
|
||||
|
||||
private DanBestDataResponse? response;
|
||||
|
||||
private static Dictionary<uint, DanBestData> bestDataMap = new();
|
||||
@ -17,12 +21,15 @@ public partial class DaniDojo
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
response = await Client.GetFromJsonAsync<DanBestDataResponse>($"api/DanBestData/{Baid}");
|
||||
response.ThrowIfNull();
|
||||
response.DanBestDataList.ForEach(data => data.DanBestStageDataList
|
||||
.Sort((stageData, otherStageData) => stageData.SongNumber.CompareTo(otherStageData.SongNumber)));
|
||||
bestDataMap = response.DanBestDataList.ToDictionary(data => data.DanId);
|
||||
|
||||
CurrentLanguage = await JSRuntime.InvokeAsync<string>("blazorCulture.get");
|
||||
|
||||
breadcrumbs.Add(new BreadcrumbItem($"User: {Baid}", href: null, disabled: true));
|
||||
breadcrumbs.Add(new BreadcrumbItem("Dani Dojo", href: $"/Users/{Baid}/DaniDojo", disabled: false));
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
@inject IGameDataService GameDataService
|
||||
@inject HttpClient Client
|
||||
@inject LoginService LoginService
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
@page "/Users/{baid:int}/HighScores"
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using static MudBlazor.Colors;
|
||||
using System;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace TaikoWebUI.Pages;
|
||||
|
||||
@ -24,13 +25,15 @@ public partial class HighScores
|
||||
await base.OnInitializedAsync();
|
||||
response = await Client.GetFromJsonAsync<SongBestResponse>($"api/PlayData/{Baid}");
|
||||
response.ThrowIfNull();
|
||||
|
||||
|
||||
var language = await JSRuntime.InvokeAsync<string>("blazorCulture.get");
|
||||
|
||||
response.SongBestData.ForEach(data =>
|
||||
{
|
||||
var songId = data.SongId;
|
||||
data.Genre = GameDataService.GetMusicGenreBySongId(songId);
|
||||
data.MusicName = GameDataService.GetMusicNameBySongId(songId);
|
||||
data.MusicArtist = GameDataService.GetMusicArtistBySongId(songId);
|
||||
data.MusicName = GameDataService.GetMusicNameBySongId(songId, string.IsNullOrEmpty(language) ? "ja" : language);
|
||||
data.MusicArtist = GameDataService.GetMusicArtistBySongId(songId, string.IsNullOrEmpty(language) ? "ja" : language);
|
||||
});
|
||||
|
||||
songBestDataMap = response.SongBestData.GroupBy(data => data.Difficulty)
|
||||
|
@ -65,14 +65,30 @@ public class GameDataService : IGameDataService
|
||||
return data;
|
||||
}
|
||||
|
||||
public string GetMusicNameBySongId(uint songId)
|
||||
public string GetMusicNameBySongId(uint songId, string? language)
|
||||
{
|
||||
return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.SongName : string.Empty;
|
||||
return musicMap.TryGetValue(songId, out var musicDetail) ? language switch
|
||||
{
|
||||
"ja" => musicDetail.SongName,
|
||||
"en-US" => musicDetail.SongNameEN,
|
||||
"zh-Hans" => musicDetail.SongNameCN,
|
||||
"zh-Hant" => musicDetail.SongNameCN,
|
||||
"ko" => musicDetail.SongNameKO,
|
||||
_ => musicDetail.SongName
|
||||
} : string.Empty;
|
||||
}
|
||||
|
||||
public string GetMusicArtistBySongId(uint songId)
|
||||
public string GetMusicArtistBySongId(uint songId, string? language)
|
||||
{
|
||||
return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.ArtistName : string.Empty;
|
||||
return musicMap.TryGetValue(songId, out var musicDetail) ? language switch
|
||||
{
|
||||
"jp" => musicDetail.ArtistName,
|
||||
"en-US" => musicDetail.ArtistNameEN,
|
||||
"zh-Hans" => musicDetail.ArtistNameCN,
|
||||
"zh-Hant" => musicDetail.ArtistNameCN,
|
||||
"ko" => musicDetail.ArtistNameKO,
|
||||
_ => musicDetail.ArtistName
|
||||
} : string.Empty;
|
||||
}
|
||||
|
||||
public SongGenre GetMusicGenreBySongId(uint songId)
|
||||
@ -282,6 +298,16 @@ public class GameDataService : IGameDataService
|
||||
musicDetail.SongName = musicName.JapaneseText;
|
||||
musicDetail.ArtistName = musicArtist.JapaneseText;
|
||||
|
||||
// Add localized names
|
||||
musicDetail.SongNameEN = musicName.EnglishUsText;
|
||||
musicDetail.ArtistNameEN = musicArtist.EnglishUsText;
|
||||
|
||||
musicDetail.SongNameCN = musicName.ChineseTText;
|
||||
musicDetail.ArtistNameCN = musicArtist.ChineseTText;
|
||||
|
||||
musicDetail.SongNameKO = musicName.KoreanText;
|
||||
musicDetail.ArtistNameKO = musicArtist.KoreanText;
|
||||
|
||||
musicMap.TryAdd(musicSongId, musicDetail);
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,9 @@ public interface IGameDataService
|
||||
{
|
||||
public Task InitializeAsync(string dataBaseUrl);
|
||||
|
||||
public string GetMusicNameBySongId(uint songId);
|
||||
public string GetMusicNameBySongId(uint songId, string? language = null);
|
||||
|
||||
public string GetMusicArtistBySongId(uint songId);
|
||||
public string GetMusicArtistBySongId(uint songId, string? language = null);
|
||||
|
||||
public SongGenre GetMusicGenreBySongId(uint songId);
|
||||
|
||||
|
@ -7,8 +7,14 @@ public class MusicDetail
|
||||
public int Index { get; set; }
|
||||
|
||||
public string SongName { get; set; } = string.Empty;
|
||||
public string SongNameEN { get; set; } = string.Empty;
|
||||
public string SongNameCN { get; set; } = string.Empty;
|
||||
public string SongNameKO { get; set; } = string.Empty;
|
||||
|
||||
public string ArtistName { get; set; } = string.Empty;
|
||||
public string ArtistNameEN { get; set; } = string.Empty;
|
||||
public string ArtistNameCN { get; set; } = string.Empty;
|
||||
public string ArtistNameKO { get; set; } = string.Empty;
|
||||
|
||||
public SongGenre Genre { get; set; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user