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

167 lines
6.0 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
/// Der Modus eines Tisches auf einen Blick: Cash, Turnier (Level, Blinds, Spur zum Geld) oder
/// K-Poker (Menue als Tasten, Uhr). Quelle ist die Anfrage, mit der der Kern entschied.
struct ModusLeiste: View {
var modus: TischModus
var body: some View {
switch modus {
case .cash(let stake): cash(stake)
case .turnier(let t): TurnierLeiste(t: t)
case .kpoker(let k): kpoker(k)
}
}
private func cash(_ stake: String?) -> some View {
HStack(spacing: 6) {
ModusChip(symbol: "circle.circle", text: "Cash", farbe: .secondary)
if let stake { Text(stake).font(.caption).foregroundStyle(.secondary) }
Spacer(minLength: 0)
}
}
private func kpoker(_ k: TischModus.KPoker) -> some View {
HStack(spacing: 6) {
ModusChip(symbol: "keyboard", text: "K-Poker", farbe: .teal)
if k.menue.isEmpty {
Taste(text: "Menü unbekannt", leer: true)
} else {
ForEach(Array(k.menue.enumerated()), id: \.offset) { _, p in
Taste(text: Aktionskuerzel.kurz(p.aktion, nil), groessen: p.groessen)
}
}
Spacer(minLength: 0)
Label(k.uhrS.map { "\(Format.zahl($0, stellen: 0)) s" } ?? "–", systemImage: "timer")
.font(.caption.weight(.semibold).monospacedDigit()).foregroundStyle(.secondary)
.help("Zeit für einen Zug an diesem Tisch")
}
}
}
private struct TurnierLeiste: View {
var t: TischModus.Turnier
var body: some View {
VStack(alignment: .leading, spacing: 5) {
HStack(spacing: 6) {
ModusChip(symbol: "trophy.fill", text: "Level \(t.level.map(String.init) ?? "–")", farbe: .indigo)
Text(blinds).font(.caption.monospacedDigit()).foregroundStyle(.secondary).lineLimit(1)
Spacer(minLength: 0)
LageKapsel(lage: t.lage)
}
if let spur = t.spur {
HStack(spacing: 8) {
Geldspur(spur: spur, lage: t.lage)
Text(t.spurText).font(.caption2.monospacedDigit()).foregroundStyle(.secondary)
.fixedSize()
}
.help("\(t.feld) Spieler übrig, \(t.bezahlt) Plätze werden bezahlt")
}
}
}
private var blinds: String {
"BB \(Format.zahl(t.bb, stellen: 0))" + (t.ante.map { $0 > 0 ? " · Ante \(Format.zahl($0, stellen: 0))" : "" } ?? "")
}
}
/// Bubble pulsiert orange, im Geld ist gruen, davor ruhig mit der Zahl bis zum Geld.
private struct LageKapsel: View {
var lage: TischModus.Geldlage
@State private var puls = false
private var farbe: Color {
switch lage {
case .bubble: .orange
case .imGeld: .green
case .vorDemGeld: .secondary
}
}
var body: some View {
HStack(spacing: 5) {
Circle().fill(farbe).frame(width: 6, height: 6).opacity(lage == .bubble && puls ? 0.3 : 1)
Text(lage.text).font(.caption2.weight(.semibold))
}
.padding(.horizontal, 8).frame(height: 20)
.foregroundStyle(farbe)
.background(farbe.opacity(0.14), in: Capsule())
.animation(lage == .bubble ? .easeInOut(duration: 0.8).repeatForever(autoreverses: true) : .default, value: puls)
.onAppear { puls = lage == .bubble }
.onChange(of: lage) { _, l in puls = l == .bubble }
}
}
/// Ein Strich je verbleibendem Spieler, gefuellt = bezahlter Platz; grosse Felder als Balken.
private struct Geldspur: View {
var spur: TischModus.Spur
var lage: TischModus.Geldlage
private var farbe: Color { lage == .imGeld ? .green : .indigo }
var body: some View {
switch spur {
case .striche(let gefuellt, let gesamt):
HStack(spacing: 2) {
ForEach(0..<gesamt, id: \.self) { i in
if i < gefuellt {
Capsule().fill(farbe.opacity(0.75))
} else {
Capsule().strokeBorder(lage == .bubble ? Color.orange : .secondary, lineWidth: 1)
}
}
}
.frame(height: 6)
case .anteil(let a):
GeometryReader { g in
ZStack(alignment: .leading) {
Capsule().fill(.quaternary)
Capsule().fill(farbe.opacity(0.75)).frame(width: g.size.width * a)
}
}
.frame(height: 6)
}
}
}
struct ModusChip: View {
var symbol: String
var text: String
var farbe: Color
var body: some View {
Label(text, systemImage: symbol)
.font(.caption2.weight(.semibold))
.labelStyle(.titleAndIcon)
.padding(.horizontal, 8).frame(height: 20)
.foregroundStyle(farbe)
.background(farbe.opacity(0.14), in: Capsule())
}
}
/// Eine K-Poker-Aktion als Taste; Raise nennt seine Groessen klein daneben.
private struct Taste: View {
var text: String
var groessen: [Double] = []
var leer = false
var body: some View {
HStack(spacing: 3) {
Text(text).font(.caption2.weight(.semibold))
if !groessen.isEmpty {
Text(groessen.map { Format.zahl($0) }.joined(separator: " · ")).font(.system(size: 9.5)).foregroundStyle(.secondary)
}
}
.padding(.horizontal, 6).frame(height: 20)
.foregroundStyle(leer ? .secondary : .primary)
.background(leer ? Color.clear : Color.white.opacity(0.08), in: RoundedRectangle(cornerRadius: 5))
.overlay(RoundedRectangle(cornerRadius: 5).strokeBorder(.separator, style: StrokeStyle(lineWidth: 1, dash: leer ? [3] : [])))
.overlay(alignment: .bottom) {
if !leer { RoundedRectangle(cornerRadius: 1).fill(.separator).frame(height: 1.5).padding(.horizontal, 2) }
}
}
}