Turnierplan (Buy-in-Band, Typ, nur laufende, Startfenster) wie cockpit/src/turnierplan.rs, nur mit Turnier-Tischen in der Wahl; eigene Anmeldungen aus kopf.turnier_anmeldungen mit Abmelden (steuern turnier_abmelden). Echtgeld mit Micro only: Budget "aus". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
3.2 KiB
C#
72 lines
3.2 KiB
C#
using System.Globalization;
|
|
using System.Text.Json.Nodes;
|
|
|
|
namespace Pokerfreak.Cockpit.Kern;
|
|
|
|
/// <summary>
|
|
/// Welche Turniere der Laeufer anmeldet (wie cockpit/src/turnierplan.rs, Turnierplan.swift,
|
|
/// betrieb/turnierplan.py): ein Buy-in-Band, die CoinPoker-Kategorie (der Typ), ein freies
|
|
/// Namens-Teilwort, nur laufende (Late-Reg) und ein Startfenster in Minuten. Im Spielplan steht er
|
|
/// als `turnier`-Objekt - nur, wenn der Owner ueberhaupt etwas eingeschraenkt hat.
|
|
/// </summary>
|
|
public sealed class Turnierplan
|
|
{
|
|
/// <summary>Der Typ-Filter: Anzeige und Kategorie (null = alle).</summary>
|
|
public static readonly (string Name, string? Kategorie)[] Typen =
|
|
{
|
|
("Alle", null), ("Daily", "Daily"), ("Satellite", "Satellite"), ("PGT", "PGT"), ("Freerolls", "Freeroll"), ("VIP", "VIP"),
|
|
};
|
|
|
|
public double? BuyinMin, BuyinMax;
|
|
public string? Name, Kategorie;
|
|
public bool NurLaufend = true;
|
|
public long? FensterMin;
|
|
|
|
private static string? Text(JsonObject o, string k) =>
|
|
o[k] is JsonValue v && v.TryGetValue<string>(out var s) && s.Trim().Length > 0 ? s.Trim() : null;
|
|
|
|
/// <summary>Nachsichtig aus `spielplan.turnier`; fehlt es, die Vorgabe.</summary>
|
|
public static Turnierplan Aus(JsonObject? o)
|
|
{
|
|
var p = new Turnierplan();
|
|
if (o == null) return p;
|
|
p.BuyinMin = o.Zahl("buyin_min");
|
|
p.BuyinMax = o.Zahl("buyin_max");
|
|
p.Name = Text(o, "name");
|
|
p.Kategorie = Text(o, "kategorie");
|
|
p.NurLaufend = o["nur_laufend"] is JsonValue nl && nl.TryGetValue<bool>(out var b) ? b : true;
|
|
p.FensterMin = o.Zahl("fenster_min") is double f && f > 0 ? (long)f : null;
|
|
return p;
|
|
}
|
|
|
|
public bool Gesetzt => BuyinMin != null || BuyinMax != null || Name != null || Kategorie != null || FensterMin != null || !NurLaufend;
|
|
|
|
/// <summary>Fuer `Spielplan.turnier`: null, solange nichts gesetzt ist.</summary>
|
|
public JsonObject? Daten()
|
|
{
|
|
if (!Gesetzt) return null;
|
|
var d = new JsonObject { ["nur_laufend"] = NurLaufend };
|
|
if (BuyinMin is double a) d["buyin_min"] = a;
|
|
if (BuyinMax is double b) d["buyin_max"] = b;
|
|
if (Name != null) d["name"] = Name;
|
|
if (Kategorie != null) d["kategorie"] = Kategorie;
|
|
if (FensterMin is long m) d["fenster_min"] = m;
|
|
return d;
|
|
}
|
|
|
|
public int TypIndex => Math.Max(0, Array.FindIndex(Typen, t => t.Kategorie == Kategorie));
|
|
|
|
public void TypSetzen(int i) => Kategorie = i >= 0 && i < Typen.Length ? Typen[i].Kategorie : null;
|
|
|
|
/// <summary>Ein Buy-in aus dem Feld: Komma wie Punkt, leer oder <= 0 heisst offenes Ende.</summary>
|
|
public static double? BetragLesen(string roh) =>
|
|
double.TryParse(roh.Trim().Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var x) && x > 0 && double.IsFinite(x) ? x : null;
|
|
|
|
/// <summary>Minuten aus dem Feld: leer oder <= 0 heisst kein Zeitfenster.</summary>
|
|
public static long? MinutenLesen(string roh) => long.TryParse(roh.Trim(), out var x) && x > 0 ? x : null;
|
|
|
|
/// <summary>Fuers Feld ohne Tausenderpunkt: "2,5", "10".</summary>
|
|
public static string BetragText(double? x) =>
|
|
x is double v ? v.ToString("0.##", CultureInfo.InvariantCulture).Replace('.', ',') : "";
|
|
}
|