initial commit
This commit is contained in:
commit
2d966b8198
28 changed files with 2901 additions and 0 deletions
41
Pages/Guides/Mode.cshtml.cs
Normal file
41
Pages/Guides/Mode.cshtml.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue