1
0
mirror of synced 2024-11-23 22:41:01 +01:00

Implemented getting flagArraySizes(other than don Color) dynamically on WebUI

This commit is contained in:
S-Sebb 2023-10-15 15:27:07 +01:00
parent d179ff4a4e
commit c963809be6
11 changed files with 157 additions and 44 deletions

View File

@ -104,7 +104,7 @@
<MudItem xs="12">
<MudStack Spacing="4" Class="mb-8">
<MudSelect @bind-Value="@response.Head" Label="Head">
@for (var i = 0; i < Constants.COSTUME_HEAD_MAX; i++)
@for (var i = 0; i < costumeFlagArraySizes[1]; i++)
{
var index = (uint)i;
var costumeTitle = GameDataService.GetHeadTitle(index);
@ -113,7 +113,7 @@
</MudSelect>
<MudSelect @bind-Value="@response.Body" Label="Body">
@for (var i = 0; i < Constants.COSTUME_BODY_MAX; i++)
@for (var i = 0; i < costumeFlagArraySizes[2]; i++)
{
var index = (uint)i;
var costumeTitle = GameDataService.GetBodyTitle(index);
@ -122,7 +122,7 @@
</MudSelect>
<MudSelect @bind-Value="@response.Face" Label="Face">
@for (var i = 0; i < Constants.COSTUME_FACE_MAX; i++)
@for (var i = 0; i < costumeFlagArraySizes[3]; i++)
{
var index = (uint)i;
var costumeTitle = GameDataService.GetFaceTitle(index);
@ -131,7 +131,7 @@
</MudSelect>
<MudSelect @bind-Value="@response.Kigurumi" Label="Kigurumi">
@for (var i = 0; i < Constants.COSTUME_KIGURUMI_MAX; i++)
@for (var i = 0; i < costumeFlagArraySizes[0]; i++)
{
var index = (uint)i;
var costumeTitle = GameDataService.GetKigurumiTitle(index);
@ -140,7 +140,7 @@
</MudSelect>
<MudSelect @bind-Value="@response.Puchi" Label="Puchi">
@for (var i = 0; i < Constants.COSTUME_PUCHI_MAX; i++)
@for (var i = 0; i < costumeFlagArraySizes[4]; i++)
{
var index = (uint)i;
var costumeTitle = GameDataService.GetPuchiTitle(index);

View File

@ -78,6 +78,8 @@ public partial class Profile
new BreadcrumbItem("Cards", href: "/Cards"),
};
private List<int> costumeFlagArraySizes = new();
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
@ -86,6 +88,8 @@ public partial class Profile
breadcrumbs.Add(new BreadcrumbItem($"Card: {Baid}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem("Profile", href: $"/Cards/{Baid}/Profile", disabled: false));
costumeFlagArraySizes = GameDataService.GetCostumeFlagArraySizes();
}
private async Task SaveOptions()

View File

@ -1,9 +1,4 @@
using System.Collections.Immutable;
using System.IO.Compression;
using System.Net;
using System.Security.Cryptography;
using System.Text.Json;
using ICSharpCode.SharpZipLib.GZip;
using Swan.Mapping;
using TaikoWebUI.Shared.Models;
@ -11,15 +6,19 @@ namespace TaikoWebUI.Services;
public class GameDataService : IGameDataService
{
private readonly string[] bodyTitles = new string[Constants.COSTUME_BODY_MAX];
private string[] bodyTitles;
private readonly HttpClient client;
private readonly string[] faceTitles = new string[Constants.COSTUME_FACE_MAX];
private string[] faceTitles;
private readonly string[] headTitles = new string[Constants.COSTUME_HEAD_MAX];
private readonly string[] kigurumiMTitles = new string[Constants.COSTUME_KIGURUMI_MAX];
private string[] headTitles;
private string[] kigurumiTitles;
private readonly Dictionary<uint, MusicDetail> musicMap = new();
private readonly string[] puchiTitles = new string[Constants.COSTUME_PUCHI_MAX];
private string[] puchiTitles;
private List<int> costumeFlagArraySizes = new();
private int titleFlagArraySize;
private ImmutableDictionary<uint, DanData> danMap = ImmutableDictionary<uint, DanData>.Empty;
@ -34,8 +33,10 @@ public class GameDataService : IGameDataService
{
dataBaseUrl = dataBaseUrl.TrimEnd('/');
var musicInfo = await GetData<MusicInfo>(dataBaseUrl, Constants.MUSIC_INFO_BASE_NAME);
var wordList = await GetData<WordList>(dataBaseUrl, Constants.WORD_LIST_BASE_NAME);
var wordList = await GetData<WordList>(dataBaseUrl, Constants.WORDLIST_BASE_NAME);
var musicOrder = await GetData<MusicOrder>(dataBaseUrl, Constants.MUSIC_ORDER_BASE_NAME);
var donCosRewardData = await GetData<DonCosRewards>(dataBaseUrl, Constants.DON_COS_REWARD_BASE_NAME);
var shougouData = await GetData<Shougous>(dataBaseUrl, Constants.SHOUGOU_BASE_NAME);
var danData = await client.GetFromJsonAsync<List<DanData>>($"{dataBaseUrl}/data/dan_data.json");
danData.ThrowIfNull();
@ -46,6 +47,9 @@ public class GameDataService : IGameDataService
.ToImmutableDictionary(group => group.Key, group => group.First());
await Task.Run(() => InitializeMusicMap(musicInfo, dict, musicOrder));
InitializeCostumeFlagArraySizes(donCosRewardData);
InitializeTitleFlagArraySize(shougouData);
await Task.Run(() => InitializeHeadTitles(dict));
await Task.Run(() => InitializeFaceTitles(dict));
await Task.Run(() => InitializeBodyTitles(dict));
@ -108,7 +112,7 @@ public class GameDataService : IGameDataService
public string GetKigurumiTitle(uint index)
{
return index < kigurumiMTitles.Length ? kigurumiMTitles[index] : string.Empty;
return index < kigurumiTitles.Length ? kigurumiTitles[index] : string.Empty;
}
public string GetBodyTitle(uint index)
@ -131,10 +135,21 @@ public class GameDataService : IGameDataService
return titles;
}
public List<int> GetCostumeFlagArraySizes()
{
return costumeFlagArraySizes;
}
private void InitializeTitleFlagArraySize(Shougous? shougouData)
{
shougouData.ThrowIfNull("Shouldn't happen!");
titleFlagArraySize = (int)shougouData.ShougouEntries.Max(entry => entry.uniqueId) + 1;
}
private void InitializeTitles(ImmutableDictionary<string, WordListEntry> dict)
{
var set = ImmutableHashSet.CreateBuilder<Title>();
for (var i = 1; i < Constants.PLAYER_TITLE_MAX; i++)
for (var i = 1; i < titleFlagArraySize; i++)
{
var key = $"syougou_{i}";
@ -149,31 +164,66 @@ public class GameDataService : IGameDataService
titles = set.ToImmutable();
}
private void InitializePuchiTitles(ImmutableDictionary<string, WordListEntry> dict)
private void InitializeCostumeFlagArraySizes(DonCosRewards? donCosRewardData)
{
for (var i = 0; i < Constants.COSTUME_PUCHI_MAX; i++)
{
var key = $"costume_puchi_{i}";
donCosRewardData.ThrowIfNull("Shouldn't happen!");
var kigurumiUniqueIdList = donCosRewardData.DonCosRewardEntries
.Where(entry => entry.cosType == "kigurumi")
.Select(entry => entry.uniqueId);
var headUniqueIdList = donCosRewardData.DonCosRewardEntries
.Where(entry => entry.cosType == "head")
.Select(entry => entry.uniqueId);
var bodyUniqueIdList = donCosRewardData.DonCosRewardEntries
.Where(entry => entry.cosType == "body")
.Select(entry => entry.uniqueId);
var faceUniqueIdList = donCosRewardData.DonCosRewardEntries
.Where(entry => entry.cosType == "face")
.Select(entry => entry.uniqueId);
var puchiUniqueIdList = donCosRewardData.DonCosRewardEntries
.Where(entry => entry.cosType == "puchi")
.Select(entry => entry.uniqueId);
var costumeWordlistItem = dict.GetValueOrDefault(key, new WordListEntry());
puchiTitles[i] = costumeWordlistItem.JapaneseText;
}
costumeFlagArraySizes = new List<int>
{
(int)kigurumiUniqueIdList.Max() + 1,
(int)headUniqueIdList.Max() + 1,
(int)bodyUniqueIdList.Max() + 1,
(int)faceUniqueIdList.Max() + 1,
(int)puchiUniqueIdList.Max() + 1
};
}
private void InitializeKigurumiTitles(ImmutableDictionary<string, WordListEntry> dict)
{
for (var i = 0; i < Constants.COSTUME_KIGURUMI_MAX; i++)
var costumeKigurumiMax = costumeFlagArraySizes[0];
kigurumiTitles = new string[costumeKigurumiMax];
for (var i = 0; i < costumeKigurumiMax; i++)
{
var key = $"costume_kigurumi_{i}";
var costumeWordlistItem = dict.GetValueOrDefault(key, new WordListEntry());
kigurumiMTitles[i] = costumeWordlistItem.JapaneseText;
kigurumiTitles[i] = costumeWordlistItem.JapaneseText;
}
}
private void InitializeHeadTitles(ImmutableDictionary<string, WordListEntry> dict)
{
var costumeHeadMax = costumeFlagArraySizes[1];
headTitles = new string[costumeHeadMax];
for (var i = 0; i < costumeHeadMax; i++)
{
var key = $"costume_head_{i}";
var costumeWordlistItem = dict.GetValueOrDefault(key, new WordListEntry());
headTitles[i] = costumeWordlistItem.JapaneseText;
}
}
private void InitializeBodyTitles(ImmutableDictionary<string, WordListEntry> dict)
{
for (var i = 0; i < Constants.COSTUME_BODY_MAX; i++)
var costumeBodyMax = costumeFlagArraySizes[2];
bodyTitles = new string[costumeBodyMax];
for (var i = 0; i < costumeBodyMax; i++)
{
var key = $"costume_body_{i}";
@ -184,7 +234,9 @@ public class GameDataService : IGameDataService
private void InitializeFaceTitles(ImmutableDictionary<string, WordListEntry> dict)
{
for (var i = 0; i < Constants.COSTUME_FACE_MAX; i++)
var costumeFaceMax = costumeFlagArraySizes[3];
faceTitles = new string[costumeFaceMax];
for (var i = 0; i < costumeFaceMax; i++)
{
var key = $"costume_face_{i}";
@ -193,14 +245,16 @@ public class GameDataService : IGameDataService
}
}
private void InitializeHeadTitles(ImmutableDictionary<string, WordListEntry> dict)
private void InitializePuchiTitles(ImmutableDictionary<string, WordListEntry> dict)
{
for (var i = 0; i < Constants.COSTUME_HEAD_MAX; i++)
var costumePuchiMax = costumeFlagArraySizes[4];
puchiTitles = new string[costumePuchiMax];
for (var i = 0; i < costumePuchiMax; i++)
{
var key = $"costume_head_{i}";
var key = $"costume_puchi_{i}";
var costumeWordlistItem = dict.GetValueOrDefault(key, new WordListEntry());
headTitles[i] = costumeWordlistItem.JapaneseText;
puchiTitles[i] = costumeWordlistItem.JapaneseText;
}
}

View File

@ -25,5 +25,7 @@ public interface IGameDataService
public string GetFaceTitle(uint index);
public string GetPuchiTitle(uint index);
public List<int> GetCostumeFlagArraySizes();
public ImmutableHashSet<Title> GetTitles();
}

View File

@ -2,15 +2,11 @@
public static class Constants
{
public const int COSTUME_HEAD_MAX = 140;
public const int COSTUME_FACE_MAX = 58;
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 = 750;
public const string MUSIC_INFO_BASE_NAME = "musicinfo";
public const string WORD_LIST_BASE_NAME = "wordlist";
public const string MUSIC_ORDER_BASE_NAME = "music_order";
public const string WORDLIST_BASE_NAME = "wordlist";
public const string MUSIC_ORDER_BASE_NAME = "music_order";
public const string DON_COS_REWARD_BASE_NAME = "don_cos_reward";
public const string SHOUGOU_BASE_NAME = "shougou";
}

View File

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace TaikoWebUI.Shared.Models;
public class DonCosRewardEntry
{
[JsonPropertyName("cosType")]
public string cosType { get; set; } = null!;
[JsonPropertyName("uniqueId")]
public uint uniqueId { get; set; }
}

View File

@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace TaikoWebUI.Shared.Models;
public class DonCosRewards
{
[JsonPropertyName("items")]
public List<DonCosRewardEntry> DonCosRewardEntries { get; set; } = new();
}

View File

@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace TaikoWebUI.Shared.Models;
public class NeiroEntry
{
[JsonPropertyName("uniqueId")]
public uint uniqueId { get; set; }
}

View File

@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace TaikoWebUI.Shared.Models;
public class Neiros
{
[JsonPropertyName("items")]
public List<NeiroEntry> NeiroEntries { get; set; } = new();
}

View File

@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace TaikoWebUI.Shared.Models;
public class ShougouEntry
{
[JsonPropertyName("uniqueId")]
public uint uniqueId { get; set; }
}

View File

@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace TaikoWebUI.Shared.Models;
public class Shougous
{
[JsonPropertyName("items")]
public List<ShougouEntry> ShougouEntries { get; set; } = new();
}