Files
pokerfreak/mac/Sources/Cockpit/Tische.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

227 lines
9.9 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
/// : oben die Tische (Klick holt einen nach vorn), darunter was gerade geschah. Sitzt der Laeufer
/// nirgends, steht dort, was bis zum Spielen fehlt, und wie die letzte Sitzung lief.
struct LiveAnsicht: View {
@Environment(Cockpit.self) private var cockpit
@State private var fragtSchliessen = false
private func schliessenFrage(_ n: Int) -> some View {
HStack {
Text("Alle \(n) Tische schließen? An jedem, an dem der Läufer sitzt, steht er auf.").font(.caption)
.fixedSize(horizontal: false, vertical: true)
Spacer()
Button("Abbrechen") { fragtSchliessen = false }
Button("Schließen") {
fragtSchliessen = false
cockpit.steuern("tische_schliessen")
}
.buttonStyle(.borderedProminent).tint(.red)
}
.controlSize(.small)
.padding(8)
.background(.red.opacity(0.12), in: RoundedRectangle(cornerRadius: 10))
}
var body: some View {
let kacheln = LiveKachel.alle(cockpit.ansicht)
ScrollView {
VStack(alignment: .leading, spacing: 10) {
TischLeiste(anzahl: cockpit.ansicht.kopf?.tischeOffen ?? kacheln.count) { fragtSchliessen = true }
if fragtSchliessen { schliessenFrage(max(kacheln.count, cockpit.ansicht.kopf?.tischeOffen ?? 0)) }
if kacheln.isEmpty {
Bereit()
} else {
Abschnitt(titel: "Tische", hinweis: "Klick holt nach vorn") { EmptyView() }
ForEach(kacheln) { KachelAnsicht(k: $0) }
}
Abschnitt(titel: "Geld", hinweis: cockpit.wahl.cash ? "Cash" : "Übung") { EmptyView() }
GeldUebersicht()
if let konto = cockpit.ansicht.kopf?.konto, !konto.felder.isEmpty {
KontoKarte(konto: konto)
}
Abschnitt(titel: "Gerade eben", hinweis: nil) { EmptyView() }
HandFeed()
}
.padding(12)
}
}
}
struct Abschnitt<Rechts: View>: View {
var titel: String
var hinweis: String?
@ViewBuilder var rechts: Rechts
var body: some View {
HStack(alignment: .firstTextBaseline, spacing: 6) {
Text(titel).font(.caption.weight(.semibold)).foregroundStyle(.secondary)
if let hinweis { Text(hinweis).font(.caption2).foregroundStyle(.tertiary) }
Spacer(minLength: 0)
rechts
}
.padding(.top, 4)
}
}
/// Alles, was alle Tische betrifft - immer sichtbar, nicht in einem Menü versteckt.
struct TischLeiste: View {
var anzahl: Int
var schliessen: () -> Void
@Environment(Cockpit.self) private var cockpit
var body: some View {
HStack(spacing: 6) {
knopf("Nach vorn", "macwindow.on.rectangle", "tische_vorn", aus: anzahl == 0)
knopf("Anordnen", "rectangle.split.2x2", "tische_anordnen", aus: anzahl == 0)
knopf("Foto", "camera", "foto", aus: anzahl == 0)
Button(action: schliessen) { kachel("Schließen", "xmark.rectangle", rot: true) }
.buttonStyle(.plain).disabled(anzahl == 0).opacity(anzahl == 0 ? 0.4 : 1)
.help("Alle Tische schließen")
}
}
private func knopf(_ titel: String, _ symbol: String, _ aktion: String, aus: Bool) -> some View {
Button { cockpit.steuern(aktion) } label: {
if cockpit.laeuftGerade(aktion) {
ProgressView().controlSize(.small).frame(maxWidth: .infinity, minHeight: 44)
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 10))
} else {
kachel(titel, symbol, rot: false)
}
}
.buttonStyle(.plain).disabled(aus).opacity(aus ? 0.4 : 1)
.help(titel)
}
private func kachel(_ titel: String, _ symbol: String, rot: Bool) -> some View {
VStack(spacing: 3) {
Image(systemName: symbol).font(.system(size: 14, weight: .semibold))
Text(titel).font(.system(size: 9.5, weight: .medium)).lineLimit(1).minimumScaleFactor(0.8)
}
.foregroundStyle(rot ? Color.red.opacity(0.9) : Color.primary)
.frame(maxWidth: .infinity, minHeight: 44)
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 10))
.contentShape(RoundedRectangle(cornerRadius: 10))
}
}
struct KachelAnsicht: View {
var k: LiveKachel
@Environment(Cockpit.self) private var cockpit
@State private var drueber = false
private var topf: Double? { k.topf }
var body: some View {
// Ein Knopf, keine Geste: das Panel ist am Hintergrund verschiebbar - ein Antippen freier
// Flaeche begann dort ein Fenster-Ziehen, und der Tisch kam nicht nach vorn.
Button { cockpit.steuern("tische_vorn", raum: k.raum) } label: { inhalt }
.buttonStyle(KartenDruck())
}
private var inhalt: some View {
VStack(alignment: .leading, spacing: 7) {
HStack(spacing: 6) {
Text(k.raumInfo?.titel ?? k.raum).font(.subheadline.weight(.semibold)).lineLimit(1)
if let z = k.raumInfo?.zustand { Abzeichen(text: z, farbe: Farben.zustand(z)) }
Spacer(minLength: 0)
symbolKnopf("camera", "Foto") { cockpit.steuern("foto", raum: k.raum) }
symbolKnopf("xmark", "Tisch schließen") { cockpit.steuern("tische_schliessen", raum: k.raum) }
}
if let m = k.modus { ModusLeiste(modus: m) }
MiniTisch(plaetze: k.raumInfo?.groesse ?? 6, board: k.board, topf: topf, zug: k.zug, tisch: k.raumInfo?.tisch)
HStack(alignment: .top, spacing: 10) {
// deine Karten groß, daneben was der Laeufer damit tut
if !k.karten.isEmpty {
HStack(spacing: 4) { ForEach(Array(k.karten.enumerated()), id: \.offset) { KarteAnsicht(code: $0.element, gross: true) } }
}
VStack(alignment: .leading, spacing: 3) {
if let a = k.aktion {
HStack(alignment: .firstTextBaseline, spacing: 6) {
Text(Aktionstext.mitBetrag(a, k.betragBB)).font(.callout.weight(.semibold))
if let e = k.equity { Text("Equity \(Format.prozent(e))").font(.caption).foregroundStyle(.secondary) }
Spacer(minLength: 0)
KlickSymbol(status: k.klick?.status, warum: k.klick?.warum)
}
if let t = k.klartext, !t.isEmpty {
Text(t).font(.caption).foregroundStyle(.secondary).lineLimit(3)
.fixedSize(horizontal: false, vertical: true)
}
} else {
Text(k.hinweis ?? "noch keine Entscheidung an diesem Tisch").font(.caption).foregroundStyle(.secondary)
}
}
}
if let t = k.raumInfo?.tisch, t.spieler.contains(where: { !$0.ich }) {
if let u = t.urteil { UrteilBand(urteil: u) }
HStack {
Text("Was ich über die Gegner denke").font(.caption2.weight(.semibold)).foregroundStyle(.secondary)
Spacer()
Text("antippen: alle Werte").font(.system(size: 9)).foregroundStyle(.tertiary)
}
GegnerListe(tisch: t)
}
if let r = k.raumInfo, r.platz != nil || r.stack != nil {
Text("Platz \(r.platz ?? "–") · Stack \(Format.auto(r.stack))" + (r.bb.map { " · BB \($0)" } ?? ""))
.font(.caption2).foregroundStyle(.tertiary)
}
if let b = cockpit.fotos[k.raum] { Foto(url: b) }
}
.padding(10)
.background(.white.opacity(drueber ? 0.09 : 0.05), in: RoundedRectangle(cornerRadius: 16, style: .continuous))
.overlay(RoundedRectangle(cornerRadius: 16, style: .continuous)
.strokeBorder(k.zug?.offen == true ? Color.orange : .clear, lineWidth: 1.5))
.contentShape(RoundedRectangle(cornerRadius: 16))
.animation(.snappy, value: k.zug?.offen)
.onHover { drueber = $0 }
.overlay(alignment: .topTrailing) {
if cockpit.laeuftGerade("tische_vorn", raum: k.raum) { ProgressView().controlSize(.mini).padding(8) }
}
.help("Klick: \(k.raum) nach vorn holen")
}
private func symbolKnopf(_ symbol: String, _ hilfe: String, _ tun: @escaping () -> Void) -> some View {
Button(action: tun) { Image(systemName: symbol).font(.caption) }
.buttonStyle(.borderless).foregroundStyle(.secondary).help(hilfe)
}
}
/// Sitzt der Laeufer nirgends: was bis zum Spielen fehlt, und wie die letzte Sitzung lief.
struct Bereit: View {
@Environment(Cockpit.self) private var cockpit
var body: some View {
Abschnitt(titel: "Bis zum Spielen", hinweis: nil) { EmptyView() }
Schrittleiste()
SitzungsKarte()
if let konto = cockpit.ansicht.kopf?.konto, !konto.felder.isEmpty {
KontoKarte(konto: konto)
}
}
}
struct Foto: View {
var url: URL
var body: some View {
AsyncImage(url: url) { bild in
bild.resizable().scaledToFit().clipShape(RoundedRectangle(cornerRadius: 8))
} placeholder: {
ProgressView().frame(maxWidth: .infinity, minHeight: 80)
}
}
}
/// Die Karte gibt beim Drücken sichtbar nach - man sieht, dass der Klick ankam.
struct KartenDruck: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.98 : 1)
.brightness(configuration.isPressed ? 0.06 : 0)
.animation(.snappy(duration: 0.12), value: configuration.isPressed)
}
}