Files
pokerfreak/winui/Kern/Ansicht.cs
T
mmintelandClaude Opus 5.5 f4d7078041 Zuschauer = Sammeln; Zuschauer-Reiter haelt; Sammler wartet nicht 60 s
Owner 20.11.: "wir haben oben ein zuschauer tab, das sollte direkt sammeln - jetzt
redundantes UI. und es klappte nicht, hat nix geoeffnet".

- WinUI: keine eigene Sammeln-Karte mit eigenem Knopf mehr. Im Reiter Zuschauer steht
  die Stufenwahl an Stelle des Spielplans, der Hauptknopf heisst "Sammeln starten" /
  "Sammeln stoppen". Wer den Reiter verlaesst (Uebung/Echtgeld), stoppt Log-Leser und
  Sammler. Zuschauen = Log-Leser laeuft ODER Sammler sammelt.
- steuern.ZUSCHAUER_PID las sicht/scratch, der Lauf schreibt in den Treffpunkt
  (betrieb/scratch) - seit 30.10. sprang der Reiter Zuschauer sofort auf Uebung zurueck
  und "Zuschauen beenden" fand keinen Lauf. Spec PidOrt prueft beide Orte gegeneinander.
- Sammler: "hat nix geoeffnet" = der erste Lobby-Abruf scheiterte am abgelaufenen Token
  des Clients (er erneuerte ihn 20:18:09, 45 s danach), der naechste kaeme erst nach
  60 s. Jetzt nach 10 s wieder, der Grund (Token abgelaufen / kein Token / gedrosselt)
  steht im Stand und orange in der Zeile ("wartet: ...").
- Sammler: am Ende pruefen, ob ein eigener Tisch noch lebt, und ihn bis zu 3x erneut
  schliessen (20:29: "Closing game table" bestaetigt, Tisch blieb offen).

Echt geprueft: Sammler 1 Tisch NL50 je 1 min am Client - geoeffnet nach 3 s, Ende
geschlossen ok, kein Tisch offen. WinUI-Probe: Reiter Zuschauer haelt, Chips unter
den Reitern, Hauptknopf "Sammeln starten". sammler_spec 50 OK, zuschauer PidOrt OK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 21:29:21 +01:00

160 lines
6.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Nodes;
namespace Pokerfreak.Cockpit.Kern;
/// <summary>
/// Die Ansicht des Servers (sicht/ANSICHT.md), nachsichtig gelesen: fehlt ein Feld oder hat es den
/// falschen Typ, ist es leer - nie ein Fehler. Die Bereiche bleiben JSON; die App liest, was sie zeigt.
/// </summary>
public sealed class Ansicht
{
public JsonObject Teile { get; }
public Ansicht(JsonObject teile) => Teile = teile;
public static Ansicht Leer { get; } = new(new JsonObject());
public JsonObject? Kopf => Teile.Obj("kopf");
public JsonObject? Jetzt => Teile.Obj("jetzt");
public JsonObject? Wachstum => Teile.Obj("wachstum");
public JsonObject? Entscheidungen => Teile.Obj("entscheidungen");
public JsonObject? Geld => Teile.Obj("geld");
public JsonObject? Sitzen => Teile.Obj("sitzen");
public JsonObject? Stil => Teile.Obj("stil");
public JsonObject? Ticker => Teile.Obj("ticker");
public JsonObject? Zuschauer => Teile.Obj("zuschauer");
/// <summary>Der Trainer an der Buehne (sicht/ANSICHT.md **trainer**).</summary>
public JsonObject? Trainer => Teile.Obj("trainer");
public bool Laeuft => Kopf.Wahr("laeuft");
/// <summary>Der Sammler (sicht/ansicht.py `sammler_`): sieht fremden Tischen zu, setzt sich nie.</summary>
public JsonObject? Sammler => Zuschauer.Obj("sammler");
public bool Sammelt => Sammler.Wahr("laeuft");
/// <summary>Der Zuschauer-Reiter ist an: der Log-Leser laeuft oder der Sammler sammelt (Owner 20.11.:
/// Zuschauer und Sammeln sind eins).</summary>
public bool Zuschauen => Zuschauer.Wahr("laeuft") || Sammelt;
}
public static class Json
{
public static JsonObject? Obj(this JsonObject? o, string k) => o?[k] as JsonObject;
public static JsonArray Liste(this JsonObject? o, string k) => o?[k] as JsonArray ?? new JsonArray();
public static IEnumerable<JsonObject> Objekte(this JsonObject? o, string k) =>
o.Liste(k).OfType<JsonObject>();
public static IEnumerable<string> Texte(this JsonObject? o, string k) =>
o.Liste(k).Select(TextVon).Where(t => t != null)!;
public static string? Text(this JsonObject? o, string k) => TextVon(o?[k]);
public static string T(this JsonObject? o, string k) => o.Text(k) ?? "";
public static string? TextVon(JsonNode? n) => n is JsonValue v
? v.GetValueKind() switch
{
JsonValueKind.String => v.GetValue<string>(),
JsonValueKind.Number => ZahlVon(v)?.ToString(CultureInfo.InvariantCulture),
JsonValueKind.True => "true",
JsonValueKind.False => "false",
_ => null,
}
: null;
/// <summary>Zahl aus einem Knoten. Vom Server gelesene Werte sind JsonElement; selbst gesetzte
/// (JsonValue.Create(long/int)) lassen sich nicht als double holen, daher alle Arten probieren.</summary>
public static double? ZahlVon(JsonNode? n)
{
if (n is not JsonValue v || v.GetValueKind() != JsonValueKind.Number) return null;
if (v.TryGetValue<double>(out var d)) return d;
if (v.TryGetValue<long>(out var l)) return l;
if (v.TryGetValue<int>(out var i)) return i;
if (v.TryGetValue<decimal>(out var m)) return (double)m;
if (v.TryGetValue<float>(out var f)) return f;
return double.TryParse(v.ToJsonString(), NumberStyles.Float, CultureInfo.InvariantCulture, out var t) ? t : null;
}
public static double? Zahl(this JsonObject? o, string k) => ZahlVon(o?[k]);
public static bool Wahr(this JsonObject? o, string k) =>
o?[k] is JsonValue v && v.GetValueKind() == JsonValueKind.True;
/// <summary>true/false, null wenn das Feld fehlt oder kein Wahrheitswert ist.</summary>
public static bool? WahrOderNull(this JsonObject? o, string k) =>
o?[k] is JsonValue v ? v.GetValueKind() switch
{
JsonValueKind.True => true,
JsonValueKind.False => false,
_ => null,
} : null;
/// <summary>Gleicher Inhalt? (Kacheln nur neu bauen, wenn sich ihr JSON aendert.)</summary>
public static string Abdruck(this JsonNode? n) => n?.ToJsonString() ?? "null";
}
/// <summary>Zahlen und Zeiten, wie die App sie zeigt: deutsch, Strich fuer unbekannt (format.rs).</summary>
public static class Format
{
private static readonly CultureInfo De = CultureInfo.GetCultureInfo("de-DE");
public static string Zahl(double? x, int stellen = 0)
{
if (x is not double v || !double.IsFinite(v)) return "–";
var s = Math.Round(v, stellen, MidpointRounding.AwayFromZero).ToString("#,0." + new string('#', stellen), De);
return s == "-0" ? "0" : s;
}
public static string Auto(double? x) => x is double v
? Zahl(v, Math.Abs(v) >= 100 ? 0 : Math.Abs(v) >= 10 ? 1 : 2)
: "–";
/// <summary>Achsenzahl: 1200 -> "1,2k", sonst bis eine Nachkommastelle.</summary>
public static string Kurzzahl(double v) => Math.Abs(v) >= 1000
? Zahl(v / 1000, 1) + "k"
: Zahl(v, Math.Abs(v) >= 10 ? 0 : 1);
public static string Prozent(double? x) => x is double v ? $"{Zahl(v * 100)} %" : "–";
public static string Vorzeichen(double? x, int stellen = 1)
{
if (x is not double v) return "–";
var t = Zahl(Math.Abs(v), stellen);
return v > 0 ? "+" + t : v < 0 ? "−" + t : t;
}
public static string Dauer(double s)
{
var g = (long)Math.Max(0, s);
return g >= 3600 ? $"{g / 3600} h {g % 3600 / 60} min" : g >= 60 ? $"{g / 60} min" : $"{g} s";
}
public static DateTime Ortszeit(double epoche) =>
DateTimeOffset.FromUnixTimeMilliseconds((long)(epoche * 1000)).LocalDateTime;
public static string Uhr(double? t) => t is double v ? Ortszeit(v).ToString("HH:mm:ss") : "–";
public static string Kurz(double? t) => t is double v ? Ortszeit(v).ToString("HH:mm") : "";
public static double Jetzt() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() / 1000.0;
/// <summary>"Qh" -> ("Q♥", rot); "Th" -> "10♥". Unlesbares: null.</summary>
public static (string Text, bool Rot)? Karte(string? s)
{
if (s is not { Length: 2 }) return null;
var (symbol, rot) = char.ToLowerInvariant(s[1]) switch
{
'h' => ("♥", true),
'd' => ("♦", true),
's' => ("♠", false),
'c' => ("♣", false),
_ => ("", false),
};
var r = char.ToUpperInvariant(s[0]);
if (symbol == "" || !"23456789TJQKA".Contains(r)) return null;
return ((r == 'T' ? "10" : r.ToString()) + symbol, rot);
}
}