41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
using System.Text.Json;
|
|
using CsWeb.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace CsWeb.Pages.Guides;
|
|
|
|
public class ModeModel(Fleet fleet) : PageModel
|
|
{
|
|
private static readonly string[] Known = ["tdm", "gungame", "survival"];
|
|
|
|
public string Mode { get; private set; } = "";
|
|
public Cached<BalancePayload>? Balance { get; private set; }
|
|
public BalancePayload? B => Balance?.Data;
|
|
|
|
public async Task<IActionResult> OnGetAsync(string mode)
|
|
{
|
|
mode = mode.ToLowerInvariant();
|
|
if (!Known.Contains(mode)) return NotFound();
|
|
Mode = mode;
|
|
(_, Balance) = await fleet.BalanceForMode(mode);
|
|
return Page();
|
|
}
|
|
|
|
// The GG ladder rows from the balance payload's GunGame.Ladder ([{Weapon, Tier}]).
|
|
public IEnumerable<(string Weapon, int Tier)> Ladder()
|
|
{
|
|
if (B is null || B.GunGame.ValueKind != JsonValueKind.Object) yield break;
|
|
if (!B.GunGame.TryGetProperty("Ladder", out var l) || l.ValueKind != JsonValueKind.Array) yield break;
|
|
foreach (var e in l.EnumerateArray())
|
|
yield return (Fmt.StrOf(e, "Weapon"), Fmt.IntOf(e, "Tier"));
|
|
}
|
|
|
|
// Survival card catalog rows ([{Key, Name, PerPick, Cap, Flat?, IsTeam?, Detail?}] — tolerant of shape drift).
|
|
public IEnumerable<JsonElement> Cards()
|
|
{
|
|
if (B is null || B.Survival.ValueKind != JsonValueKind.Object) yield break;
|
|
if (!B.Survival.TryGetProperty("Cards", out var c) || c.ValueKind != JsonValueKind.Array) yield break;
|
|
foreach (var e in c.EnumerateArray()) yield return e;
|
|
}
|
|
}
|