Files
pokerfreak/mac/Sources/Cockpit/EntscheidungenGeld.swift
T
mmintel 9c79d8236b Acceptance 5.11.: channel play without AFK, quiet focus, working Cockpit, stronger play
- Practice tables: 20-min session 54/54 turns at the server, control session 28 turns,
  0 timeouts; stage: 3 tables, two rounds each, clean teardown.
- Never let the clock run: an engine abstention becomes check or fold (nie_verstreichen).
- Mittler join in a fixed order (kill the duplicate, then announce), a mittler ends with its
  game, the laufwache opens no tables, stop waits for the runner to stand up.
- Focus: no lobby connections from HUD, probes or layout; "Focus Window on Turn" off.
- Tables: disconnected or sitting-out opponents do not count; a table without channel is
  closed and avoided after 45 s; the join event keeps the writer's pid (strict invariants).
- Geldwache: same room list as the runner, the table's own report, stand up before closing.
- Engine: the small blind completes the top 65 % against limpers (price per fair share);
  the calling range of a bet is as wide as the villain calls - value bets into stations.
- Cockpit: the source tree never comes from SHELL; one operating set for laufwache and
  Cockpit (sicht/start.py --client, ServerStart).
- Project lives in ~/Projects/pokerfreak (kern was a detour).
2026-11-05 16:10:43 +01:00

223 lines
9.8 KiB
Swift
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.
import Foundation
import CockpitKern
import SwiftUI
struct EntscheidungenAnsicht: View {
@Environment(Cockpit.self) private var cockpit
@State private var filter = EntscheidungsFilter()
@State private var offen: String?
var body: some View {
let e = cockpit.ansicht.entscheidungen
let alle = e?.zeilen ?? []
let treffer = filter.anwenden(alle)
VStack(spacing: 0) {
VStack(spacing: 6) {
TextField("Suchen: Grund, Karten, Hand, Tisch", text: $filter.suche)
.textFieldStyle(.roundedBorder)
HStack(spacing: 6) {
Auswahl(titel: "Aktion", werte: e?.facetten?.aktion ?? [], wahl: $filter.aktion)
Auswahl(titel: "Stake", werte: e?.facetten?.stake ?? [], wahl: $filter.stake)
Auswahl(titel: "Spiel", werte: e?.facetten?.spielart ?? [], wahl: $filter.spielart)
Menu(filter.ergebnis?.rawValue.capitalized ?? "Ergebnis") {
Button("alle") { filter.ergebnis = nil }
ForEach(ErgebnisFilter.allCases, id: \.self) { x in Button(x.rawValue) { filter.ergebnis = x } }
}
.fixedSize()
Spacer(minLength: 0)
if !filter.istLeer { Button("Zurücksetzen") { filter = EntscheidungsFilter() }.buttonStyle(.link) }
}
.controlSize(.small)
Text(zaehler(e, treffer.count)).font(.caption2).foregroundStyle(.secondary)
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(12)
Divider()
if alle.isEmpty {
Leer(titel: "Noch keine Entscheidungen", text: e?.leer ?? "Sobald der Kern entscheidet, steht es hier.")
} else {
List(treffer) { z in
EntscheidungsZeileAnsicht(z: z, offen: offen == z.id)
.contentShape(Rectangle())
.onTapGesture { withAnimation(.snappy) { offen = offen == z.id ? nil : z.id } }
}
.scrollContentBackground(.hidden)
}
}
}
private func zaehler(_ e: Entscheidungen?, _ n: Int) -> String {
let da = e?.zeilen.count ?? 0
var t = n == da ? "\(da) Entscheidungen" : "\(n) von \(da) passen"
if let h = e?.hinweis { t += " · " + h }
return t
}
}
private struct Auswahl: View {
var titel: String
var werte: [String]
@Binding var wahl: String?
var body: some View {
Menu(wahl ?? titel) {
Button("alle") { wahl = nil }
ForEach(werte, id: \.self) { w in Button(w) { wahl = w } }
}
.fixedSize()
.disabled(werte.isEmpty)
}
}
struct EntscheidungsZeileAnsicht: View {
var z: EntscheidungsZeile
var offen: Bool
var body: some View {
VStack(alignment: .leading, spacing: 5) {
HStack(spacing: 6) {
Text(Zeit.uhr(z.zeit)).font(.caption.monospacedDigit()).foregroundStyle(.secondary)
Text(z.strasse ?? "").font(.caption).foregroundStyle(.secondary)
Text(Aktionstext.mitBetrag(z.aktionText ?? z.aktion, z.betragBB))
.font(.callout.weight(.semibold))
Spacer(minLength: 0)
if let x = z.ergebnisBB { Text(Format.vorzeichen(x) + " bb").font(.caption.monospacedDigit()).foregroundStyle(Farben.ergebnis(x)) }
KlickSymbol(status: z.klick, warum: z.klickWarum)
}
HStack(spacing: 6) {
if !z.karten.isEmpty { Kartenzeile(karten: z.karten, board: z.board) }
Text(z.klartext ?? z.grund ?? "").font(.caption).foregroundStyle(.secondary).lineLimit(offen ? nil : 2)
}
if offen, let m = z.modus {
// Cash steht schon unter Stake; Turnier und K-Poker brauchen die ganze Lage
if case .cash = m {} else { ModusLeiste(modus: m) }
}
if offen {
Grid(alignment: .leading, horizontalSpacing: 10, verticalSpacing: 3) {
zeile("Tisch", z.raum ?? "–")
zeile("Hand", z.hand ?? "–")
zeile("Stake", [z.stake, z.spielart].compactMap { $0 }.joined(separator: " · "))
zeile("Equity", Format.prozent(z.equity))
zeile("Confidence", Format.zahl(z.confidence))
zeile("Gedenkzeit", z.gedenkzeitS.map { Format.zahl($0, stellen: 1) + " s" } ?? "–")
zeile("Ergebnis", z.ergebnisText ?? "–")
zeile("Klick", [z.klick, z.klickWarum].compactMap { $0 }.filter { !$0.isEmpty }.joined(separator: " - "))
if let b = z.beleg, !b.isEmpty { zeile("Beleg", b) }
if let g = z.grund, g != z.klartext { zeile("Grund", g) }
}
.font(.caption)
.textSelection(.enabled)
.padding(.top, 4)
}
}
.padding(.vertical, 3)
}
private func zeile(_ a: String, _ b: String) -> some View {
GridRow {
Text(a).foregroundStyle(.secondary)
Text(b.isEmpty ? "–" : b)
}
}
}
struct GeldAnsicht: View {
@Environment(Cockpit.self) private var cockpit
@State private var art: String?
var body: some View {
let g = cockpit.ansicht.geld
let arten = Array(Set((g?.zeilen ?? []).compactMap(\.art))).sorted()
let zeilen = (g?.zeilen ?? []).filter { art == nil || $0.art == art }
VStack(spacing: 0) {
HStack {
Picker("Art", selection: $art) {
Text("alle").tag(String?.none)
ForEach(arten, id: \.self) { Text($0).tag(String?.some($0)) }
}
.fixedSize()
Spacer()
if g?.uebung == true { Abzeichen(text: "ÜBUNG", farbe: .blue) }
}
.controlSize(.small)
.padding(12)
Divider()
if zeilen.isEmpty {
Leer(titel: "Keine Geldbewegungen", text: g?.leer ?? "Buy-in, Nachkauf und Aufstehen erscheinen hier.")
} else {
List(zeilen) { z in
VStack(alignment: .leading, spacing: 3) {
HStack {
Text(Zeit.uhr(z.zeit)).font(.caption.monospacedDigit()).foregroundStyle(.secondary)
Text(z.art ?? "–").font(.callout.weight(.semibold))
if z.uebung == true { Abzeichen(text: "Übung", farbe: .blue) }
Spacer()
if let b = z.betrag { Text(Format.zahl(b)).font(.callout.monospacedDigit()) }
if let b = z.betragBB { Text("\(Format.zahl(b)) bb").font(.caption).foregroundStyle(.secondary) }
}
Text([z.raum, z.grund].compactMap { $0 }.filter { !$0.isEmpty }.joined(separator: " · "))
.font(.caption).foregroundStyle(.secondary).textSelection(.enabled)
}
.opacity(z.uebung == true ? 0.75 : 1)
}
.scrollContentBackground(.hidden)
}
}
}
}
struct ProtokollAnsicht: View {
enum Teil: String, CaseIterable { case gedanken = "Gedanken", ereignisse = "Ereignisse", geld = "Geld" }
@Environment(Cockpit.self) private var cockpit
@AppStorage("protokoll.teil") private var teil: Teil = .gedanken
@State private var pause: Ticker?
var body: some View {
let t = pause ?? cockpit.ansicht.ticker
VStack(spacing: 0) {
HStack {
Picker("", selection: $teil) { ForEach(Teil.allCases, id: \.self) { Text($0.rawValue) } }
.pickerStyle(.segmented).labelsHidden()
if teil != .geld {
Toggle(isOn: Binding(get: { pause != nil }, set: { pause = $0 ? cockpit.ansicht.ticker : nil })) {
Image(systemName: "pause")
}
.toggleStyle(.button).help("Anhalten zum Lesen")
}
}
.controlSize(.small)
.padding(12)
Divider()
if teil == .geld {
GeldAnsicht()
} else {
ScrollView {
LazyVStack(alignment: .leading, spacing: 6) {
if teil == .gedanken {
ForEach(Array((t?.gedanken ?? []).enumerated()), id: \.offset) { _, g in
Text(g).font(.system(.caption, design: .monospaced)).textSelection(.enabled)
}
} else {
ForEach(t?.zeilen ?? []) { z in
HStack(alignment: .firstTextBaseline, spacing: 6) {
Text(Zeit.uhr(z.zeit)).foregroundStyle(.secondary)
Text(z.art ?? "").foregroundStyle(.tint)
Text([z.raum, z.text].compactMap { $0 }.joined(separator: " · ")).textSelection(.enabled)
}
.font(.system(.caption, design: .monospaced))
}
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(12)
}
.overlay {
if (teil == .gedanken ? t?.gedanken.isEmpty : t?.zeilen.isEmpty) ?? true {
Leer(titel: "Noch nichts", text: t?.leer ?? "Der Strom läuft, sobald der Läufer arbeitet.")
}
}
}
}
}
}