1
0
mirror of synced 2024-11-24 06:50:15 +01:00
TaikoLocalServer/TaikoWebUI/Pages/DaniDojo.razor.cs

227 lines
9.4 KiB
C#
Raw Normal View History

2022-09-12 23:15:27 +02:00
using SharedProject.Enums;
using System.Net.NetworkInformation;
2022-09-12 17:49:28 +02:00
namespace TaikoWebUI.Pages;
2022-09-11 18:33:58 +02:00
public partial class DaniDojo
{
[Parameter]
public int Baid { get; set; }
private DanBestDataResponse? response;
private Dictionary<uint, DanBestData> bestDataMap = new();
private readonly List<BreadcrumbItem> breadcrumbs = new()
{
new BreadcrumbItem("Cards", href: "/Cards"),
};
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
response = await Client.GetFromJsonAsync<DanBestDataResponse>($"api/DanBestData/{Baid}");
response.ThrowIfNull();
2022-09-12 16:17:15 +02:00
response.DanBestDataList.ForEach(data => data.DanBestStageDataList
.Sort((stageData, otherStageData) => stageData.SongNumber.CompareTo(otherStageData.SongNumber)));
2022-09-11 18:33:58 +02:00
bestDataMap = response.DanBestDataList.ToDictionary(data => data.DanId);
breadcrumbs.Add(new BreadcrumbItem($"Card: {Baid}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem("Dani Dojo", href: $"/Cards/{Baid}/DaniDojo", disabled: false));
}
2022-09-12 23:15:27 +02:00
private static string GetDanClearStateString(DanClearState danClearState)
{
return danClearState switch
{
DanClearState.NotClear => "Not Cleared",
DanClearState.RedNormalClear => "Red Clear",
DanClearState.RedFullComboClear => "Red Full Combo",
DanClearState.RedPerfectClear => "Red Donderful Combo",
DanClearState.GoldNormalClear => "Gold Clear",
DanClearState.GoldFullComboClear => "Gold Full Combo",
DanClearState.GoldPerfectClear => "Gold Donderful Combo",
_ => ""
};
}
2022-09-12 17:49:28 +02:00
private static string GetDanRequirementString(DanConditionType danConditionType)
{
return danConditionType switch
{
DanConditionType.TotalHitCount => "Total Hits",
2022-09-12 19:33:13 +02:00
DanConditionType.GoodCount => "Good Hits",
DanConditionType.OkCount => "OK Hits",
DanConditionType.BadCount => "Bad Hits",
2022-09-12 17:49:28 +02:00
DanConditionType.SoulGauge => "Soul Gauge",
DanConditionType.DrumrollCount => "Drumroll Hits",
DanConditionType.Score => "Score",
DanConditionType.ComboCount => "MAX Combo",
_ => ""
};
}
2022-09-12 16:17:15 +02:00
private static string GetDanRequirementTitle(DanData.OdaiBorder data)
2022-09-11 18:33:58 +02:00
{
var danConditionType = (DanConditionType)data.OdaiType;
2022-09-12 17:49:28 +02:00
string danConditionTitle = GetDanRequirementString(danConditionType);
2022-09-11 18:33:58 +02:00
return (DanBorderType)data.BorderType switch
{
2022-09-12 17:49:28 +02:00
DanBorderType.All => $"{danConditionTitle} (All stages)",
DanBorderType.PerSong => $"{danConditionTitle} (Per stage)",
2022-09-12 16:17:15 +02:00
_ => throw new ArgumentOutOfRangeException(nameof(data))
};
}
private static string GetDanRequirementAll(DanData.OdaiBorder odaiBorder)
{
((DanBorderType)odaiBorder.BorderType).Throw().IfNotEquals(DanBorderType.All);
var type = (DanConditionType)odaiBorder.OdaiType;
var template =
$"Pass when {{0}} {{1}} {odaiBorder.RedBorderTotal}, gold when {{1}} {odaiBorder.GoldBorderTotal}";
return type switch
{
DanConditionType.SoulGauge => throw new ArgumentException("Soul gauge should not be here"),
DanConditionType.GoodCount => string.Format(template, "good count", "exceeds"),
DanConditionType.OkCount => string.Format(template, "ok count", "exceeds"),
DanConditionType.BadCount => string.Format(template, "bad count", "below"),
DanConditionType.ComboCount => string.Format(template, "combo count", "exceeds"),
DanConditionType.DrumrollCount => string.Format(template, "drum roll count", "exceeds"),
DanConditionType.Score => string.Format(template, "score", "exceeds"),
DanConditionType.TotalHitCount => string.Format(template, "hit count", "exceeds"),
_ => throw new ArgumentOutOfRangeException(nameof(odaiBorder))
};
}
private static string GetDanRequirementPerSong(DanData.OdaiBorder odaiBorder, int songNumber)
{
songNumber.Throw().IfOutOfRange(0, 2);
((DanBorderType)odaiBorder.BorderType).Throw().IfNotEquals(DanBorderType.PerSong);
var type = (DanConditionType)odaiBorder.OdaiType;
var template =
$"Pass when song{songNumber}'s {{0}} {{1}} {odaiBorder.RedBorderTotal}, gold when {{1}} {odaiBorder.GoldBorderTotal}";
return type switch
{
DanConditionType.SoulGauge => throw new ArgumentException("Soul gauge should not be here"),
DanConditionType.GoodCount => string.Format(template, "good count", "exceeds"),
DanConditionType.OkCount => string.Format(template, "ok count", "exceeds"),
DanConditionType.BadCount => string.Format(template, "bad count", "below"),
DanConditionType.ComboCount => string.Format(template, "combo count", "exceeds"),
DanConditionType.DrumrollCount => string.Format(template, "drum roll count", "exceeds"),
DanConditionType.Score => string.Format(template, "score", "exceeds"),
DanConditionType.TotalHitCount => string.Format(template, "hit count", "exceeds"),
_ => throw new ArgumentOutOfRangeException(nameof(odaiBorder))
};
}
private static string GetAllBestFromData(DanConditionType type, DanBestData data)
{
return type switch
{
DanConditionType.SoulGauge => throw new ArgumentException("Soul gauge should not be here"),
DanConditionType.GoodCount => data.DanBestStageDataList.Sum(stageData => stageData.GoodCount).ToString(),
DanConditionType.OkCount => data.DanBestStageDataList.Sum(stageData => stageData.OkCount).ToString(),
DanConditionType.BadCount => data.DanBestStageDataList.Sum(stageData => stageData.BadCount).ToString(),
DanConditionType.ComboCount => data.ComboCountTotal.ToString(),
DanConditionType.DrumrollCount => data.DanBestStageDataList.Sum(stageData => stageData.DrumrollCount)
.ToString(),
DanConditionType.Score => data.DanBestStageDataList.Sum(stageData => stageData.PlayScore).ToString(),
DanConditionType.TotalHitCount => data.DanBestStageDataList.Sum(stageData => stageData.TotalHitCount)
.ToString(),
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
}
private static string GetSongBestFromData(DanConditionType type, DanBestData data, int songNumber)
{
songNumber.Throw().IfOutOfRange(0, 2);
return type switch
{
DanConditionType.SoulGauge => throw new ArgumentException("Soul gauge should not be here"),
DanConditionType.GoodCount => data.DanBestStageDataList[songNumber].GoodCount.ToString(),
DanConditionType.OkCount => data.DanBestStageDataList[songNumber].OkCount.ToString(),
DanConditionType.BadCount => data.DanBestStageDataList[songNumber].BadCount.ToString(),
DanConditionType.ComboCount => data.DanBestStageDataList[songNumber].ComboCount.ToString(),
DanConditionType.DrumrollCount => data.DanBestStageDataList[songNumber].DrumrollCount.ToString(),
DanConditionType.Score => data.DanBestStageDataList[songNumber].PlayScore.ToString(),
DanConditionType.TotalHitCount => data.DanBestStageDataList[songNumber].TotalHitCount.ToString(),
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
2022-09-11 18:33:58 +02:00
};
}
2022-09-11 23:32:24 +02:00
private static string GetDanTitle(string title)
{
return title switch
{
"5kyuu" => "Fifth Kyuu",
"4kyuu" => "Fourth Kyuu",
"3kyuu" => "Third Kyuu",
"2kyuu" => "Second Kyuu",
"1kyuu" => "First Kyuu",
"1dan" => "First Dan",
"2dan" => "Second Dan",
"3dan" => "Third Dan",
"4dan" => "Fourth Dan",
"5dan" => "Fifth Dan",
"6dan" => "Sixth Dan",
"7dan" => "Seventh Dan",
"8dan" => "Eighth Dan",
"9dan" => "Ninth Dan",
"10dan" => "Tenth Dan",
"11dan" => "Kuroto",
"12dan" => "Meijin",
"13dan" => "Chojin",
"14dan" => "Tatsujin",
"15dan" => "Gaiden",
_ => ""
};
}
2022-09-12 04:15:03 +02:00
private string GetDanResultIcon(uint danId)
{
2022-09-12 16:17:15 +02:00
var icon = "";
2022-09-12 04:15:03 +02:00
2022-09-12 16:17:15 +02:00
if (!bestDataMap.ContainsKey(danId))
2022-09-12 04:15:03 +02:00
{
2022-09-12 16:17:15 +02:00
return icon;
}
var state = bestDataMap[danId].ClearState;
2022-09-12 04:15:03 +02:00
2022-09-12 16:17:15 +02:00
if (state is not DanClearState.NotClear)
{
icon = $"<image href='/images/dani_{state}.png' width='24' height='24'/>";
2022-09-12 04:15:03 +02:00
}
return icon;
}
2022-09-12 16:17:15 +02:00
2022-09-12 23:15:27 +02:00
private DanClearState GetDanResultState(uint danId)
{
if (bestDataMap.ContainsKey(danId))
{
return bestDataMap[danId].ClearState;
}
else
{
return DanClearState.NotClear;
}
}
2022-09-12 17:49:28 +02:00
private static uint GetSoulGauge(DanData data, bool isGold)
2022-09-12 16:17:15 +02:00
{
var borders = data.OdaiBorderList;
var soulBorder =
borders.FirstOrDefault(border => (DanConditionType)border.BorderType == DanConditionType.SoulGauge,
new DanData.OdaiBorder());
if (isGold)
{
2022-09-12 17:49:28 +02:00
return soulBorder.GoldBorderTotal;
2022-09-12 16:17:15 +02:00
}
2022-09-12 17:49:28 +02:00
return soulBorder.RedBorderTotal;
2022-09-12 16:17:15 +02:00
}
2022-09-11 18:33:58 +02:00
}