Mac cockpit: Features tab, cash/tournament switches, mini tables (WinUI parity)
- Features tab from GET /api/features (sicht/features.py): runner since, features on, changes pending a restart, missing programs, what the features bring, session vs session, details; polls every 10 s while open - Cash and tournaments switched on/off separately in real money (spielplan "aus", always sent like WinUI); main button "Cash oder Turniere einschalten" when both rest - Raster tiles become mini tables: felt, own cards, pot, coloured board or last own action, draining move clock Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,14 +3,14 @@ import CockpitKern
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
/// Die fünf Ansichten der Leiste, Tasten 1-5.
|
||||
/// Die Ansichten der Leiste, Tasten 1 bis 6.
|
||||
enum Reiter: String, CaseIterable, Identifiable {
|
||||
case cash, haende, statistik, protokoll, trainer
|
||||
case cash, haende, statistik, features, protokoll, trainer
|
||||
var id: String { rawValue }
|
||||
|
||||
var titel: String {
|
||||
switch self {
|
||||
case .cash: "Spielen"; case .haende: "Hände"; case .statistik: "Statistik"; case .protokoll: "Protokoll"
|
||||
case .cash: "Spielen"; case .haende: "Hände"; case .statistik: "Statistik"; case .features: "Features"; case .protokoll: "Protokoll"
|
||||
case .trainer: "Trainer"
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ enum Reiter: String, CaseIterable, Identifiable {
|
||||
var symbol: String {
|
||||
switch self {
|
||||
case .cash: "dot.radiowaves.left.and.right"; case .haende: "list.bullet.rectangle"
|
||||
case .statistik: "chart.line.uptrend.xyaxis"; case .protokoll: "text.alignleft"
|
||||
case .statistik: "chart.line.uptrend.xyaxis"; case .features: "switch.2"; case .protokoll: "text.alignleft"
|
||||
case .trainer: "graduationcap"
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,8 @@ final class Cockpit {
|
||||
@ObservationIgnored var beiSeite: ((Seite) -> Void)?
|
||||
@ObservationIgnored var beiSteuern: ((String, String?, String?) async -> Rueckmeldung)?
|
||||
@ObservationIgnored var fotoAdresse: ((String) -> URL?)?
|
||||
/// GET auf einen JSON-Endpunkt des Servers (z. B. /api/features); nil bei Fehler.
|
||||
@ObservationIgnored var beiHolen: ((String) async -> Data?)?
|
||||
@ObservationIgnored var beiUebernehmen: (() -> Void)?
|
||||
@ObservationIgnored private var meldungsZeit = 0
|
||||
|
||||
|
||||
@@ -0,0 +1,491 @@
|
||||
import AppKit
|
||||
import CockpitKern
|
||||
import SwiftUI
|
||||
|
||||
/// Der Reiter Features (winui/Seiten/FeaturesSeite.cs): was der Laeufer an Schaltern gerade spielt und was
|
||||
/// jedes Feature bringt. Liest GET /api/features alle 10 s, solange der Reiter sichtbar ist, und rechnet nichts
|
||||
/// nach - die Texte kommen aus `FeaturesText` (CockpitKern/Features.swift). Nur Anzeige.
|
||||
///
|
||||
/// `holen` ist der GET der Verbindung (`Verbindung.holen`); die Ansicht kennt den Server sonst nicht.
|
||||
struct FeaturesAnsicht: View {
|
||||
var holen: @MainActor (String) async -> Data?
|
||||
|
||||
@State private var daten: Features?
|
||||
@State private var versucht = false
|
||||
private static let takt = 10.0
|
||||
private static let ersterTakt = 2.0
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
if let d = daten, d.hatGruppen {
|
||||
FeaturesInhalt(d: d)
|
||||
} else {
|
||||
let l = versucht ? FeaturesText.leerSeite(daten) : FeaturesText.LeerSeite(titel: "Keine Features", text: "Verbindet mit dem Cockpit-Server …")
|
||||
Leer(titel: l.titel, text: l.text)
|
||||
}
|
||||
}
|
||||
.padding(12)
|
||||
}
|
||||
.task {
|
||||
// Endet mit dem Reiter: .task wird beim Verschwinden abgebrochen, dann bricht auch das Warten ab.
|
||||
while !Task.isCancelled {
|
||||
if let d = await holen("/api/features"), let f = Features.lesen(d) { daten = f }
|
||||
versucht = true
|
||||
do { try await Task.sleep(for: .seconds(daten == nil ? Self.ersterTakt : Self.takt)) } catch { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct FeaturesInhalt: View {
|
||||
var d: Features
|
||||
|
||||
var body: some View {
|
||||
FeaturesKopfKarte(d: d)
|
||||
if d.wirkung != nil { FeaturesWirkungAbschnitt(w: d.wirkung!) }
|
||||
if let s = d.sitzungen, !s.liste.isEmpty { FeaturesSitzungenAbschnitt(s: s) }
|
||||
FeaturesDetails(d: d)
|
||||
if let f = d.fehler {
|
||||
Text("Server: " + f).font(.caption).foregroundStyle(.red)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.padding(8).frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(.red.opacity(0.10), in: RoundedRectangle(cornerRadius: 8))
|
||||
}
|
||||
Text("Stand \(Zeit.uhr(d.stand)) · nur Anzeige, hier lässt sich nichts verstellen")
|
||||
.font(.caption2).foregroundStyle(.tertiary).frame(maxWidth: .infinity)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Kopf
|
||||
|
||||
private struct FeaturesKopfKarte: View {
|
||||
var d: Features
|
||||
|
||||
var body: some View {
|
||||
let k = FeaturesText.kopf(d)
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
HStack(spacing: 10) {
|
||||
Circle().fill(k.laeuft ? Color.green : Color.secondary).frame(width: 10, height: 10)
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text(k.titel).font(.title3.weight(.semibold)).fixedSize(horizontal: false, vertical: true)
|
||||
Text(k.unter).font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
FlussLayout(abstand: 6) {
|
||||
ForEach(Array(k.abzeichen.enumerated()), id: \.offset) { _, m in
|
||||
Abzeichen(text: m.text, farbe: StatistikFarbe.ton(m.ton))
|
||||
}
|
||||
}
|
||||
if !k.geaendert.isEmpty {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text("Geändert seit dem Start – wirkt erst nach einem Neustart des Läufers:")
|
||||
.font(.caption.weight(.semibold)).foregroundStyle(.orange)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
ForEach(Array(k.geaendert.enumerated()), id: \.offset) { _, z in
|
||||
Text(z).font(.caption2.monospaced()).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
.padding(8).frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(.orange.opacity(0.10), in: RoundedRectangle(cornerRadius: 8))
|
||||
}
|
||||
}
|
||||
.padding(14)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 14))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Wirkung
|
||||
|
||||
private struct FeaturesWirkungAbschnitt: View {
|
||||
var w: FeaturesWirkung
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Abschnitt(titel: "Was die Features bringen", hinweis: FeaturesText.wirkungKopf(w.sitzung)) { EmptyView() }
|
||||
VStack(spacing: 0) {
|
||||
if let f = w.fehler {
|
||||
Text("Konnte nicht rechnen: " + f).font(.caption).foregroundStyle(.red)
|
||||
.fixedSize(horizontal: false, vertical: true).padding(14)
|
||||
}
|
||||
ForEach(Array(w.features.enumerated()), id: \.element.id) { i, x in
|
||||
if i > 0 || w.fehler != nil { Divider() }
|
||||
FeatureKarte(x: x)
|
||||
}
|
||||
if let leer = FeaturesText.wirkungLeer(w) {
|
||||
Text(leer).font(.caption).foregroundStyle(.secondary).padding(14)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 14))
|
||||
Fussnote(FeaturesText.wirkungFuss(w.regeln)).padding(.horizontal, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct FeatureKarte: View {
|
||||
var x: FeaturesWirkFeature
|
||||
@State private var offen: Bool
|
||||
|
||||
init(x: FeaturesWirkFeature) {
|
||||
self.x = x
|
||||
_offen = State(initialValue: FeaturesText.standardOffen(x))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let zahl = FeaturesText.wirkungZahl(x)
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Button { withAnimation(.snappy) { offen.toggle() } } label: {
|
||||
HStack(alignment: .top, spacing: 10) {
|
||||
Circle().fill(StatistikFarbe.ton(x.ton)).frame(width: 10, height: 10).padding(.top, 5)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
HStack(spacing: 8) {
|
||||
Text(x.titel).font(.callout.weight(.semibold)).fixedSize(horizontal: false, vertical: true)
|
||||
Abzeichen(text: x.urteil, farbe: StatistikFarbe.ton(x.ton))
|
||||
}
|
||||
Text(x.satz).font(.caption)
|
||||
.foregroundStyle(x.ton == "rot" ? Color.red : Color.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
Spacer(minLength: 4)
|
||||
VStack(alignment: .trailing, spacing: 0) {
|
||||
Text(zahl.wert).font(.system(.title3, design: .rounded).weight(.semibold)).monospacedDigit()
|
||||
.foregroundStyle(zahl.ton.map(StatistikFarbe.ton) ?? .primary)
|
||||
Text(zahl.unter).font(.caption2).foregroundStyle(.tertiary)
|
||||
}
|
||||
Image(systemName: offen ? "chevron.up" : "chevron.down").font(.caption2).foregroundStyle(.tertiary)
|
||||
.frame(height: 20)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
// Ein Schalter des Features anders als in der vorigen Sitzung: immer sichtbar
|
||||
ForEach(Array(x.wechsel.enumerated()), id: \.offset) { _, wc in
|
||||
Text(FeaturesText.neuInSitzung(wc)).font(.caption2).foregroundStyle(.orange)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.padding(6).frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(.orange.opacity(0.08), in: RoundedRectangle(cornerRadius: 8))
|
||||
.padding(.leading, 20)
|
||||
}
|
||||
if offen { innen.padding(.leading, 20).padding(.bottom, 4) }
|
||||
}
|
||||
.padding(.horizontal, 14).padding(.vertical, 10)
|
||||
}
|
||||
|
||||
private var innen: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
if !x.erklaerung.isEmpty {
|
||||
Text(x.erklaerung).font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
KachelRaster(kacheln: FeaturesText.wirkungKacheln(x))
|
||||
Fussnote(FeaturesText.beteiligt(x))
|
||||
ForEach([("Größte Verluste", x.verlierer), ("Größte Gewinne", x.gewinner)], id: \.0) { titel, haende in
|
||||
if !haende.isEmpty {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(titel).font(.caption2.weight(.semibold)).foregroundStyle(.secondary)
|
||||
VStack(spacing: 0) {
|
||||
ForEach(Array(haende.enumerated()), id: \.element.hand) { i, h in
|
||||
if i > 0 { Divider() }
|
||||
FeaturesHandZeile(h: h, feature: x.id)
|
||||
}
|
||||
}
|
||||
.background(.white.opacity(0.04), in: RoundedRectangle(cornerRadius: 8))
|
||||
}
|
||||
}
|
||||
}
|
||||
if !x.zustand.isEmpty {
|
||||
Text("Schalter: " + x.zustand.sorted { $0.key < $1.key }
|
||||
.map { "\($0.key)=\(FeaturesText.wert($0.value))" }.joined(separator: " "))
|
||||
.font(.caption2.monospaced()).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Eine Hand: Kennung (Tipp kopiert sie und klappt die Gruende auf), Ergebnis, Uhrzeit; darunter der Ablauf.
|
||||
private struct FeaturesHandZeile: View {
|
||||
var h: FeaturesHand
|
||||
var feature: String
|
||||
@State private var offen = false
|
||||
|
||||
var body: some View {
|
||||
let t = FeaturesText.handZeile(h, feature: feature)
|
||||
Button {
|
||||
NSPasteboard.general.clearContents()
|
||||
NSPasteboard.general.setString(t.kennung, forType: .string)
|
||||
withAnimation(.snappy) { offen.toggle() }
|
||||
} label: {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "doc.on.doc").font(.system(size: 10)).foregroundStyle(.tint)
|
||||
Text(t.kennung).font(.caption.monospaced()).foregroundStyle(.blue).lineLimit(1).truncationMode(.middle)
|
||||
Spacer(minLength: 4)
|
||||
Text(t.ergebnis).font(.caption.weight(.semibold)).monospacedDigit()
|
||||
.foregroundStyle(t.ton.map(StatistikFarbe.ton) ?? .primary)
|
||||
}
|
||||
Text(t.mitte).font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
|
||||
kette(t)
|
||||
if offen {
|
||||
ForEach(Array(t.gruende.enumerated()), id: \.offset) { _, g in
|
||||
Text(g.text).font(.caption2).foregroundStyle(g.eigen ? Color.teal : Color.secondary.opacity(0.7))
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.horizontal, 10).padding(.vertical, 8)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help("Tippen: Hand-Kennung kopieren und die Gründe zeigen · \(t.hilfe)")
|
||||
}
|
||||
|
||||
private func kette(_ t: FeaturesText.HandText) -> Text {
|
||||
var r = Text("")
|
||||
for (i, z) in t.kette.enumerated() {
|
||||
if i > 0 { r = r + Text(" › ").foregroundStyle(.tertiary) }
|
||||
r = r + Text(z.text).fontWeight(z.eigen ? .semibold : .regular).foregroundStyle(z.eigen ? Color.teal : Color.secondary)
|
||||
if let w = z.wer { r = r + Text(" (\(w))").font(.caption2).foregroundStyle(.tertiary) }
|
||||
}
|
||||
return r.font(.caption)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Sitzung gegen Sitzung
|
||||
|
||||
private struct FeaturesSitzungenAbschnitt: View {
|
||||
var s: FeaturesSitzungen
|
||||
@State private var frueher = false
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Abschnitt(titel: "Sitzung gegen Sitzung", hinweis: "AIVAT bb/100") { EmptyView() }
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
if s.liste.count >= 2 {
|
||||
ViewThatFits(in: .horizontal) {
|
||||
HStack(alignment: .top, spacing: 8) { kachel("Vorige", s.liste[1]); kachel("Letzte", s.liste[0]) }
|
||||
VStack(spacing: 8) { kachel("Vorige", s.liste[1]); kachel("Letzte", s.liste[0]) }
|
||||
}
|
||||
} else {
|
||||
kachel("Letzte", s.liste[0])
|
||||
}
|
||||
if let v = s.vergleich { vergleich(v) }
|
||||
if s.liste.count > 2 {
|
||||
Button { withAnimation(.snappy) { frueher.toggle() } } label: {
|
||||
HStack {
|
||||
Text("Frühere Sitzungen").font(.caption.weight(.semibold))
|
||||
Spacer()
|
||||
Text("\(s.liste.count - 2)").font(.caption).foregroundStyle(.secondary)
|
||||
Image(systemName: frueher ? "chevron.up" : "chevron.down").font(.caption2).foregroundStyle(.tertiary)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
if frueher {
|
||||
ForEach(Array(s.liste.dropFirst(2).enumerated()), id: \.offset) { i, x in
|
||||
if i > 0 { Divider() }
|
||||
zeile(x)
|
||||
}
|
||||
}
|
||||
}
|
||||
Fussnote(FeaturesText.sitzungFuss(s))
|
||||
}
|
||||
.padding(12).frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 14))
|
||||
}
|
||||
}
|
||||
|
||||
private func kachel(_ titel: String, _ x: FeaturesSitzung) -> some View {
|
||||
let k = FeaturesText.sitzungKachel(titel, x)
|
||||
return VStack(alignment: .leading, spacing: 2) {
|
||||
Text(k.kopf).font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
|
||||
Text(k.gross).font(.system(.title3, design: .rounded).weight(.semibold)).monospacedDigit()
|
||||
.foregroundStyle(k.ton.map(StatistikFarbe.ton) ?? .primary)
|
||||
Text(k.mitte).font(.caption2).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
|
||||
Text(k.unter).font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(10)
|
||||
.background(.quaternary.opacity(0.5), in: RoundedRectangle(cornerRadius: 10))
|
||||
}
|
||||
|
||||
private func vergleich(_ v: FeaturesVergleich) -> some View {
|
||||
let ton = StatistikFarbe.ton(FeaturesText.urteilTon(v.urteil))
|
||||
return VStack(alignment: .leading, spacing: 6) {
|
||||
FlussLayout(abstand: 8) {
|
||||
Text("Letzte − vorige").font(.caption).foregroundStyle(.secondary)
|
||||
Text(FeaturesText.vergleichZeile(v)).font(.callout.weight(.semibold)).monospacedDigit()
|
||||
Abzeichen(text: v.urteil, farbe: ton)
|
||||
}
|
||||
Text(FeaturesText.urteilSatz(v.urteil)).font(.caption).foregroundStyle(ton).fixedSize(horizontal: false, vertical: true)
|
||||
if v.anders.isEmpty {
|
||||
Fussnote("Gleiche Schalter – ein Exe-Tausch steht nicht in der Schalter-Marke.")
|
||||
} else {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Diese Schalter waren anders als in der vorigen Sitzung:").font(.caption2.weight(.semibold)).foregroundStyle(.secondary)
|
||||
ForEach(Array(v.anders.enumerated()), id: \.offset) { _, a in
|
||||
(Text(a.name + " ").fontWeight(.semibold)
|
||||
+ Text(a.vorher ?? FeaturesText.nichtGesetzt).foregroundStyle(.secondary)
|
||||
+ Text(" → ").foregroundStyle(.tertiary)
|
||||
+ Text(a.nachher ?? FeaturesText.nichtGesetzt))
|
||||
.font(.caption2).fixedSize(horizontal: false, vertical: true)
|
||||
.help(FeaturesText.wechsel(a))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func zeile(_ x: FeaturesSitzung) -> some View {
|
||||
let z = FeaturesText.sitzungZeile(x)
|
||||
return HStack(alignment: .firstTextBaseline, spacing: 8) {
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text(z.kopf).font(.caption).fixedSize(horizontal: false, vertical: true)
|
||||
Text(z.unter).font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
Spacer(minLength: 4)
|
||||
Text(z.wert).font(.caption.weight(.semibold)).monospacedDigit().foregroundStyle(z.ton.map(StatistikFarbe.ton) ?? .primary)
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Details (zugeklappt)
|
||||
|
||||
private struct FeaturesDetails: View {
|
||||
var d: Features
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Abschnitt(titel: "Details", hinweis: "Schalter und Programme") { EmptyView() }
|
||||
VStack(spacing: 8) {
|
||||
ForEach(d.gruppen) { g in
|
||||
FeaturesFalte(titel: g.titel, wert: FeaturesText.gruppeWert(g), hinweis: FeaturesText.gruppeHinweis(g)) {
|
||||
VStack(spacing: 0) {
|
||||
ForEach(Array(g.schalter.enumerated()), id: \.offset) { i, s in
|
||||
if i > 0 { Divider() }
|
||||
SchalterZeile(s: s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FeaturesFalte(titel: "Programme im Einsatz", wert: FeaturesText.exesWert(d.exes),
|
||||
hinweis: "Kennung (md5) und Baudatum jeder Exe, die gerade zählt.") {
|
||||
VStack(spacing: 0) {
|
||||
ForEach(Array(d.exes.enumerated()), id: \.offset) { i, e in
|
||||
if i > 0 { Divider() }
|
||||
ExeZeile(e: e)
|
||||
}
|
||||
}
|
||||
}
|
||||
liste("Ausgeschaltet", FeaturesText.zeilenAus(d.aus), "Stehen in der Datei ausdrücklich auf aus (0, aus).")
|
||||
liste("Ruht", FeaturesText.zeilenRuht(d.ruht), "Einstellungen eines Schalters, der aus ist – sie schalten nichts.")
|
||||
liste("Leer oder unbekannt", FeaturesText.zeilenLeerUnbekannt(leer: d.leerZeilen, unbekannt: d.unbekannt),
|
||||
"Was der Läufer beim Lesen übergeht.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func liste(_ titel: String, _ zeilen: [FeaturesText.Zeile], _ hinweis: String) -> some View {
|
||||
if !zeilen.isEmpty {
|
||||
FeaturesFalte(titel: titel, wert: "\(zeilen.count)", hinweis: hinweis) {
|
||||
VStack(spacing: 0) {
|
||||
ForEach(Array(zeilen.enumerated()), id: \.offset) { i, z in
|
||||
if i > 0 { Divider() }
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 8) {
|
||||
Text(z.name).font(.caption.weight(.semibold).monospaced()).lineLimit(1).truncationMode(.middle)
|
||||
Spacer(minLength: 4)
|
||||
Text(z.wert).font(.caption.monospaced()).foregroundStyle(.secondary).lineLimit(1).truncationMode(.head)
|
||||
}
|
||||
Text(z.unter).font(.caption2).foregroundStyle(.tertiary).lineLimit(2).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
.padding(.horizontal, 12).padding(.vertical, 6)
|
||||
.help(z.unter)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein zugeklappter Abschnitt mit Titel links, Zahl rechts, Hinweis darunter.
|
||||
private struct FeaturesFalte<Inhalt: View>: View {
|
||||
var titel: String
|
||||
var wert: String
|
||||
var hinweis: String?
|
||||
@ViewBuilder var inhalt: Inhalt
|
||||
@State private var offen = false
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Button { withAnimation(.snappy) { offen.toggle() } } label: {
|
||||
HStack(spacing: 8) {
|
||||
Text(titel).font(.callout.weight(.semibold)).fixedSize(horizontal: false, vertical: true)
|
||||
Spacer(minLength: 4)
|
||||
Text(wert).font(.caption).foregroundStyle(.secondary)
|
||||
Image(systemName: offen ? "chevron.up" : "chevron.down").font(.caption2).foregroundStyle(.tertiary)
|
||||
}
|
||||
.padding(.horizontal, 12).frame(minHeight: 38)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help(hinweis ?? "")
|
||||
if offen {
|
||||
if let hinweis { Fussnote(hinweis).padding(.horizontal, 12).padding(.bottom, 4) }
|
||||
inhalt
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
}
|
||||
|
||||
private struct SchalterZeile: View {
|
||||
var s: FeaturesSchalter
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||||
Text(s.name).font(.caption.weight(.semibold).monospaced()).lineLimit(1).truncationMode(.middle)
|
||||
if s.neuSeitStart { Abzeichen(text: "NEU", farbe: .orange) }
|
||||
if s.sharingan { Abzeichen(text: "SHARINGAN", farbe: .purple) }
|
||||
Spacer(minLength: 4)
|
||||
Text(FeaturesText.wert(s.wert, pfad: s.pfad)).font(.caption.monospaced()).foregroundStyle(.teal)
|
||||
.lineLimit(1).truncationMode(.head).help(s.wert)
|
||||
}
|
||||
Text(FeaturesText.grund(datum: s.datum, kommentar: s.kommentar)).font(.caption2).foregroundStyle(.secondary)
|
||||
.lineLimit(2).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
.padding(.horizontal, 12).padding(.vertical, 8)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.help(FeaturesText.schalterTipp(s))
|
||||
}
|
||||
}
|
||||
|
||||
private struct ExeZeile: View {
|
||||
var e: FeaturesExe
|
||||
|
||||
var body: some View {
|
||||
let z = FeaturesText.exeZustand(e)
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
Circle().fill(StatistikFarbe.ton(z.ton)).frame(width: 8, height: 8).padding(.top, 4)
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text(e.rolle).font(.caption.weight(.semibold)).fixedSize(horizontal: false, vertical: true)
|
||||
Text(e.name).font(.caption2).foregroundStyle(.tertiary).lineLimit(1).truncationMode(.middle)
|
||||
}
|
||||
Spacer(minLength: 4)
|
||||
VStack(alignment: .trailing, spacing: 1) {
|
||||
Text(e.md5 ?? "–").font(.caption.monospaced())
|
||||
Text(FeaturesText.exeUnter(e)).font(.caption2).foregroundStyle(z.ton == "rot" ? Color.red : Color.secondary)
|
||||
.multilineTextAlignment(.trailing).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 12).padding(.vertical, 8)
|
||||
.opacity(e.an ? 1 : 0.5)
|
||||
.help(e.pfad)
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,9 @@ struct TischListe: View {
|
||||
GridRow {
|
||||
ForEach(0..<spalten, id: \.self) { s in
|
||||
if let c = live.chips.first(where: { $0.reihe == z && $0.spalte == s }) {
|
||||
RasterKachel(chip: c, offen: offen == c.raum) { offen = offen == c.raum ? nil : c.raum }
|
||||
RasterKachel(chip: c, kachel: live.kacheln.first { $0.raum == c.raum }, offen: offen == c.raum) {
|
||||
offen = offen == c.raum ? nil : c.raum
|
||||
}
|
||||
} else {
|
||||
Color.clear.frame(maxWidth: .infinity, minHeight: 1)
|
||||
}
|
||||
@@ -164,15 +166,19 @@ enum RaumName {
|
||||
static func kurz(_ satz: String) -> String { satz.replacing(name) { "#" + $0.1 } }
|
||||
}
|
||||
|
||||
/// Eine Kachel im Raster als kleiner Tisch (Owner 30.11.: "informativer und geiler", wie WinUI): Filzgrund, Kopf und
|
||||
/// Netto, eigene Karten mit Topf, darunter Board in Farbe oder die letzte eigene Aktion; am Zug orange mit
|
||||
/// ablaufender Uhr. Nach dem Fold sind die Karten blass.
|
||||
private struct RasterKachel: View {
|
||||
var chip: LiveChip
|
||||
var kachel: LiveKachelDaten?
|
||||
var offen: Bool
|
||||
var tippen: () -> Void
|
||||
|
||||
var body: some View {
|
||||
let nr = RaumName.nummer(chip.raum)
|
||||
Button(action: tippen) {
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
HStack(spacing: 4) {
|
||||
Circle().fill(Farben.name(chip.punktTon)).frame(width: 6, height: 6)
|
||||
Text(nr == chip.raum ? chip.titel : String(nr.suffix(5)))
|
||||
@@ -183,18 +189,97 @@ private struct RasterKachel: View {
|
||||
}
|
||||
Text(chip.zeile).font(.system(size: 12, weight: .semibold).monospacedDigit())
|
||||
.foregroundStyle(Farben.name(chip.zeileTon)).lineLimit(1)
|
||||
if let kachel { Minitisch(kachel: kachel, amZug: chip.amZug) }
|
||||
}
|
||||
.padding(.horizontal, 7).padding(.vertical, 5)
|
||||
.padding(.horizontal, 7).padding(.top, 5).padding(.bottom, 6)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(chip.amZug ? Color.orange.opacity(0.22) : Color.white.opacity(offen ? 0.14 : 0.06),
|
||||
in: RoundedRectangle(cornerRadius: 5))
|
||||
.overlay(RoundedRectangle(cornerRadius: 5)
|
||||
.strokeBorder(chip.amZug ? Color.orange.opacity(0.9) : Color.white.opacity(offen ? 0.35 : 0), lineWidth: 1))
|
||||
.contentShape(RoundedRectangle(cornerRadius: 5))
|
||||
.background(grund, in: RoundedRectangle(cornerRadius: 6))
|
||||
.overlay(RoundedRectangle(cornerRadius: 6)
|
||||
.strokeBorder(chip.amZug ? Color.orange.opacity(0.9) : Color.white.opacity(offen ? 0.35 : 0.07), lineWidth: 1))
|
||||
.contentShape(RoundedRectangle(cornerRadius: 6))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help(chip.titel)
|
||||
}
|
||||
|
||||
/// Filzgrund: dunkles Tischgruen von oben nach unten (aufgeklappt etwas heller); am Zug orange.
|
||||
private var grund: AnyShapeStyle {
|
||||
if chip.amZug { return AnyShapeStyle(Color.orange.opacity(0.22)) }
|
||||
let oben = Color(red: 20 / 255, green: 115 / 255, blue: 77 / 255).opacity(offen ? 0.43 : 0.27)
|
||||
let unten = Color(red: 8 / 255, green: 64 / 255, blue: 43 / 255).opacity(offen ? 0.27 : 0.15)
|
||||
return AnyShapeStyle(LinearGradient(colors: [oben, unten], startPoint: .top, endPoint: .bottom))
|
||||
}
|
||||
}
|
||||
|
||||
/// Unter Kopf und Netto: eigene Karten mit Topf, darunter Board oder letzte eigene Aktion, am Zug die Uhr.
|
||||
private struct Minitisch: View {
|
||||
var kachel: LiveKachelDaten
|
||||
var amZug: Bool
|
||||
|
||||
var body: some View {
|
||||
let karten = Array(kachel.karten.prefix(4))
|
||||
HStack(spacing: 3) {
|
||||
HStack(spacing: 1) {
|
||||
if karten.isEmpty { Text("–").font(.system(size: 10)).foregroundStyle(.tertiary) }
|
||||
ForEach(Array(karten.enumerated()), id: \.offset) { MikroKarte(code: $0.element).opacity(kachel.ichRaus ? 0.35 : 1) }
|
||||
}
|
||||
Spacer(minLength: 2)
|
||||
if !kachel.topf.isEmpty {
|
||||
Text(kachel.topf.replacingOccurrences(of: "Topf ", with: ""))
|
||||
.font(.system(size: 9.5).monospacedDigit()).foregroundStyle(Color.yellow.opacity(0.85)).lineLimit(1)
|
||||
}
|
||||
}
|
||||
let board = Array(kachel.board.prefix(5))
|
||||
if !board.isEmpty {
|
||||
board.reduce(Text("")) { t, roh in
|
||||
let k = Karte(roh)
|
||||
return t + Text(k.map { $0.rang + $0.farbe.symbol } ?? "?")
|
||||
.foregroundColor(k?.farbe.rot == true ? .red : .primary)
|
||||
}
|
||||
.font(.system(size: 10, weight: .semibold)).lineLimit(1)
|
||||
.help(board.compactMap { Karte($0).map { $0.rang + $0.farbe.symbol } }.joined(separator: " "))
|
||||
} else if !kachel.ichAktion.isEmpty {
|
||||
Text(kachel.ichAktion).font(.system(size: 9.5, weight: .semibold)).lineLimit(1)
|
||||
.foregroundStyle(LiveAktion.ton(kachel.ichAktion).isEmpty ? Color.primary : Farben.name(LiveAktion.ton(kachel.ichAktion)))
|
||||
}
|
||||
if amZug, let zug = kachel.zug, zug.restAnteil(jetzt: Date().timeIntervalSince1970) != nil {
|
||||
ZugUhrBalken(zug: zug).padding(.top, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Die ablaufende Zug-Uhr als Balken, jede Sekunde nachgestellt.
|
||||
private struct ZugUhrBalken: View {
|
||||
var zug: Zug
|
||||
|
||||
var body: some View {
|
||||
TimelineView(.periodic(from: .now, by: 1)) { kontext in
|
||||
let a = zug.restAnteil(jetzt: kontext.date.timeIntervalSince1970) ?? 0
|
||||
GeometryReader { g in
|
||||
ZStack(alignment: .leading) {
|
||||
Capsule().fill(Color.white.opacity(0.10))
|
||||
Capsule().fill(Farben.name(Zug.uhrTon(a)).opacity(0.9)).frame(width: g.size.width * a)
|
||||
}
|
||||
}
|
||||
.frame(height: 3)
|
||||
.animation(.linear(duration: 1), value: a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Eine winzige Karte fuer die Kachel (Rang und Farbe, rot oder dunkel auf hell).
|
||||
private struct MikroKarte: View {
|
||||
var code: String
|
||||
|
||||
var body: some View {
|
||||
let k = Karte(code)
|
||||
Text((k?.rang ?? "?") + (k?.farbe.symbol ?? ""))
|
||||
.font(.system(size: 9.5, weight: .bold, design: .rounded))
|
||||
.foregroundStyle(k?.farbe.rot == true ? Color.red : Color.black)
|
||||
.padding(.horizontal, 2)
|
||||
.frame(minWidth: 17, minHeight: 17)
|
||||
.background(Color.white.opacity(0.92), in: RoundedRectangle(cornerRadius: 3))
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Tisch als Zeile (Zustand, Nummer und Stufe, Karten, was er tut, Ergebnis), darunter die volle Kachel.
|
||||
|
||||
@@ -570,6 +570,7 @@ struct SpielFuss: View {
|
||||
if notAus {
|
||||
NotAusBand().transition(.scale(scale: 0.95).combined(with: .opacity))
|
||||
} else {
|
||||
if cockpit.wahl.cash, !zuschauen { BereichSchalterReihe(laeuft: laeuft) }
|
||||
HStack(spacing: 8) {
|
||||
HauptknopfAnsicht()
|
||||
if !zuschauen, laeuft || cockpit.pausiertGewollt { PauseKnopf() }
|
||||
@@ -600,6 +601,67 @@ struct SpielFuss: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Cash und Turniere getrennt an/aus (Owner 30.11., wie WinUI): ueber dem Hauptknopf, wirkt live
|
||||
/// (der Plan geht bei laufendem Laeufer sofort mit, betrieb/spielplan.reihe_von).
|
||||
private struct BereichSchalterReihe: View {
|
||||
@Environment(Cockpit.self) private var cockpit
|
||||
var laeuft: Bool
|
||||
|
||||
var body: some View {
|
||||
let live = cockpit.ansicht.sitzen?.live
|
||||
let angemeldet = (cockpit.ansicht.kopf?.turnierAnmeldungen ?? []).filter { !$0.raum.isEmpty }.count
|
||||
let cash = Bereiche.cash(cockpit.wahl, tische: laeuft ? live?.cashTische ?? 0 : 0)
|
||||
let turniere = Bereiche.turniere(cockpit.wahl, tische: laeuft ? live?.turnierTische ?? 0 : 0, angemeldet: angemeldet)
|
||||
ViewThatFits(in: .horizontal) {
|
||||
HStack(spacing: 8) { schalter(cash, turniere) }
|
||||
VStack(spacing: 6) { schalter(cash, turniere) }
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func schalter(_ cash: BereichStand, _ turniere: BereichStand) -> some View {
|
||||
BereichSchalter(titel: "Cash", symbol: "suit.spade.fill", ton: .green, stand: cash) { cockpit.wahl.umschalten("cash") }
|
||||
BereichSchalter(titel: "Turniere", symbol: "trophy.fill", ton: .teal, stand: turniere) { cockpit.wahl.umschalten("turniere") }
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Bereichsschalter: Zeichen, Name, was gerade ist, rechts ein Schieber. An farbig getoent, ruhend grau.
|
||||
private struct BereichSchalter: View {
|
||||
var titel: String
|
||||
var symbol: String
|
||||
var ton: Color
|
||||
var stand: BereichStand
|
||||
var tun: () -> Void
|
||||
|
||||
var body: some View {
|
||||
Button(action: tun) {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: symbol).font(.system(size: 13)).foregroundStyle(stand.an ? ton : Color.secondary)
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Text(titel).font(.callout.weight(.semibold))
|
||||
Text(stand.unter).font(.caption2).lineLimit(1).truncationMode(.tail)
|
||||
.foregroundStyle(stand.an ? AnyShapeStyle(.secondary) : AnyShapeStyle(Color.orange.opacity(0.9)))
|
||||
}
|
||||
Spacer(minLength: 4)
|
||||
Capsule().fill(stand.an ? ton.opacity(0.9) : Color.white.opacity(0.14))
|
||||
.frame(width: 28, height: 16)
|
||||
.overlay(alignment: stand.an ? .trailing : .leading) {
|
||||
Circle().fill(stand.an ? Color.black.opacity(0.85) : Color.white.opacity(0.7))
|
||||
.frame(width: 10, height: 10).padding(.horizontal, 3)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 10).padding(.vertical, 7)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(stand.an ? ton.opacity(0.14) : Color.white.opacity(0.04), in: RoundedRectangle(cornerRadius: 10))
|
||||
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(stand.an ? ton.opacity(0.55) : Color.white.opacity(0.10)))
|
||||
.contentShape(RoundedRectangle(cornerRadius: 10))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(!stand.bedienbar)
|
||||
.help(stand.hilfe)
|
||||
.animation(.easeOut(duration: 0.15), value: stand.an)
|
||||
}
|
||||
}
|
||||
|
||||
/// Pause: der Laeufer klickt nicht mehr, Tische und Sitz bleiben (lokale Pause-Dateien).
|
||||
private struct PauseKnopf: View {
|
||||
@Environment(Cockpit.self) private var cockpit
|
||||
|
||||
@@ -53,6 +53,16 @@ final class Verbindung {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein GET auf den Server (z. B. "/api/features"): der Koerper bei Status 200, sonst nil.
|
||||
func holen(_ pfad: String) async -> Data? {
|
||||
guard let a = adresse else { return nil }
|
||||
var anfrage = URLRequest(url: a.http.appending(path: pfad), timeoutInterval: 15)
|
||||
anfrage.httpMethod = "GET"
|
||||
guard let (d, antwort) = try? await sitzung.data(for: anfrage),
|
||||
(antwort as? HTTPURLResponse)?.statusCode == 200 else { return nil }
|
||||
return d
|
||||
}
|
||||
|
||||
/// Ein Knopf. Die Rueckmeldung kommt hier und zusaetzlich ueber den WebSocket.
|
||||
/// `daten`: JSON-Text eines Objekts (Spielplan, Modus) - als Text, weil er Faeden wechselt.
|
||||
func steuern(_ aktion: String, raum: String? = nil, daten: String? = nil) async -> Rueckmeldung {
|
||||
|
||||
@@ -93,6 +93,7 @@ struct Leiste: View {
|
||||
case .cash: SpielenAnsicht()
|
||||
case .haende: EntscheidungenAnsicht()
|
||||
case .statistik: StatistikAnsicht()
|
||||
case .features: FeaturesAnsicht(holen: { p in await cockpit.beiHolen?(p) })
|
||||
case .protokoll: ProtokollAnsicht()
|
||||
case .trainer: TrainerAnsicht()
|
||||
}
|
||||
@@ -316,6 +317,7 @@ extension Hauptknopf {
|
||||
case .clientStarten: "CoinPoker starten"
|
||||
case .clientNeuStarten: "CoinPoker neu starten"
|
||||
case .portFehlt: "Debug-Port fehlt"
|
||||
case .nichtsAn: "Cash oder Turniere einschalten"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,6 +336,7 @@ extension Hauptknopf {
|
||||
case .clientStarten: "power"
|
||||
case .clientNeuStarten: "arrow.clockwise"
|
||||
case .portFehlt: "exclamationmark.triangle"
|
||||
case .nichtsAn: "pause.circle"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +346,7 @@ extension Hauptknopf {
|
||||
case .zuschauenBeenden, .sammelnStarten: .teal
|
||||
case .starten(let cash): cash ? .red : .green
|
||||
case .notAusLoesen, .clientStarten, .clientNeuStarten: .green
|
||||
case .budgetFehlt, .freigabeFehlt, .portFehlt, .unbekannt: .gray
|
||||
case .budgetFehlt, .freigabeFehlt, .portFehlt, .nichtsAn, .unbekannt: .gray
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,6 +367,7 @@ extension Hauptknopf {
|
||||
case .clientStarten: "CoinPoker mit Debug-Port starten - danach anmelden"
|
||||
case .clientNeuStarten: "CoinPoker läuft ohne Debug-Port - beenden und mit Port neu starten, danach anmelden"
|
||||
case .portFehlt: "CoinPoker läuft ohne Debug-Port, aber Tische sind offen - erst die Tische schließen, dann neu starten"
|
||||
case .nichtsAn: "Cash und Turniere ruhen beide - oben einen der beiden Schalter antippen"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ final class App: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
cockpit.beiSteuern = { [verbindung] a, r, d in await verbindung.steuern(a, raum: r, daten: d) }
|
||||
cockpit.fotoAdresse = { [verbindung] p in verbindung.adresse?.foto(p) }
|
||||
cockpit.beiHolen = { [verbindung] p in await verbindung.holen(p) }
|
||||
cockpit.beiUebernehmen = { [weak self] in
|
||||
self?.cockpit.verbindung = .startet
|
||||
self?.server.uebernehmen()
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import Foundation
|
||||
|
||||
/// Was ein Bereichsschalter (Cash / Turniere) zeigt: an oder ruhend, darunter was gerade ist, die Hilfe beim Zeigen.
|
||||
/// `bedienbar` falsch: Turniere ohne Turnier in der Vorrang-Reihe - der Schalter hat nichts zu schalten.
|
||||
public struct BereichStand: Equatable, Sendable {
|
||||
public var an: Bool
|
||||
public var unter: String
|
||||
public var hilfe: String
|
||||
public var bedienbar = true
|
||||
}
|
||||
|
||||
/// Die Schalter Cash / Turniere (winui/Seiten/CashSeite.cs `Bereiche`). Ruht Cash, verlaesst der Laeufer die
|
||||
/// Cash-Tische nach der Hand und oeffnet keine; ruhen die Turniere, meldet er nichts Neues an, laufende spielt er
|
||||
/// zu Ende (betrieb/spielplan.reihe_von). `tische`: laufende Tische des Bereichs (0, wenn der Laeufer nicht laeuft).
|
||||
public enum Bereiche {
|
||||
static let gezeigteStufen = 3
|
||||
|
||||
public static func cash(_ wahl: Spielplan, tische: Int) -> BereichStand {
|
||||
let an = !wahl.ruht("cash")
|
||||
let geld = wahl.stufen.filter { $0 > 0 }
|
||||
let stufen = geld.isEmpty ? "automatisch" : geld.prefix(gezeigteStufen).map(nl).joined(separator: ", ")
|
||||
let unter = an ? (tische > 0 ? "\(Self.tische(tische)) · \(stufen)" : stufen)
|
||||
: (tische > 0 ? "ruht · \(Self.tische(tische)) laufen aus" : "ruht")
|
||||
let hilfe = an
|
||||
? "Antippen: Cash ruhen lassen – er steht nach der laufenden Hand auf und öffnet keine Cash-Tische mehr. Turniere laufen weiter."
|
||||
: "Antippen: Cash wieder spielen – er öffnet Cash-Tische nach den Stufen."
|
||||
return BereichStand(an: an, unter: unter, hilfe: hilfe)
|
||||
}
|
||||
|
||||
public static func turniere(_ wahl: Spielplan, tische: Int, angemeldet: Int) -> BereichStand {
|
||||
guard wahl.hatTurniere else {
|
||||
return BereichStand(an: false, unter: "keine in den Stufen",
|
||||
hilfe: "Unter „Stufen“ ein Turnier (Freeroll …) in die Reihe nehmen", bedienbar: false)
|
||||
}
|
||||
if wahl.ruht("turniere") {
|
||||
return BereichStand(an: false, unter: tische > 0 ? "ruht · \(Self.tische(tische)) spielt zu Ende" : "ruht · meldet nichts an",
|
||||
hilfe: "Antippen: Turniere wieder anmelden")
|
||||
}
|
||||
var teile: [String] = []
|
||||
if tische > 0 { teile.append("\(tische) läuft") }
|
||||
if angemeldet > 0 { teile.append("\(angemeldet) angemeldet") }
|
||||
return BereichStand(an: true, unter: teile.isEmpty ? "meldet an" : teile.joined(separator: " · "),
|
||||
hilfe: "Antippen: Turniere ruhen lassen – keine neuen Anmeldungen, laufende spielt er zu Ende. Cash läuft weiter.")
|
||||
}
|
||||
|
||||
static func tische(_ n: Int) -> String { "\(n) Tisch\(n == 1 ? "" : "e")" }
|
||||
|
||||
/// 0.02 -> "NL2" (Big Blind in Cent, hoechstens zwei Nachkommastellen).
|
||||
static func nl(_ bb: Double) -> String { "NL" + Format.roh((bb * 10_000).rounded() / 100) }
|
||||
}
|
||||
@@ -0,0 +1,772 @@
|
||||
import Foundation
|
||||
|
||||
// Der Reiter Features (GET /api/features, sicht/features.py + sicht/featurewirkung.py) - wie
|
||||
// winui/Seiten/FeaturesSeite.cs ihn zeigt. Alles nachsichtig gelesen: jedes Feld darf fehlen, eine Zahl darf
|
||||
// als Text kommen, ein kaputter Listeneintrag faellt weg. Die Texte stehen hier als reine Funktionen
|
||||
// (`FeaturesText`), die Ansicht malt sie nur.
|
||||
|
||||
private extension KeyedDecodingContainer {
|
||||
/// Eine ganze Zahl; was nicht endlich oder absurd gross ist, ist unbekannt (Int(x) wuerde sonst abstuerzen).
|
||||
func ganz(_ k: Key) -> Int? {
|
||||
guard let x = zahl(k), x.isFinite, abs(x) < 1e15 else { return nil }
|
||||
return Int(x)
|
||||
}
|
||||
|
||||
func einzeln<T: Decodable>(_ k: Key) -> T? {
|
||||
(try? decodeIfPresent(T.self, forKey: k)) ?? nil
|
||||
}
|
||||
|
||||
func vorhanden(_ k: Key) -> Bool {
|
||||
contains(k) && !((try? decodeNil(forKey: k)) ?? true)
|
||||
}
|
||||
}
|
||||
|
||||
/// Mittel mit 95-%-Halbbreite und Summe (featurewirkung._mittel; bei Sitzungen ohne Summe).
|
||||
public struct FeaturesMass: Decodable, Equatable, Sendable {
|
||||
public var mittel: Double?
|
||||
public var halb95: Double?
|
||||
public var summe: Double?
|
||||
public var n: Int?
|
||||
enum CodingKeys: String, CodingKey { case mittel, halb95, summe, n }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
mittel = c.zahl(.mittel); halb95 = c.zahl(.halb95); summe = c.zahl(.summe); n = c.ganz(.n)
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Schalter, der in der Sitzung anders war als in der vorigen (name, vorher, nachher; nil = nicht gesetzt).
|
||||
public struct FeaturesUnterschied: Decodable, Equatable, Sendable {
|
||||
public var name: String
|
||||
public var vorher: String?
|
||||
public var nachher: String?
|
||||
enum CodingKeys: String, CodingKey { case name, vorher, nachher }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
name = c.text(.name) ?? ""; vorher = c.text(.vorher); nachher = c.text(.nachher)
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Schalter, der seit dem Laeuferstart aus der Datei verschwand (jetzt nil = wieder Standard).
|
||||
public struct FeaturesWeg: Decodable, Equatable, Sendable {
|
||||
public var name: String
|
||||
public var vorher: String
|
||||
public var jetzt: String?
|
||||
enum CodingKeys: String, CodingKey { case name, vorher, jetzt }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
name = c.text(.name) ?? ""; vorher = c.text(.vorher) ?? ""; jetzt = c.text(.jetzt)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesLaeufer: Decodable, Equatable, Sendable {
|
||||
public var seit: Double?
|
||||
public var markeVon: Double?
|
||||
public var geaendert: Int
|
||||
public var weg: [FeaturesWeg]
|
||||
enum CodingKeys: String, CodingKey { case seit, markeVon = "marke_von", geaendert, weg }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
seit = c.zahl(.seit); markeVon = c.zahl(.markeVon); geaendert = c.ganz(.geaendert) ?? 0; weg = c.objekte(.weg)
|
||||
}
|
||||
public init() { seit = nil; markeVon = nil; geaendert = 0; weg = [] }
|
||||
}
|
||||
|
||||
public struct FeaturesSchalter: Decodable, Equatable, Sendable {
|
||||
public var name: String
|
||||
public var wert: String
|
||||
public var zeile: Int?
|
||||
public var datum: String?
|
||||
public var kommentar: String?
|
||||
public var block: [String]
|
||||
public var sharingan: Bool
|
||||
public var pfad: Bool
|
||||
/// null (kein Laeufer, keine Marke) zaehlt als nicht neu.
|
||||
public var neuSeitStart: Bool
|
||||
enum CodingKeys: String, CodingKey { case name, wert, zeile, datum, kommentar, block, sharingan, pfad, neuSeitStart = "neu_seit_start" }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
name = c.text(.name) ?? ""; wert = c.text(.wert) ?? ""; zeile = c.ganz(.zeile)
|
||||
datum = c.text(.datum); kommentar = c.text(.kommentar); block = c.liste(.block)
|
||||
sharingan = c.wahr(.sharingan); pfad = c.wahr(.pfad); neuSeitStart = c.wahr(.neuSeitStart)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesGruppe: Decodable, Equatable, Sendable, Identifiable {
|
||||
public var id: String
|
||||
public var titel: String
|
||||
public var schalter: [FeaturesSchalter]
|
||||
enum CodingKeys: String, CodingKey { case id, titel, schalter }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
id = c.text(.id) ?? ""; titel = c.text(.titel) ?? id; schalter = c.objekte(.schalter)
|
||||
}
|
||||
}
|
||||
|
||||
/// Eine Zeile aus "aus" oder "ruht" (ruht bringt `elter` mit).
|
||||
public struct FeaturesEinstellung: Decodable, Equatable, Sendable {
|
||||
public var name: String
|
||||
public var wert: String
|
||||
public var datum: String?
|
||||
public var kommentar: String?
|
||||
public var elter: String
|
||||
enum CodingKeys: String, CodingKey { case name, wert, datum, kommentar, elter }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
name = c.text(.name) ?? ""; wert = c.text(.wert) ?? ""; datum = c.text(.datum)
|
||||
kommentar = c.text(.kommentar); elter = c.text(.elter) ?? ""
|
||||
}
|
||||
}
|
||||
|
||||
/// Eine leere Zeile der Datei; `gilt` = was trotzdem weiter gilt.
|
||||
public struct FeaturesLeerZeile: Decodable, Equatable, Sendable {
|
||||
public var name: String
|
||||
public var zeile: Int?
|
||||
public var gilt: String?
|
||||
enum CodingKeys: String, CodingKey { case name, zeile, gilt }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
name = c.text(.name) ?? ""; zeile = c.ganz(.zeile); gilt = c.text(.gilt)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesUnbekannt: Decodable, Equatable, Sendable {
|
||||
public var name: String
|
||||
public var wert: String
|
||||
public var zeile: Int?
|
||||
enum CodingKeys: String, CodingKey { case name, wert, zeile }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
name = c.text(.name) ?? ""; wert = c.text(.wert) ?? ""; zeile = c.ganz(.zeile)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesExe: Decodable, Equatable, Sendable {
|
||||
public var rolle: String
|
||||
public var name: String
|
||||
public var pfad: String
|
||||
public var an: Bool
|
||||
public var da: Bool
|
||||
public var laeuft: Bool
|
||||
public var md5: String?
|
||||
public var datum: Double?
|
||||
enum CodingKeys: String, CodingKey { case rolle, name, pfad, an, da, laeuft, md5, datum }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
rolle = c.text(.rolle) ?? ""; name = c.text(.name) ?? ""; pfad = c.text(.pfad) ?? ""
|
||||
an = c.wahr(.an); da = c.wahr(.da); laeuft = c.wahr(.laeuft); md5 = c.text(.md5); datum = c.zahl(.datum)
|
||||
}
|
||||
}
|
||||
|
||||
/// Eine Sitzung (gleiche Schalter-Marke, keine Pause ueber 60 min): AIVAT bb/100 mit 95 %.
|
||||
public struct FeaturesSitzung: Decodable, Equatable, Sendable {
|
||||
public var von: Double?
|
||||
public var bis: Double?
|
||||
public var haende: Int
|
||||
public var roh: FeaturesMass?
|
||||
public var aivat: FeaturesMass?
|
||||
public var nettoBB: Double?
|
||||
public var anders: [FeaturesUnterschied]
|
||||
enum CodingKeys: String, CodingKey { case von, bis, haende, roh, aivat, nettoBB = "netto_bb", anders }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
von = c.zahl(.von); bis = c.zahl(.bis); haende = c.ganz(.haende) ?? 0
|
||||
roh = c.einzeln(.roh); aivat = c.einzeln(.aivat); nettoBB = c.zahl(.nettoBB); anders = c.objekte(.anders)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesVergleich: Decodable, Equatable, Sendable {
|
||||
public var diff: Double?
|
||||
public var halb95: Double?
|
||||
public var urteil: String
|
||||
public var anders: [FeaturesUnterschied]
|
||||
enum CodingKeys: String, CodingKey { case diff, halb95, urteil, anders }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
diff = c.zahl(.diff); halb95 = c.zahl(.halb95); urteil = c.text(.urteil) ?? ""; anders = c.objekte(.anders)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesSitzungen: Decodable, Equatable, Sendable {
|
||||
/// Neueste zuerst.
|
||||
public var liste: [FeaturesSitzung]
|
||||
public var vergleich: FeaturesVergleich?
|
||||
public var klein: Int
|
||||
public var mindest: Int?
|
||||
enum CodingKeys: String, CodingKey { case liste, vergleich, klein, mindest }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
liste = c.objekte(.liste); vergleich = c.einzeln(.vergleich); klein = c.ganz(.klein) ?? 0; mindest = c.ganz(.mindest)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Wirkung je Feature
|
||||
|
||||
public struct FeaturesZug: Decodable, Equatable, Sendable {
|
||||
public var street: String
|
||||
public var aktion: String
|
||||
public var groesse: Double?
|
||||
public var grund: String
|
||||
/// Die Features, die diese Entscheidung zaehlt (ids).
|
||||
public var wer: [String]
|
||||
enum CodingKeys: String, CodingKey { case street, aktion, groesse, grund, wer }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
street = c.text(.street) ?? ""; aktion = c.text(.aktion) ?? ""; groesse = c.zahl(.groesse)
|
||||
grund = c.text(.grund) ?? ""; wer = c.liste(.wer)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesHand: Decodable, Equatable, Sendable {
|
||||
public var hand: String
|
||||
public var t: Double?
|
||||
public var raum: String?
|
||||
public var roh: Double?
|
||||
public var aivat: Double?
|
||||
/// Die Features, bei denen diese Hand zaehlt, weil sie das meiste Geld setzten.
|
||||
public var haupt: [String]
|
||||
public var alle: [FeaturesZug]
|
||||
enum CodingKeys: String, CodingKey { case hand, t, raum, roh, aivat, haupt, alle }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
hand = c.text(.hand) ?? ""; t = c.zahl(.t); raum = c.text(.raum); roh = c.zahl(.roh); aivat = c.zahl(.aivat)
|
||||
haupt = c.liste(.haupt); alle = c.objekte(.alle)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesWechsel: Decodable, Equatable, Sendable {
|
||||
public var name: String
|
||||
public var vorher: String?
|
||||
public var nachher: String?
|
||||
public var kommentar: String?
|
||||
enum CodingKeys: String, CodingKey { case name, vorher, nachher, kommentar }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
name = c.text(.name) ?? ""; vorher = c.text(.vorher); nachher = c.text(.nachher); kommentar = c.text(.kommentar)
|
||||
}
|
||||
}
|
||||
|
||||
/// Die Haende, in denen das Feature das meiste Geld setzte.
|
||||
public struct FeaturesHaupt: Decodable, Equatable, Sendable {
|
||||
public var haende: Int
|
||||
public var aivat: FeaturesMass?
|
||||
public var roh: FeaturesMass?
|
||||
enum CodingKeys: String, CodingKey { case haende, aivat, roh }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
haende = c.ganz(.haende) ?? 0; aivat = c.einzeln(.aivat); roh = c.einzeln(.roh)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesVorher: Decodable, Equatable, Sendable {
|
||||
public var haupt: FeaturesHaupt
|
||||
enum CodingKeys: String, CodingKey { case haupt }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
haupt = c.einzeln(.haupt) ?? FeaturesHaupt.leer
|
||||
}
|
||||
}
|
||||
|
||||
extension FeaturesHaupt {
|
||||
static let leer: FeaturesHaupt = {
|
||||
// Ein leeres Objekt liest sich immer; try! ist hier ausgeschlossen.
|
||||
(try? JSONDecoder().decode(FeaturesHaupt.self, from: Data("{}".utf8))) ?? FeaturesHaupt(haende: 0, aivat: nil, roh: nil)
|
||||
}()
|
||||
init(haende: Int, aivat: FeaturesMass?, roh: FeaturesMass?) { self.haende = haende; self.aivat = aivat; self.roh = roh }
|
||||
}
|
||||
|
||||
public struct FeaturesWirkVergleich: Decodable, Equatable, Sendable {
|
||||
public var diff: Double?
|
||||
public var halb95: Double?
|
||||
public var urteil: String
|
||||
enum CodingKeys: String, CodingKey { case diff, halb95, urteil }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
diff = c.zahl(.diff); halb95 = c.zahl(.halb95); urteil = c.text(.urteil) ?? ""
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesWirkFeature: Decodable, Equatable, Sendable, Identifiable {
|
||||
public var id: String
|
||||
public var titel: String
|
||||
public var erklaerung: String
|
||||
/// "rot", "gruen" oder "grau".
|
||||
public var ton: String
|
||||
public var satz: String
|
||||
public var urteil: String
|
||||
public var entscheidungen: Int
|
||||
public var ueberstimmt: Int
|
||||
public var haende: Int
|
||||
public var aivat: FeaturesMass?
|
||||
public var roh: FeaturesMass?
|
||||
public var haupt: FeaturesHaupt
|
||||
public var wechsel: [FeaturesWechsel]
|
||||
public var vorher: FeaturesVorher?
|
||||
public var vergleich: FeaturesWirkVergleich?
|
||||
public var verlierer: [FeaturesHand]
|
||||
public var gewinner: [FeaturesHand]
|
||||
/// Wert der zugehoerigen Schalter in dieser Sitzung (Name -> Wert).
|
||||
public var zustand: [String: String]
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, titel, erklaerung, ton, satz, urteil, entscheidungen, ueberstimmt, haende, aivat, roh, haupt
|
||||
case wechsel, vorher, vergleich, verlierer, gewinner, zustand
|
||||
}
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
id = c.text(.id) ?? ""; titel = c.text(.titel) ?? id; erklaerung = c.text(.erklaerung) ?? ""
|
||||
ton = c.text(.ton) ?? "grau"; satz = c.text(.satz) ?? ""; urteil = c.text(.urteil) ?? ""
|
||||
entscheidungen = c.ganz(.entscheidungen) ?? 0; ueberstimmt = c.ganz(.ueberstimmt) ?? 0; haende = c.ganz(.haende) ?? 0
|
||||
aivat = c.einzeln(.aivat); roh = c.einzeln(.roh); haupt = c.einzeln(.haupt) ?? FeaturesHaupt.leer
|
||||
wechsel = c.objekte(.wechsel); vorher = c.einzeln(.vorher); vergleich = c.einzeln(.vergleich)
|
||||
verlierer = c.objekte(.verlierer); gewinner = c.objekte(.gewinner); zustand = c.woerter(.zustand)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FeaturesWirkSitzung: Decodable, Equatable, Sendable {
|
||||
public var von: Double?
|
||||
public var bis: Double?
|
||||
public var haende: Int
|
||||
public var aivatBB: Double?
|
||||
enum CodingKeys: String, CodingKey { case von, bis, haende, aivatBB = "aivat_bb" }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
von = c.zahl(.von); bis = c.zahl(.bis); haende = c.ganz(.haende) ?? 0; aivatBB = c.zahl(.aivatBB)
|
||||
}
|
||||
}
|
||||
|
||||
/// Die Regeln der Ampel (featurewirkung): fehlen sie, gelten die Werte des Servers.
|
||||
public struct FeaturesRegeln: Decodable, Equatable, Sendable {
|
||||
public var minHaende: Int
|
||||
public var klumpenBB: Double
|
||||
public var klumpenAnteil: Double
|
||||
enum CodingKeys: String, CodingKey { case minHaende = "min_haende", klumpenBB = "klumpen_bb", klumpenAnteil = "klumpen_anteil" }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
minHaende = c.ganz(.minHaende) ?? 10; klumpenBB = c.zahl(.klumpenBB) ?? 15; klumpenAnteil = c.zahl(.klumpenAnteil) ?? 0.5
|
||||
}
|
||||
public init() { minHaende = 10; klumpenBB = 15; klumpenAnteil = 0.5 }
|
||||
}
|
||||
|
||||
public struct FeaturesWirkung: Decodable, Equatable, Sendable {
|
||||
public var features: [FeaturesWirkFeature]
|
||||
public var sitzung: FeaturesWirkSitzung?
|
||||
public var hinweis: String?
|
||||
public var fehler: String?
|
||||
public var regeln: FeaturesRegeln
|
||||
enum CodingKeys: String, CodingKey { case features, sitzung, hinweis, fehler, regeln }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
features = c.objekte(.features); sitzung = c.einzeln(.sitzung); hinweis = c.text(.hinweis)
|
||||
fehler = c.text(.fehler); regeln = c.einzeln(.regeln) ?? FeaturesRegeln()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Die ganze Nutzlast
|
||||
|
||||
public struct Features: Decodable, Equatable, Sendable {
|
||||
public var stand: Double?
|
||||
/// Der Server rechnet noch ({rechnet: true, leer: "..."}).
|
||||
public var rechnet: Bool
|
||||
/// `leer` als Text (solange der Server rechnet); als Liste steht es in `leerZeilen`.
|
||||
public var leerText: String?
|
||||
public var fehler: String?
|
||||
public var hatGruppen: Bool
|
||||
public var laeufer: FeaturesLaeufer
|
||||
public var an: Int
|
||||
public var gruppen: [FeaturesGruppe]
|
||||
public var aus: [FeaturesEinstellung]
|
||||
public var ruht: [FeaturesEinstellung]
|
||||
public var unbekannt: [FeaturesUnbekannt]
|
||||
public var leerZeilen: [FeaturesLeerZeile]
|
||||
public var exes: [FeaturesExe]
|
||||
public var sitzungen: FeaturesSitzungen?
|
||||
public var wirkung: FeaturesWirkung?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case stand, rechnet, leer, fehler, laeufer, an, gruppen, aus, ruht, unbekannt, exes, sitzungen, wirkung
|
||||
}
|
||||
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
stand = c.zahl(.stand); rechnet = c.wahr(.rechnet); leerText = c.text(.leer); fehler = c.text(.fehler)
|
||||
hatGruppen = c.vorhanden(.gruppen)
|
||||
laeufer = c.einzeln(.laeufer) ?? FeaturesLaeufer(); an = c.ganz(.an) ?? 0
|
||||
gruppen = c.objekte(.gruppen); aus = c.objekte(.aus); ruht = c.objekte(.ruht)
|
||||
unbekannt = c.objekte(.unbekannt); leerZeilen = c.objekte(.leer); exes = c.objekte(.exes)
|
||||
sitzungen = c.einzeln(.sitzungen); wirkung = c.einzeln(.wirkung)
|
||||
}
|
||||
|
||||
/// Die Antwort des Servers lesen; ein Text, der kein Objekt ist, ergibt nil.
|
||||
public static func lesen(text: String) -> Features? { lesen(Data(text.utf8)) }
|
||||
|
||||
public static func lesen(_ daten: Data) -> Features? {
|
||||
try? JSONDecoder().decode(Features.self, from: daten)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Texte
|
||||
|
||||
/// Die Texte des Reiters als reine Funktionen (wie FeaturesSeite.cs). Zeiten in der Ortszeit;
|
||||
/// `zoneSekunden` (Abstand zu UTC) ist fuer die Pruefung.
|
||||
public enum FeaturesText {
|
||||
public static let nichtGesetzt = "nicht gesetzt"
|
||||
|
||||
public struct Zeile: Equatable, Sendable {
|
||||
public var name: String
|
||||
public var wert: String
|
||||
public var unter: String
|
||||
public init(name: String, wert: String, unter: String) { self.name = name; self.wert = wert; self.unter = unter }
|
||||
}
|
||||
|
||||
public struct LeerSeite: Equatable, Sendable {
|
||||
public var titel: String
|
||||
public var text: String
|
||||
public init(titel: String, text: String) { self.titel = titel; self.text = text }
|
||||
}
|
||||
|
||||
// ---- Zeit
|
||||
|
||||
private static func zeit(_ t: Double?, _ muster: String, _ zone: Int?) -> String? {
|
||||
guard let t, t.isFinite else { return nil }
|
||||
let f = DateFormatter()
|
||||
f.locale = Locale(identifier: "de_DE")
|
||||
f.dateFormat = muster
|
||||
if let zone, let z = TimeZone(secondsFromGMT: zone) { f.timeZone = z }
|
||||
return f.string(from: Date(timeIntervalSince1970: t))
|
||||
}
|
||||
|
||||
/// "30.11. 12:16" (ohne Zeit: "–").
|
||||
public static func uhrtag(_ t: Double?, zoneSekunden: Int? = nil) -> String {
|
||||
zeit(t, "dd.MM. HH:mm", zoneSekunden) ?? "–"
|
||||
}
|
||||
|
||||
/// "12:16" (ohne Zeit: leer).
|
||||
public static func uhr(_ t: Double?, zoneSekunden: Int? = nil) -> String {
|
||||
zeit(t, "HH:mm", zoneSekunden) ?? ""
|
||||
}
|
||||
|
||||
// ---- Zahlen
|
||||
|
||||
/// "+12,5 ±4": Wert mit Vorzeichen, dahinter die Halbbreite der 95-%-Spanne.
|
||||
public static func mitSpanne(_ m: Double?, _ h: Double?) -> String {
|
||||
guard let m else { return "–" }
|
||||
guard let h else { return AuswertungText.vz(m, stellen: 1) }
|
||||
return "\(AuswertungText.vz(m, stellen: 1)) ±\(Format.zahl(h, stellen: 1))"
|
||||
}
|
||||
|
||||
private static func vz(_ x: Double?, _ stellen: Int = 1) -> String { AuswertungText.vz(x, stellen: stellen) }
|
||||
|
||||
/// Eine Groesse ohne Nachkommanullen, mit Punkt (2.5, 0.125, 3).
|
||||
public static func groesse(_ x: Double) -> String {
|
||||
let f = NumberFormatter()
|
||||
f.locale = Locale(identifier: "en_US_POSIX")
|
||||
f.numberStyle = .decimal
|
||||
f.usesGroupingSeparator = false
|
||||
f.minimumFractionDigits = 0
|
||||
f.maximumFractionDigits = 3
|
||||
return f.string(from: x as NSNumber) ?? Format.roh(x)
|
||||
}
|
||||
|
||||
// ---- Leerseite
|
||||
|
||||
public static let nichtErreicht = "Server ohne /api/features (älterer Stand?) oder nicht erreicht."
|
||||
|
||||
/// Was statt der Seite steht, solange es keine Gruppen gibt. `nil` = noch nie geantwortet.
|
||||
public static func leerSeite(_ f: Features?) -> LeerSeite {
|
||||
guard let f else { return LeerSeite(titel: "Keine Features", text: nichtErreicht) }
|
||||
return LeerSeite(titel: f.rechnet ? "Wird gelesen" : "Keine Features", text: f.leerText ?? "Verbindet mit dem Cockpit-Server …")
|
||||
}
|
||||
|
||||
// ---- Kopf
|
||||
|
||||
public struct Marke: Equatable, Sendable {
|
||||
public var text: String
|
||||
public var ton: String
|
||||
}
|
||||
|
||||
public struct Kopf: Equatable, Sendable {
|
||||
public var titel: String
|
||||
public var unter: String
|
||||
public var laeuft: Bool
|
||||
public var abzeichen: [Marke]
|
||||
/// Schalter, die seit dem Laeuferstart anders sind (gelten erst nach einem Neustart).
|
||||
public var geaendert: [String]
|
||||
}
|
||||
|
||||
public static func kopf(_ f: Features, zoneSekunden: Int? = nil) -> Kopf {
|
||||
let l = f.laeufer
|
||||
let laeuft = l.seit != nil
|
||||
let titel = laeuft ? "Läufer spielt seit \(uhrtag(l.seit, zoneSekunden: zoneSekunden))" : "Läufer steht"
|
||||
let unter = laeuft ? "mit diesen Schaltern"
|
||||
: l.markeVon.map { "letzte Hand \(uhrtag($0, zoneSekunden: zoneSekunden)) · die Schalter gelten beim nächsten Start" }
|
||||
?? "noch keine Hand mit Schalter-Marke"
|
||||
var a = [Marke(text: "\(f.an) \(f.an == 1 ? "Feature" : "Features") an", ton: "blau")]
|
||||
let feats = f.wirkung?.features ?? []
|
||||
let rot = feats.filter { $0.ton == "rot" }.count
|
||||
let gruen = feats.filter { $0.ton == "gruen" }.count
|
||||
if rot > 0 { a.append(Marke(text: rot == 1 ? "1 Feature ansehen" : "\(rot) Features ansehen", ton: "rot")) }
|
||||
if gruen > 0 { a.append(Marke(text: "\(gruen) bringen Geld", ton: "gruen")) }
|
||||
let n = l.geaendert
|
||||
if n > 0 {
|
||||
a.append(Marke(text: n == 1 ? "1 Änderung wartet auf Neustart" : "\(n) Änderungen warten auf Neustart", ton: "orange"))
|
||||
} else {
|
||||
a.append(Marke(text: laeuft ? "Schalter wie beim Start" : "Schalter wie im letzten Lauf", ton: "grau"))
|
||||
}
|
||||
let fehlt = f.exes.filter { $0.an && !$0.da }.count
|
||||
if fehlt > 0 { a.append(Marke(text: fehlt == 1 ? "1 Programm fehlt" : "\(fehlt) Programme fehlen", ton: "rot")) }
|
||||
var zeilen = f.gruppen.flatMap(\.schalter).filter(\.neuSeitStart).map { "\($0.name) = \(wert($0.wert, pfad: $0.pfad))" }
|
||||
zeilen += l.weg.map { "\($0.name): \($0.vorher) → \($0.jetzt ?? "entfernt (wieder Standard)")" }
|
||||
return Kopf(titel: titel, unter: unter, laeuft: laeuft, abzeichen: a, geaendert: zeilen)
|
||||
}
|
||||
|
||||
// ---- Sitzung gegen Sitzung
|
||||
|
||||
public static func urteilTon(_ urteil: String) -> String {
|
||||
urteil == "besser" ? "gruen" : urteil == "schlechter" ? "rot" : "gelb"
|
||||
}
|
||||
|
||||
public static func urteilSatz(_ urteil: String) -> String {
|
||||
switch urteil {
|
||||
case "besser": "Die letzte Sitzung war besser als die vorige – und das ist kein Zufall mehr."
|
||||
case "schlechter": "Die letzte Sitzung war schlechter als die vorige – und das ist kein Zufall mehr."
|
||||
default: "Noch kein Urteil: der Unterschied kann Zufall sein. Mehr Hände abwarten."
|
||||
}
|
||||
}
|
||||
|
||||
public struct SitzungKachelText: Equatable, Sendable {
|
||||
public var kopf: String
|
||||
public var gross: String
|
||||
public var ton: String?
|
||||
public var mitte: String
|
||||
public var unter: String
|
||||
}
|
||||
|
||||
public static func sitzungKachel(_ titel: String, _ s: FeaturesSitzung, zoneSekunden: Int? = nil) -> SitzungKachelText {
|
||||
let m = s.aivat?.mittel
|
||||
return SitzungKachelText(
|
||||
kopf: "\(titel) · \(uhrtag(s.von, zoneSekunden: zoneSekunden))–\(uhr(s.bis, zoneSekunden: zoneSekunden))",
|
||||
gross: vz(m), ton: AuswertungText.ton(m),
|
||||
mitte: "± \(Format.zahl(s.aivat?.halb95, stellen: 1)) bb/100 · \(s.haende) Hände",
|
||||
unter: "roh \(vz(s.roh?.mittel)) · netto \(Format.vorzeichen(s.nettoBB, stellen: 0)) bb")
|
||||
}
|
||||
|
||||
public static func vergleichZeile(_ v: FeaturesVergleich) -> String { mitSpanne(v.diff, v.halb95) + " bb/100" }
|
||||
|
||||
/// "MOTOR_EINSATZ nicht gesetzt → 1"
|
||||
public static func wechsel(_ a: FeaturesUnterschied) -> String {
|
||||
"\(a.name) \(a.vorher ?? nichtGesetzt) → \(a.nachher ?? nichtGesetzt)"
|
||||
}
|
||||
|
||||
public static func andersText(_ namen: [String]) -> String {
|
||||
namen.isEmpty ? "Schalter wie davor"
|
||||
: "anders: " + namen.prefix(4).joined(separator: ", ") + (namen.count > 4 ? " +\(namen.count - 4)" : "")
|
||||
}
|
||||
|
||||
public struct SitzungZeileText: Equatable, Sendable {
|
||||
public var kopf: String
|
||||
public var unter: String
|
||||
public var wert: String
|
||||
public var ton: String?
|
||||
}
|
||||
|
||||
public static func sitzungZeile(_ s: FeaturesSitzung, zoneSekunden: Int? = nil) -> SitzungZeileText {
|
||||
SitzungZeileText(
|
||||
kopf: "\(uhrtag(s.von, zoneSekunden: zoneSekunden))–\(uhr(s.bis, zoneSekunden: zoneSekunden)) · \(s.haende) Hände",
|
||||
unter: andersText(s.anders.map(\.name)),
|
||||
wert: mitSpanne(s.aivat?.mittel, s.aivat?.halb95), ton: AuswertungText.ton(s.aivat?.mittel))
|
||||
}
|
||||
|
||||
public static func sitzungFuss(_ s: FeaturesSitzungen) -> String {
|
||||
var t = "Sitzung = Hände mit derselben Schalter-Marke ohne Pause über 60 min, nur Cash, AIVAT (lesen/aivat.py), ±95 %"
|
||||
if s.klein > 0 {
|
||||
t += " · \(s.klein) kleine \(s.klein == 1 ? "Sitzung" : "Sitzungen") unter \(s.mindest.map(String.init) ?? "–") Händen ausgelassen"
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// ---- Wirkung
|
||||
|
||||
public static func wirkungKopf(_ s: FeaturesWirkSitzung?, zoneSekunden: Int? = nil) -> String? {
|
||||
s.map { "diese Sitzung seit \(uhrtag($0.von, zoneSekunden: zoneSekunden)) · \($0.haende) Hände · \(vz($0.aivatBB)) bb" }
|
||||
}
|
||||
|
||||
public static func wirkungFuss(_ r: FeaturesRegeln) -> String {
|
||||
"So wird gerechnet: Eine Hand gehört zu dem Feature, dessen Entscheidungen in ihr das meiste Geld gesetzt haben. "
|
||||
+ "bb sind glücksbereinigt (AIVAT), nur Cash. "
|
||||
+ "Rot = sicher im Minus, oder höchstens 3 Hände tragen mindestens \(Format.zahl(r.klumpenAnteil * 100, stellen: 0)) % eines Verlusts ab \(Format.zahl(r.klumpenBB, stellen: 0)) bb. "
|
||||
+ "Grau = unter \(r.minHaende) Händen oder unauffällig."
|
||||
}
|
||||
|
||||
/// Der Satz, wenn kein Feature zu zeigen ist; nil, wenn es Features gibt oder der Server einen Fehler meldet.
|
||||
public static func wirkungLeer(_ w: FeaturesWirkung?) -> String? {
|
||||
guard let w, w.features.isEmpty, w.fehler == nil else { return nil }
|
||||
return w.hinweis == "keine Cash-Sitzung" ? "Noch keine Cash-Sitzung." : "Noch keine Entscheidung eines Features in dieser Sitzung."
|
||||
}
|
||||
|
||||
public struct WirkZahl: Equatable, Sendable {
|
||||
public var wert: String
|
||||
public var unter: String
|
||||
public var ton: String?
|
||||
}
|
||||
|
||||
/// Rechts im Kopf der Karte: bb der Haende, in denen das Feature das meiste Geld setzte.
|
||||
public static func wirkungZahl(_ f: FeaturesWirkFeature) -> WirkZahl {
|
||||
let n = f.haupt.haende
|
||||
let s = f.haupt.aivat?.summe
|
||||
return WirkZahl(wert: n > 0 ? vz(s) : "–", unter: n > 0 ? "bb · \(n) Hände" : "keine Hand", ton: AuswertungText.ton(s))
|
||||
}
|
||||
|
||||
/// Rot steht offen.
|
||||
public static func standardOffen(_ f: FeaturesWirkFeature) -> Bool { f.ton == "rot" }
|
||||
|
||||
public static func wirkungKacheln(_ f: FeaturesWirkFeature) -> [KennzahlKachel] {
|
||||
let n = f.haupt.haende
|
||||
let s = f.haupt.aivat?.summe
|
||||
let diese = KennzahlKachel(
|
||||
titel: "Diese Sitzung", wert: n > 0 ? "\(vz(s)) bb" : "–", ton: AuswertungText.ton(s),
|
||||
unter: "\(n) Hände · je Hand \(mitSpanne(f.haupt.aivat?.mittel, f.haupt.aivat?.halb95))", hilfe: nil)
|
||||
let vh = f.vorher?.haupt
|
||||
let vs = vh?.aivat?.summe
|
||||
let vorige = KennzahlKachel(
|
||||
titel: "Vorige Sitzung",
|
||||
wert: vh == nil ? "–" : (vh?.haende ?? 0) > 0 ? "\(vz(vs)) bb" : "nicht aktiv",
|
||||
ton: AuswertungText.ton(vs),
|
||||
unter: vh == nil ? "keine vorige Sitzung" : "\(vh?.haende ?? 0) Hände", hilfe: nil)
|
||||
let dd = f.vergleich?.diff
|
||||
let unterschied = KennzahlKachel(
|
||||
titel: "Unterschied je Hand", wert: dd.map { "\(vz($0, 2)) bb" } ?? "–", ton: AuswertungText.ton(dd),
|
||||
unter: f.vergleich.map { $0.urteil == "noch offen" ? "kann Zufall sein" : $0.urteil } ?? "", hilfe: nil)
|
||||
return [diese, vorige, unterschied]
|
||||
}
|
||||
|
||||
public static func beteiligt(_ f: FeaturesWirkFeature) -> String {
|
||||
"Insgesamt beteiligt: \(f.entscheidungen) Entscheidungen in \(f.haende) Händen · \(vz(f.aivat?.summe)) bb bereinigt, \(vz(f.roh?.summe)) bb roh"
|
||||
+ (f.ueberstimmt > 0 ? " · \(f.ueberstimmt)× von einer Regel überstimmt" : "")
|
||||
}
|
||||
|
||||
public static func neuInSitzung(_ w: FeaturesWechsel) -> String {
|
||||
"Neu in dieser Sitzung: \(w.name) \(w.vorher ?? nichtGesetzt) → \(w.nachher ?? nichtGesetzt)"
|
||||
+ (w.kommentar.map { $0.isEmpty ? "" : " · " + $0 } ?? "")
|
||||
}
|
||||
|
||||
// ---- Hand
|
||||
|
||||
private static let strassen = ["PREFLOP": "PF", "FLOP": "F", "TURN": "T", "RIVER": "R"]
|
||||
|
||||
public static func kurzstrasse(_ s: String) -> String { strassen[s] ?? s }
|
||||
|
||||
/// Feature-Kennung -> kurzer Name fuer den Ablauf einer Hand.
|
||||
public static func kurzname(_ id: String) -> String {
|
||||
switch id {
|
||||
case "blueprint": "SHARINGAN"; case "suche_flop": "Flop-Suche"; case "suche_turn_river": "T/R-Suche"
|
||||
case "motor_preis": "Preis-Rückfall"; case "motor_genau": "Motor genau"; case "motor_baum": "Motor"
|
||||
case "nl2_daten": "NL2-Daten"; case "nl2_typ": "Gegnertyp"; case "nl2_einsatz": "Bluff/Wert"; case "nl2_iso": "Iso"
|
||||
case "nl2_raise": "Raise-Bremse"; case "nl2_groesse": "Wertgröße"; case "vertrauen": "Vertrauen"
|
||||
case "splash": "Splash"; case "fold_rundung": "Fold-Rundung"; case "kern": "Kern"
|
||||
default: id
|
||||
}
|
||||
}
|
||||
|
||||
public struct KettenTeil: Equatable, Sendable {
|
||||
public var text: String
|
||||
/// Entschieden vom Feature dieser Karte (farbig), sonst grau.
|
||||
public var eigen: Bool
|
||||
/// Bei fremden Entscheidungen: wer sie entschied.
|
||||
public var wer: String?
|
||||
}
|
||||
|
||||
public struct GrundZeile: Equatable, Sendable {
|
||||
public var text: String
|
||||
public var eigen: Bool
|
||||
}
|
||||
|
||||
public struct HandText: Equatable, Sendable {
|
||||
public var kennung: String
|
||||
public var mitte: String
|
||||
public var ergebnis: String
|
||||
public var ton: String?
|
||||
public var hilfe: String
|
||||
public var kette: [KettenTeil]
|
||||
public var gruende: [GrundZeile]
|
||||
}
|
||||
|
||||
public static func handZeile(_ h: FeaturesHand, feature fid: String, zoneSekunden: Int? = nil) -> HandText {
|
||||
let haupt = h.haupt.contains(fid)
|
||||
let kette = h.alle.map { z -> KettenTeil in
|
||||
let eigen = z.wer.contains(fid)
|
||||
let g = z.groesse.map { " " + groesse($0) } ?? ""
|
||||
return KettenTeil(text: "\(kurzstrasse(z.street)) \(z.aktion)\(g)", eigen: eigen,
|
||||
wer: !eigen && !z.wer.isEmpty ? z.wer.map(kurzname).joined(separator: ", ") : nil)
|
||||
}
|
||||
let gruende = h.alle.map {
|
||||
GrundZeile(text: "\(kurzstrasse($0.street)) \($0.aktion): \($0.grund)", eigen: $0.wer.contains(fid))
|
||||
}
|
||||
return HandText(
|
||||
kennung: h.hand,
|
||||
mitte: uhr(h.t, zoneSekunden: zoneSekunden) + (haupt ? " · hier entschied es das meiste Geld" : " · beteiligt"),
|
||||
ergebnis: "\(vz(h.aivat)) bb", ton: AuswertungText.ton(h.aivat),
|
||||
hilfe: "roh \(vz(h.roh)) bb · \(h.raum ?? "")", kette: kette, gruende: gruende)
|
||||
}
|
||||
|
||||
// ---- Schalter und Programme
|
||||
|
||||
/// Pfade kurz (nur der Dateiname), der Rest hinter dem ersten Komma bleibt; voll im Tipp.
|
||||
public static func wert(_ w: String, pfad: Bool = false) -> String {
|
||||
guard pfad || w.contains(":\\") || w.contains(":/") else { return w }
|
||||
let teile = w.split(separator: ",", maxSplits: 1, omittingEmptySubsequences: false)
|
||||
var name = String(teile.first ?? "")
|
||||
while let l = name.last, l == "\\" || l == "/" { name.removeLast() }
|
||||
if let i = name.lastIndex(where: { $0 == "\\" || $0 == "/" }) { name = "…" + name[i...] }
|
||||
return teile.count > 1 ? name + "," + teile[1] : name
|
||||
}
|
||||
|
||||
/// "22.11. · Grund": das Datum steht nur einmal vorn.
|
||||
public static func grund(datum: String?, kommentar: String?) -> String {
|
||||
var k = kommentar ?? ""
|
||||
if let datum, k.hasPrefix(datum) { k = String(k.dropFirst(datum.count).drop { $0 == " " || $0 == ":" }) }
|
||||
return datum.map { "\($0) · \(k)" } ?? k
|
||||
}
|
||||
|
||||
public static func gruppeWert(_ g: FeaturesGruppe) -> String {
|
||||
let neu = g.schalter.filter(\.neuSeitStart).count
|
||||
return neu > 0 ? "\(g.schalter.count) an · \(neu) neu" : "\(g.schalter.count) an"
|
||||
}
|
||||
|
||||
public static func gruppeHinweis(_ g: FeaturesGruppe) -> String? {
|
||||
g.id == "kern" ? "Spielt nur, wenn der Motor ausfällt (Ante, Splash, Nicht-NLHE, Ausfall)." : nil
|
||||
}
|
||||
|
||||
/// Das Fenster am Schalter: Zeile in der Datei und der Kommentarblock.
|
||||
public static func schalterTipp(_ s: FeaturesSchalter) -> String {
|
||||
"Zeile \(s.zeile.map(String.init) ?? "–")\n" + s.block.filter { !$0.isEmpty }.joined(separator: "\n")
|
||||
}
|
||||
|
||||
public static func exeZustand(_ e: FeaturesExe) -> (ton: String, text: String) {
|
||||
!e.da ? ("rot", "Datei fehlt!") : e.laeuft ? ("gruen", "läuft gerade") : e.an ? ("grau", "liegt bereit") : ("grau", "ausgeschaltet")
|
||||
}
|
||||
|
||||
public static func exesWert(_ exes: [FeaturesExe]) -> String {
|
||||
"\(exes.filter(\.laeuft).count) von \(exes.count) laufen"
|
||||
}
|
||||
|
||||
public static func exeUnter(_ e: FeaturesExe, zoneSekunden: Int? = nil) -> String {
|
||||
(e.datum.map { uhrtag($0, zoneSekunden: zoneSekunden) } ?? "") + " · " + exeZustand(e).text
|
||||
}
|
||||
|
||||
public static func zeilenAus(_ l: [FeaturesEinstellung]) -> [Zeile] {
|
||||
l.map { Zeile(name: $0.name, wert: "= " + wert($0.wert), unter: grund(datum: $0.datum, kommentar: $0.kommentar)) }
|
||||
}
|
||||
|
||||
public static func zeilenRuht(_ l: [FeaturesEinstellung]) -> [Zeile] {
|
||||
l.map { Zeile(name: $0.name, wert: "= " + wert($0.wert), unter: "wirkt nicht: \($0.elter) ist aus") }
|
||||
}
|
||||
|
||||
public static func zeilenLeerUnbekannt(leer: [FeaturesLeerZeile], unbekannt: [FeaturesUnbekannt]) -> [Zeile] {
|
||||
func zeile(_ n: Int?) -> String { "Zeile \(n.map(String.init) ?? "–")" }
|
||||
return leer.map {
|
||||
Zeile(name: $0.name + "=", wert: zeile($0.zeile),
|
||||
unter: $0.gilt.map { "leer überschreibt nicht – es gilt weiter \($0)" } ?? "leer – der Schalter ist nicht gesetzt")
|
||||
} + unbekannt.map {
|
||||
Zeile(name: $0.name, wert: "= " + wert($0.wert), unter: "\(zeile($0.zeile)): kein bekannter Schalter (entscheiden/decide.py) – wirkt nicht")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public enum Hauptknopf: Equatable, Sendable {
|
||||
case unbekannt, notAusLoesen, hoertAuf, aufhoeren, zuschauenBeenden, freigabeFehlt, clientStarten, budgetFehlt
|
||||
case clientNeuStarten, portFehlt // CoinPoker ohne Debug-Port: Tische oeffnen ginge nicht
|
||||
case sammelnStarten, sammelnStoppen // der Zuschauer sammelt Haende (betrieb/sammler.py)
|
||||
case nichtsAn // Cash und Turniere ruhen beide: ein Start saesse nirgends
|
||||
case starten(cash: Bool)
|
||||
|
||||
/// `fensterLesbar`: hat die App (und damit Server und Laeufer, die sie startet) die
|
||||
@@ -33,6 +34,8 @@ public enum Hauptknopf: Equatable, Sendable {
|
||||
if !fensterLesbar { return .freigabeFehlt }
|
||||
if k.client == false { return .clientStarten }
|
||||
if k.clientPort == false { return (k.tischeOffen ?? 0) > 0 ? .portFehlt : .clientNeuStarten }
|
||||
// Cash und Turniere ruhen beide: ein Start saesse nirgends (Owner 30.11.: getrennte Schalter)
|
||||
if wahl.ruht("cash") && (wahl.ruht("turniere") || !wahl.hatTurniere) { return .nichtsAn }
|
||||
if wahl.cash && k.guthaben == nil && wahl.budget == nil { return .budgetFehlt }
|
||||
return .starten(cash: wahl.cash)
|
||||
}
|
||||
@@ -48,7 +51,7 @@ public enum Hauptknopf: Equatable, Sendable {
|
||||
case .starten: ["spielplan_setzen", "laeufer_starten"]
|
||||
case .clientStarten: ["client_starten"]
|
||||
case .clientNeuStarten: ["client_neu_starten"]
|
||||
case .hoertAuf, .freigabeFehlt, .budgetFehlt, .portFehlt, .unbekannt: []
|
||||
case .hoertAuf, .freigabeFehlt, .budgetFehlt, .portFehlt, .nichtsAn, .unbekannt: []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ import Foundation
|
||||
/// `sitzen.live`: Tisch-Chips im Raster, je Tisch eine Kachel, ohne Tisch der Weg zum Spielen, die Suche.
|
||||
public struct LiveTische: Decodable, Equatable, Sendable {
|
||||
public var anzahl = 0
|
||||
/// Tische je Bereich (Schalter Cash / Turniere).
|
||||
public var cashTische = 0
|
||||
public var turnierTische = 0
|
||||
/// Erst ab zwei Tischen (sonst leer); `spalte_nr`/`zeile_nr` ordnen das Raster.
|
||||
public var chips: [LiveChip] = []
|
||||
public var kacheln: [LiveKachelDaten] = []
|
||||
@@ -18,12 +21,15 @@ public struct LiveTische: Decodable, Equatable, Sendable {
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case anzahl, chips, kacheln, bereit, schliessenFrage = "schliessen_frage", such
|
||||
case cashTische = "cash_tische", turnierTische = "turnier_tische"
|
||||
case suchTitel = "such_titel", suchText = "such_text"
|
||||
}
|
||||
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
anzahl = c.zahl(.anzahl).map { Int($0) } ?? 0
|
||||
cashTische = c.zahl(.cashTische).map { Int($0) } ?? 0
|
||||
turnierTische = c.zahl(.turnierTische).map { Int($0) } ?? 0
|
||||
chips = c.objekte(.chips); kacheln = c.objekte(.kacheln)
|
||||
bereit = try? c.decodeIfPresent(LiveBereit.self, forKey: .bereit)
|
||||
schliessenFrage = c.text(.schliessenFrage)
|
||||
@@ -362,3 +368,33 @@ public struct GeldAnzeige: Decodable, Equatable, Sendable {
|
||||
hinweis = c.text(.hinweis) ?? ""; skalen = c.objekte(.skalen); regeln = c.liste(.regeln)
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Minitisch (Rasterkachel als kleiner Tisch, wie WinUI LiveTeil.Minitisch) ----
|
||||
|
||||
extension LiveKachelDaten {
|
||||
/// Die letzte eigene Aktion dieser Hand aus den Plaetzen ("Fold", "Raise 0,06", ...).
|
||||
public var ichAktion: String { sitze.first(where: \.ich)?.aktion ?? "" }
|
||||
/// Nach dem Fold sind die eigenen Karten blass.
|
||||
public var ichRaus: Bool { ichAktion.hasPrefix("Fold") }
|
||||
}
|
||||
|
||||
public enum LiveAktion {
|
||||
public static func ton(_ aktion: String) -> String {
|
||||
if aktion.hasPrefix("Fold") { return "grau" }
|
||||
if aktion.hasPrefix("Call") || aktion.hasPrefix("Check") { return "gruen" }
|
||||
if ["Raise", "Bet", "All"].contains(where: aktion.hasPrefix) { return "orange" }
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
extension Zug {
|
||||
/// Rest der Frist als Anteil 0...1 (ohne Frist: 1); nil, wenn keine Uhr laeuft.
|
||||
public func restAnteil(jetzt: Double) -> Double? {
|
||||
guard offen, let bis else { return nil }
|
||||
let rest = max(0, bis - jetzt)
|
||||
let ganz = fristS.flatMap { $0 > 0 ? $0 : nil } ?? max(rest, 1)
|
||||
return min(1, max(0, rest / ganz))
|
||||
}
|
||||
|
||||
public static func uhrTon(_ anteil: Double) -> String { anteil < 0.25 ? "rot" : anteil < 0.5 ? "orange" : "gruen" }
|
||||
}
|
||||
|
||||
@@ -74,6 +74,18 @@ public struct Spielplan: Equatable, Sendable, Decodable {
|
||||
|
||||
public var cash: Bool { modus == .echt }
|
||||
|
||||
/// Was im Echtgeld gerade ruht: "cash" und/oder "turniere" (betrieb/spielplan.ruht). Die Stufenwahl bleibt
|
||||
/// stehen; der Laeufer liest es live (Owner 30.11.: Cash und Turniere getrennt steuern).
|
||||
public var ruhend: Set<String> = []
|
||||
public static let ruhendeArten: Set<String> = ["cash", "turniere"]
|
||||
public func ruht(_ art: String) -> Bool { cash && ruhend.contains(art) }
|
||||
public mutating func umschalten(_ art: String) {
|
||||
guard Self.ruhendeArten.contains(art) else { return }
|
||||
if ruhend.remove(art) == nil { ruhend.insert(art) }
|
||||
}
|
||||
/// Stehen Turniere in der Vorrang-Reihe (negative Schluessel, betrieb/stufenwahl.TURNIERE)?
|
||||
public var hatTurniere: Bool { stufen.contains { $0 < 0 } }
|
||||
|
||||
private var stufenSchluessel: String { cash ? "cash" : "uebung" }
|
||||
|
||||
/// Die Stufen des jetzigen Modus nach Vorrang.
|
||||
@@ -156,7 +168,7 @@ public struct Spielplan: Equatable, Sendable, Decodable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case modus, tische, budget, ziel, reihenfolge, zeiger, lehrer, tischform, tischeBis = "tische_bis", zeitplan, geld, formate
|
||||
case stufen, stufenTische = "stufen_tische"
|
||||
case turnier
|
||||
case turnier, aus
|
||||
case formateListe = "formate_liste"
|
||||
}
|
||||
|
||||
@@ -186,6 +198,7 @@ public struct Spielplan: Equatable, Sendable, Decodable {
|
||||
}
|
||||
}
|
||||
if let t = c.text(.tischform).flatMap(Tischform.init(rawValue:)) { tischform = t }
|
||||
ruhend = Set(c.liste(.aus)).intersection(Self.ruhendeArten)
|
||||
zeitplan = ((try? c.decodeIfPresent(Zeitplan.self, forKey: .zeitplan)) ?? nil) ?? .ohne
|
||||
geld = ((try? c.decodeIfPresent(Geldplan.self, forKey: .geld)) ?? nil) ?? Geldplan()
|
||||
turnier = ((try? c.decodeIfPresent(Turnierplan.self, forKey: .turnier)) ?? nil) ?? Turnierplan()
|
||||
@@ -244,6 +257,7 @@ public struct Spielplan: Equatable, Sendable, Decodable {
|
||||
Dictionary(uniqueKeysWithValues: je.map { (Format.roh($0.key), $0.value) })
|
||||
}
|
||||
if turnier.gesetzt { d["turnier"] = turnier.daten }
|
||||
d["aus"] = ruhend.sorted() // immer, auch leer: leer heisst beides an
|
||||
d["tischform"] = tischform.rawValue // immer mitschicken (robuster Round-Trip, wie geld.reserve)
|
||||
if zeitplan.aktiv { d["zeitplan"] = zeitplan.daten }
|
||||
if geld != Geldplan() { d["geld"] = geld.daten }
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import CockpitKern
|
||||
import Testing
|
||||
|
||||
// Cash und Turniere getrennt an/aus (Owner 30.11., wie WinUI 9e7bee20): Spielplan "aus" = ["cash"|"turniere"],
|
||||
// der Laeufer liest es live (betrieb/spielplan.reihe_von). Die Stufenwahl bleibt dabei stehen.
|
||||
|
||||
private func kopf(_ json: String) -> Kopf? {
|
||||
var a = Ansicht()
|
||||
_ = a.anwenden(#"{"typ":"ansicht","teile":{"kopf":"# + json + "}}")
|
||||
return a.kopf
|
||||
}
|
||||
|
||||
private func echt(_ stufen: [Double] = [], aus: [String] = []) -> Spielplan {
|
||||
var p = Spielplan(modus: .echt, tische: 2, budget: 250)
|
||||
p.stufenSetzen(stufen)
|
||||
for a in aus { p.umschalten(a) }
|
||||
return p
|
||||
}
|
||||
|
||||
@Suite("Bereiche: Cash und Turniere ruhen getrennt")
|
||||
struct BereicheSpec {
|
||||
@Test("umschalten legt eine Art still und wieder an; ruhen gibt es nur im Echtgeld")
|
||||
func ruhen() {
|
||||
var p = echt()
|
||||
#expect(!p.ruht("cash"))
|
||||
p.umschalten("cash")
|
||||
#expect(p.ruht("cash") && !p.ruht("turniere"))
|
||||
p.umschalten("cash")
|
||||
#expect(!p.ruht("cash"))
|
||||
|
||||
var u = Spielplan(modus: .uebung, tische: 2, budget: nil)
|
||||
u.umschalten("cash")
|
||||
#expect(!u.ruht("cash"))
|
||||
}
|
||||
|
||||
@Test("Turniere stehen in der Reihe, wenn ein negativer Schlüssel drin ist")
|
||||
func hatTurniere() {
|
||||
#expect(!echt([0.02, 0.05]).hatTurniere)
|
||||
#expect(echt([0.02, -1]).hatTurniere)
|
||||
}
|
||||
|
||||
@Test("geht immer mit, auch leer (leer heißt beides an), sortiert")
|
||||
func daten() {
|
||||
#expect(echt().datenText.contains(#""aus":[]"#))
|
||||
#expect(echt(aus: ["turniere", "cash"]).datenText.contains(#""aus":["cash","turniere"]"#))
|
||||
}
|
||||
|
||||
@Test("gelesen: nur cash und turniere zählen")
|
||||
func gelesen() {
|
||||
let k = kopf(#"{"spielplan":{"modus":"cash","tische":2,"aus":["turniere","quatsch"]}}"#)
|
||||
#expect(k?.spielplan?.ruht("turniere") == true)
|
||||
#expect(k?.spielplan?.ruht("cash") == false)
|
||||
#expect(kopf(#"{"spielplan":{"modus":"cash","tische":2,"aus":"cash"}}"#)?.spielplan?.ruht("cash") == false)
|
||||
}
|
||||
|
||||
@Test("ruhen beide (oder Cash ohne Turniere in der Reihe), startet der Knopf nichts")
|
||||
func nichtsAn() {
|
||||
let k = kopf(#"{"laeuft":false,"guthaben":100}"#)
|
||||
#expect(Hauptknopf.waehlen(k, wahl: echt([0.02, -1], aus: ["cash", "turniere"])) == .nichtsAn)
|
||||
#expect(Hauptknopf.waehlen(k, wahl: echt([0.02], aus: ["cash"])) == .nichtsAn)
|
||||
#expect(Hauptknopf.waehlen(k, wahl: echt([0.02, -1], aus: ["cash"])) == .starten(cash: true))
|
||||
#expect(Hauptknopf.waehlen(k, wahl: echt([0.02], aus: ["turniere"])) == .starten(cash: true))
|
||||
#expect(Hauptknopf.nichtsAn.schritte.isEmpty)
|
||||
// Client-Fragen gehen vor
|
||||
#expect(Hauptknopf.waehlen(kopf(#"{"laeuft":false,"client":false}"#), wahl: echt([0.02], aus: ["cash"])) == .clientStarten)
|
||||
}
|
||||
|
||||
@Test("Cash: an mit Stufen und Tischen, ruhend mit auslaufenden Tischen")
|
||||
func cashText() {
|
||||
#expect(Bereiche.cash(echt([0.02, 0.05, 0.1, 0.25]), tische: 0).unter == "NL2, NL5, NL10")
|
||||
#expect(Bereiche.cash(echt(), tische: 3).unter == "3 Tische · automatisch")
|
||||
#expect(Bereiche.cash(echt([0.02]), tische: 1).unter == "1 Tisch · NL2")
|
||||
let ruht = Bereiche.cash(echt([0.02], aus: ["cash"]), tische: 2)
|
||||
#expect(!ruht.an && ruht.unter == "ruht · 2 Tische laufen aus")
|
||||
#expect(Bereiche.cash(echt(aus: ["cash"]), tische: 0).unter == "ruht")
|
||||
}
|
||||
|
||||
@Test("Turniere: ohne Turnier in der Reihe nicht bedienbar; sonst läuft, angemeldet, ruht")
|
||||
func turnierText() {
|
||||
let ohne = Bereiche.turniere(echt([0.02]), tische: 0, angemeldet: 0)
|
||||
#expect(!ohne.an && !ohne.bedienbar && ohne.unter == "keine in den Stufen")
|
||||
#expect(Bereiche.turniere(echt([-1]), tische: 0, angemeldet: 0).unter == "meldet an")
|
||||
#expect(Bereiche.turniere(echt([-1]), tische: 2, angemeldet: 1).unter == "2 läuft · 1 angemeldet")
|
||||
#expect(Bereiche.turniere(echt([-1], aus: ["turniere"]), tische: 1, angemeldet: 0).unter == "ruht · 1 Tisch spielt zu Ende")
|
||||
#expect(Bereiche.turniere(echt([-1], aus: ["turniere"]), tische: 0, angemeldet: 0).unter == "ruht · meldet nichts an")
|
||||
}
|
||||
|
||||
@Test("Tische je Bereich kommen fertig vom Server")
|
||||
func liveZahlen() {
|
||||
var a = Ansicht()
|
||||
_ = a.anwenden(#"{"typ":"ansicht","teile":{"sitzen":{"live":{"anzahl":3,"cash_tische":2,"turnier_tische":"1"}}}}"#)
|
||||
#expect(a.sitzen?.live?.cashTische == 2 && a.sitzen?.live?.turnierTische == 1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,393 @@
|
||||
import CockpitKern
|
||||
import Testing
|
||||
|
||||
// Der Reiter Features (GET /api/features, sicht/features.py + featurewirkung.py): nachsichtig gelesen,
|
||||
// Texte wie winui/Seiten/FeaturesSeite.cs. Beispiel: Fixtures/features.json (echte Form, erfundene Zahlen).
|
||||
// Zeiten in UTC (zoneSekunden: 0), damit die Pruefung nicht an der Ortszeit haengt.
|
||||
|
||||
private func features(_ json: String? = Hilfen.fixture("features")) -> Features? {
|
||||
json.flatMap { Features.lesen(text: $0) }
|
||||
}
|
||||
|
||||
private let utc = 0
|
||||
|
||||
@Suite("Features: Nutzlast lesen")
|
||||
struct FeaturesLesenSpec {
|
||||
@Test("das Beispiel kommt vollstaendig an")
|
||||
func beispiel() {
|
||||
let f = features()
|
||||
#expect(f?.hatGruppen == true)
|
||||
#expect(f?.an == 5)
|
||||
#expect(f?.laeufer.seit == 1796041000)
|
||||
#expect(f?.laeufer.geaendert == 2)
|
||||
#expect(f?.laeufer.weg.first?.name == "ALT_SCHALTER")
|
||||
#expect(f?.laeufer.weg.first?.jetzt == nil)
|
||||
#expect(f?.gruppen.map(\.id) == ["motor", "laeufer", "kern"])
|
||||
#expect(f?.gruppen.first?.schalter.count == 2)
|
||||
#expect(f?.gruppen.first?.schalter.last?.neuSeitStart == true)
|
||||
#expect(f?.gruppen.last?.schalter.first?.sharingan == true)
|
||||
#expect(f?.gruppen.last?.schalter.first?.neuSeitStart == false) // null
|
||||
#expect(f?.aus.count == 1)
|
||||
#expect(f?.ruht.first?.elter == "MOTOR_NL2")
|
||||
#expect(f?.unbekannt.first?.zeile == 77)
|
||||
#expect(f?.leerZeilen.map(\.name) == ["VORWISSEN", "LEER2"])
|
||||
#expect(f?.leerZeilen.last?.gilt == nil)
|
||||
#expect(f?.exes.count == 2)
|
||||
#expect(f?.sitzungen?.liste.count == 3)
|
||||
#expect(f?.sitzungen?.vergleich?.urteil == "besser")
|
||||
#expect(f?.wirkung?.features.count == 2)
|
||||
#expect(f?.wirkung?.features.first?.verlierer.first?.alle.count == 3)
|
||||
#expect(f?.wirkung?.features.first?.verlierer.first?.alle[1].wer == ["nl2_daten"])
|
||||
#expect(f?.wirkung?.features.first?.zustand == ["MOTOR_NL2": "1"])
|
||||
#expect(f?.wirkung?.regeln.minHaende == 10)
|
||||
}
|
||||
|
||||
@Test("der Server rechnet noch: leer ist ein Text, nicht die Liste der leeren Zeilen")
|
||||
func rechnet() {
|
||||
let f = features(#"{"rechnet":true,"leer":"wird gelesen","stand":5}"#)
|
||||
#expect(f?.rechnet == true)
|
||||
#expect(f?.leerText == "wird gelesen")
|
||||
#expect(f?.hatGruppen == false)
|
||||
#expect(f?.leerZeilen.isEmpty == true)
|
||||
#expect(f?.stand == 5)
|
||||
}
|
||||
|
||||
@Test("ein Feld mit falschem Typ ist unbekannt, ein kaputter Eintrag faellt weg")
|
||||
func nachsichtig() {
|
||||
let f = features(#"{"gruppen":[{"id":"a","titel":"A","schalter":[{"name":"X","wert":"1"},7,{"name":"Y","wert":2}]},"nein"],"an":"56","laeufer":[1],"exes":"keine","wirkung":5}"#)
|
||||
#expect(f?.hatGruppen == true)
|
||||
#expect(f?.an == 56)
|
||||
#expect(f?.gruppen.count == 1)
|
||||
#expect(f?.gruppen.first?.schalter.map(\.wert) == ["1", "2"])
|
||||
#expect(f?.laeufer.seit == nil)
|
||||
#expect(f?.exes.isEmpty == true)
|
||||
#expect(f?.wirkung == nil)
|
||||
}
|
||||
|
||||
@Test("Leerseite: rechnet noch, Server meldet leer, nie erreicht")
|
||||
func leerseite() {
|
||||
#expect(FeaturesText.leerSeite(features(#"{"rechnet":true,"leer":"liest"}"#)) == FeaturesText.LeerSeite(titel: "Wird gelesen", text: "liest"))
|
||||
#expect(FeaturesText.leerSeite(features("{}")) == FeaturesText.LeerSeite(titel: "Keine Features", text: "Verbindet mit dem Cockpit-Server …"))
|
||||
#expect(FeaturesText.leerSeite(nil).text == "Server ohne /api/features (älterer Stand?) oder nicht erreicht.")
|
||||
}
|
||||
|
||||
@Test("ein Objekt ohne alles ist leer, kein Objekt ist nil")
|
||||
func leer() {
|
||||
let f = features("{}")
|
||||
#expect(f?.hatGruppen == false)
|
||||
#expect(f?.rechnet == false)
|
||||
#expect(f?.gruppen.isEmpty == true)
|
||||
#expect(features("[1,2]") == nil)
|
||||
#expect(features("kein json") == nil)
|
||||
}
|
||||
|
||||
@Test("fehler steht neben den Daten")
|
||||
func fehler() {
|
||||
#expect(features(#"{"gruppen":[],"fehler":"Lesen scheiterte"}"#)?.fehler == "Lesen scheiterte")
|
||||
}
|
||||
}
|
||||
|
||||
@Suite("Features: Kopf, Lage in einem Blick")
|
||||
struct FeaturesKopfSpec {
|
||||
@Test("Laeufer spielt: Titel, Zeile, Abzeichen in der Reihenfolge der WinUI-Seite")
|
||||
func spielt() throws {
|
||||
let k = FeaturesText.kopf(try #require(features()), zoneSekunden: utc)
|
||||
#expect(k.laeuft == true)
|
||||
#expect(k.titel == "Läufer spielt seit 30.11. 12:16")
|
||||
#expect(k.unter == "mit diesen Schaltern")
|
||||
#expect(k.abzeichen.map(\.text) == ["5 Features an", "1 Feature ansehen", "2 Änderungen warten auf Neustart", "1 Programm fehlt"])
|
||||
#expect(k.abzeichen.map(\.ton) == ["blau", "rot", "orange", "rot"])
|
||||
#expect(k.geaendert == ["MOTOR_SPIELT = 1", "TISCHWAHL = 1", "ALT_SCHALTER: 1 → entfernt (wieder Standard)"])
|
||||
}
|
||||
|
||||
@Test("Laeufer steht: letzte Hand und Hinweis, ohne Aenderung grau")
|
||||
func steht() throws {
|
||||
let j = try #require(Hilfen.fixture("features"))
|
||||
.replacingOccurrences(of: "\"seit\": 1796041000.0", with: "\"seit\": null")
|
||||
.replacingOccurrences(of: "\"geaendert\": 2", with: "\"geaendert\": 0")
|
||||
let k = FeaturesText.kopf(try #require(features(j)), zoneSekunden: utc)
|
||||
#expect(k.laeuft == false)
|
||||
#expect(k.titel == "Läufer steht")
|
||||
#expect(k.unter == "letzte Hand 30.11. 13:40 · die Schalter gelten beim nächsten Start")
|
||||
#expect(k.abzeichen.contains { $0.text == "Schalter wie im letzten Lauf" && $0.ton == "grau" })
|
||||
#expect(k.abzeichen.contains { $0.text.contains("Änderung") } == false)
|
||||
}
|
||||
|
||||
@Test("ohne Marke, eine Aenderung, mehrere Programme fehlen, Features bringen Geld")
|
||||
func raender() throws {
|
||||
let f = try #require(features(#"""
|
||||
{"gruppen":[],"an":1,"laeufer":{"geaendert":1},
|
||||
"exes":[{"an":true,"da":false},{"an":true,"da":false},{"an":false,"da":false}],
|
||||
"wirkung":{"features":[{"id":"a","ton":"gruen"},{"id":"b","ton":"gruen"},{"id":"c","ton":"rot"},{"id":"d","ton":"rot"}]}}
|
||||
"""#))
|
||||
let k = FeaturesText.kopf(f, zoneSekunden: utc)
|
||||
#expect(k.titel == "Läufer steht")
|
||||
#expect(k.unter == "noch keine Hand mit Schalter-Marke")
|
||||
#expect(k.abzeichen.map(\.text) == ["1 Feature an", "2 Features ansehen", "2 bringen Geld",
|
||||
"1 Änderung wartet auf Neustart", "2 Programme fehlen"])
|
||||
}
|
||||
|
||||
@Test("Laeufer spielt ohne Aenderung: Schalter wie beim Start")
|
||||
func wieBeimStart() throws {
|
||||
let k = FeaturesText.kopf(try #require(features(#"{"gruppen":[],"laeufer":{"seit":1796041000}}"#)), zoneSekunden: utc)
|
||||
#expect(k.abzeichen.last?.text == "Schalter wie beim Start")
|
||||
}
|
||||
}
|
||||
|
||||
@Suite("Features: Sitzung gegen Sitzung")
|
||||
struct FeaturesSitzungSpec {
|
||||
@Test("Spanne: Wert mit Vorzeichen, ±Halbbreite, ohne Wert Strich")
|
||||
func spanne() {
|
||||
#expect(FeaturesText.mitSpanne(12.5, 4.0) == "+12,5 ±4")
|
||||
#expect(FeaturesText.mitSpanne(-3.25, 5.04) == "−3,3 ±5")
|
||||
#expect(FeaturesText.mitSpanne(0.0, nil) == "0,0")
|
||||
#expect(FeaturesText.mitSpanne(2, nil) == "+2,0")
|
||||
#expect(FeaturesText.mitSpanne(nil, 3) == "–")
|
||||
}
|
||||
|
||||
@Test("Urteil: Ton und Satz")
|
||||
func urteil() {
|
||||
#expect(FeaturesText.urteilTon("besser") == "gruen")
|
||||
#expect(FeaturesText.urteilTon("schlechter") == "rot")
|
||||
#expect(FeaturesText.urteilTon("noch offen") == "gelb")
|
||||
#expect(FeaturesText.urteilSatz("besser") == "Die letzte Sitzung war besser als die vorige – und das ist kein Zufall mehr.")
|
||||
#expect(FeaturesText.urteilSatz("schlechter") == "Die letzte Sitzung war schlechter als die vorige – und das ist kein Zufall mehr.")
|
||||
#expect(FeaturesText.urteilSatz("noch offen") == "Noch kein Urteil: der Unterschied kann Zufall sein. Mehr Hände abwarten.")
|
||||
}
|
||||
|
||||
@Test("Kachel der letzten Sitzung")
|
||||
func kachel() throws {
|
||||
let s = try #require(features()?.sitzungen)
|
||||
let k = FeaturesText.sitzungKachel("Letzte", s.liste[0], zoneSekunden: utc)
|
||||
#expect(k.kopf == "Letzte · 30.11. 12:00–13:40")
|
||||
#expect(k.gross == "+12,5")
|
||||
#expect(k.ton == "gruen")
|
||||
#expect(k.mitte == "± 4 bb/100 · 80 Hände")
|
||||
#expect(k.unter == "roh +12,5 · netto +10 bb")
|
||||
#expect(FeaturesText.sitzungKachel("Vorige", s.liste[1], zoneSekunden: utc).ton == "rot")
|
||||
}
|
||||
|
||||
@Test("Vergleich: Zeile und Wechsel der Schalter")
|
||||
func vergleich() throws {
|
||||
let v = try #require(features()?.sitzungen?.vergleich)
|
||||
#expect(FeaturesText.vergleichZeile(v) == "+15,8 ±6,4 bb/100")
|
||||
#expect(FeaturesText.wechsel(try #require(v.anders.first)) == "MOTOR_EINSATZ nicht gesetzt → 1")
|
||||
}
|
||||
|
||||
@Test("fruehere Sitzung: Zeit, Haende, wer anders war, Ergebnis")
|
||||
func zeile() throws {
|
||||
let s = try #require(features()?.sitzungen)
|
||||
let z = FeaturesText.sitzungZeile(s.liste[2], zoneSekunden: utc)
|
||||
#expect(z.kopf == "28.11. 21:06–22:46 · 60 Hände")
|
||||
#expect(z.unter == "Schalter wie davor")
|
||||
#expect(z.wert == "+1,0 ±6")
|
||||
#expect(FeaturesText.sitzungZeile(s.liste[0], zoneSekunden: utc).unter == "anders: MOTOR_EINSATZ")
|
||||
}
|
||||
|
||||
@Test("anders: nur vier Namen, der Rest als +n")
|
||||
func andersGekuerzt() {
|
||||
#expect(FeaturesText.andersText(["A", "B", "C", "D", "E", "F"]) == "anders: A, B, C, D +2")
|
||||
#expect(FeaturesText.andersText([]) == "Schalter wie davor")
|
||||
}
|
||||
|
||||
@Test("Fuss: Erklaerung, mit Zahl der ausgelassenen kleinen Sitzungen")
|
||||
func fuss() throws {
|
||||
let s = try #require(features()?.sitzungen)
|
||||
#expect(FeaturesText.sitzungFuss(s) == "Sitzung = Hände mit derselben Schalter-Marke ohne Pause über 60 min, nur Cash, AIVAT (lesen/aivat.py), ±95 % · 2 kleine Sitzungen unter 50 Händen ausgelassen")
|
||||
var eine = s; eine.klein = 1
|
||||
#expect(FeaturesText.sitzungFuss(eine).hasSuffix("· 1 kleine Sitzung unter 50 Händen ausgelassen"))
|
||||
var keine = s; keine.klein = 0
|
||||
#expect(FeaturesText.sitzungFuss(keine).hasSuffix("±95 %"))
|
||||
}
|
||||
}
|
||||
|
||||
@Suite("Features: Wirkung je Feature")
|
||||
struct FeaturesWirkungSpec {
|
||||
private func wirkung() -> FeaturesWirkung? { features()?.wirkung }
|
||||
|
||||
@Test("Kopf rechts: Zahl der Haende, in denen das Feature das meiste Geld setzte")
|
||||
func kopfZahl() throws {
|
||||
let w = try #require(wirkung())
|
||||
let z = FeaturesText.wirkungZahl(w.features[0])
|
||||
#expect(z.wert == "−31,0")
|
||||
#expect(z.unter == "bb · 10 Hände")
|
||||
#expect(z.ton == "rot")
|
||||
let leer = FeaturesText.wirkungZahl(w.features[1])
|
||||
#expect(leer.wert == "–")
|
||||
#expect(leer.unter == "keine Hand")
|
||||
#expect(leer.ton == nil)
|
||||
}
|
||||
|
||||
@Test("rot steht offen, grau zu")
|
||||
func offen() throws {
|
||||
let w = try #require(wirkung())
|
||||
#expect(FeaturesText.standardOffen(w.features[0]) == true)
|
||||
#expect(FeaturesText.standardOffen(w.features[1]) == false)
|
||||
}
|
||||
|
||||
@Test("drei Kacheln: diese Sitzung, vorige, Unterschied je Hand")
|
||||
func kacheln() throws {
|
||||
let k = FeaturesText.wirkungKacheln(try #require(wirkung()).features[0])
|
||||
#expect(k.map(\.titel) == ["Diese Sitzung", "Vorige Sitzung", "Unterschied je Hand"])
|
||||
#expect(k.map(\.wert) == ["−31,0 bb", "+2,0 bb", "−3,10 bb"])
|
||||
#expect(k[0].unter == "10 Hände · je Hand −3,1 ±5,5")
|
||||
#expect(k[1].unter == "20 Hände")
|
||||
#expect(k[2].unter == "schlechter")
|
||||
#expect(k.map(\.ton) == ["rot", "gruen", "rot"])
|
||||
}
|
||||
|
||||
@Test("ohne Haende und ohne vorige Sitzung: Striche")
|
||||
func kachelnLeer() throws {
|
||||
let k = FeaturesText.wirkungKacheln(try #require(wirkung()).features[1])
|
||||
#expect(k.map(\.wert) == ["–", "–", "–"])
|
||||
#expect(k[1].unter == "keine vorige Sitzung")
|
||||
#expect(k[2].unter == "")
|
||||
}
|
||||
|
||||
@Test("Unterschied noch offen heisst: kann Zufall sein")
|
||||
func zufall() throws {
|
||||
var f = try #require(wirkung()).features[0]
|
||||
f.vergleich?.urteil = "noch offen"
|
||||
#expect(FeaturesText.wirkungKacheln(f)[2].unter == "kann Zufall sein")
|
||||
}
|
||||
|
||||
@Test("vorige Sitzung ohne Haende des Features: nicht aktiv")
|
||||
func nichtAktiv() throws {
|
||||
var f = try #require(wirkung()).features[0]
|
||||
f.vorher?.haupt.haende = 0
|
||||
#expect(FeaturesText.wirkungKacheln(f)[1].wert == "nicht aktiv")
|
||||
}
|
||||
|
||||
@Test("beteiligt: Entscheidungen, Haende, bereinigt und roh, ueberstimmt")
|
||||
func beteiligt() throws {
|
||||
let w = try #require(wirkung())
|
||||
#expect(FeaturesText.beteiligt(w.features[0]) == "Insgesamt beteiligt: 14 Entscheidungen in 12 Händen · −31,0 bb bereinigt, −35,5 bb roh · 2× von einer Regel überstimmt")
|
||||
var f = w.features[0]; f.ueberstimmt = 0
|
||||
#expect(FeaturesText.beteiligt(f).hasSuffix("bb roh"))
|
||||
}
|
||||
|
||||
@Test("neuer Schalter dieser Sitzung, mit Kommentar")
|
||||
func wechsel() throws {
|
||||
let f = try #require(wirkung()).features[0]
|
||||
#expect(FeaturesText.neuInSitzung(f.wechsel[0]) == "Neu in dieser Sitzung: MOTOR_NL2 nicht gesetzt → 1 · 30.11.: neu an")
|
||||
}
|
||||
|
||||
@Test("Kopf und Fuss der Karte")
|
||||
func kopfFuss() throws {
|
||||
let w = try #require(wirkung())
|
||||
#expect(FeaturesText.wirkungKopf(w.sitzung, zoneSekunden: utc) == "diese Sitzung seit 30.11. 12:00 · 80 Hände · +10,0 bb")
|
||||
#expect(FeaturesText.wirkungKopf(nil, zoneSekunden: utc) == nil)
|
||||
#expect(FeaturesText.wirkungFuss(w.regeln) == "So wird gerechnet: Eine Hand gehört zu dem Feature, dessen Entscheidungen in ihr das meiste Geld gesetzt haben. bb sind glücksbereinigt (AIVAT), nur Cash. Rot = sicher im Minus, oder höchstens 3 Hände tragen mindestens 50 % eines Verlusts ab 15 bb. Grau = unter 10 Händen oder unauffällig.")
|
||||
}
|
||||
|
||||
@Test("leere Wirkung: Hinweis oder Fehler")
|
||||
func leerHinweis() {
|
||||
#expect(FeaturesText.wirkungLeer(features(#"{"gruppen":[],"wirkung":{"features":[],"hinweis":"keine Cash-Sitzung"}}"#)?.wirkung) == "Noch keine Cash-Sitzung.")
|
||||
#expect(FeaturesText.wirkungLeer(features(#"{"gruppen":[],"wirkung":{"features":[]}}"#)?.wirkung) == "Noch keine Entscheidung eines Features in dieser Sitzung.")
|
||||
#expect(FeaturesText.wirkungLeer(features(#"{"gruppen":[],"wirkung":{"features":[],"fehler":"kaputt"}}"#)?.wirkung) == nil)
|
||||
#expect(features(#"{"gruppen":[],"wirkung":{"features":[],"fehler":"kaputt"}}"#)?.wirkung?.fehler == "kaputt")
|
||||
}
|
||||
|
||||
@Test("Hand: Kopfzeile, Kette der Entscheidungen, Gruende")
|
||||
func hand() throws {
|
||||
let h = try #require(wirkung()).features[0].verlierer[0]
|
||||
let z = FeaturesText.handZeile(h, feature: "nl2_daten", zoneSekunden: utc)
|
||||
#expect(z.kennung == "h-100")
|
||||
#expect(z.mitte == "12:08 · hier entschied es das meiste Geld")
|
||||
#expect(z.ergebnis == "−22,5 bb")
|
||||
#expect(z.ton == "rot")
|
||||
#expect(z.hilfe == "roh −20,0 bb · A")
|
||||
#expect(z.kette.map(\.text) == ["PF RAISE 2.5", "F CALL", "T FOLD"])
|
||||
#expect(z.kette.map(\.eigen) == [false, true, false])
|
||||
#expect(z.kette.map(\.wer) == ["SHARINGAN", nil, "Preis-Rückfall, Gegnertyp"])
|
||||
#expect(z.gruende.map(\.text) == ["PF RAISE: SHARINGAN Blueprint", "F CALL: NL2-Daten: Call", "T FOLD: Preis"])
|
||||
#expect(z.gruende.map(\.eigen) == [false, true, false])
|
||||
let g = FeaturesText.handZeile(h, feature: "blueprint", zoneSekunden: utc)
|
||||
#expect(g.mitte == "12:08 · beteiligt")
|
||||
}
|
||||
|
||||
@Test("Strassenkuerzel, Groesse ohne Nachkommanull, Namen der Features")
|
||||
func kleinteile() {
|
||||
#expect(FeaturesText.kurzstrasse("PREFLOP") == "PF")
|
||||
#expect(FeaturesText.kurzstrasse("RIVER") == "R")
|
||||
#expect(FeaturesText.kurzstrasse("SHOWDOWN") == "SHOWDOWN")
|
||||
#expect(FeaturesText.groesse(0.125) == "0.125")
|
||||
#expect(FeaturesText.groesse(3) == "3")
|
||||
#expect(FeaturesText.groesse(2.5) == "2.5")
|
||||
#expect(FeaturesText.kurzname("blueprint") == "SHARINGAN")
|
||||
#expect(FeaturesText.kurzname("nl2_iso") == "Iso")
|
||||
#expect(FeaturesText.kurzname("neu_unbekannt") == "neu_unbekannt")
|
||||
}
|
||||
}
|
||||
|
||||
@Suite("Features: Schalter, Programme, Details")
|
||||
struct FeaturesDetailsSpec {
|
||||
@Test("Wert: Pfade nur mit Dateiname, Rest hinter dem Komma bleibt, sonst unveraendert")
|
||||
func wert() {
|
||||
#expect(FeaturesText.wert(#"C:\Users\m\v.json.gz"#, pfad: true) == #"…\v.json.gz"#)
|
||||
#expect(FeaturesText.wert(#"C:\Users\m\v.json.gz,5"#, pfad: false) == #"…\v.json.gz,5"#) // ":\" verraet den Pfad
|
||||
#expect(FeaturesText.wert("/a/b/c/", pfad: true) == "…/c")
|
||||
#expect(FeaturesText.wert("x:/y/z") == "…/z")
|
||||
#expect(FeaturesText.wert("name", pfad: true) == "name")
|
||||
#expect(FeaturesText.wert("raiseToBet,reraiseToRaise") == "raiseToBet,reraiseToRaise")
|
||||
#expect(FeaturesText.wert("1") == "1")
|
||||
}
|
||||
|
||||
@Test("Grund: Datum vorn, der Kommentar ohne doppeltes Datum")
|
||||
func grund() {
|
||||
#expect(FeaturesText.grund(datum: "22.11.", kommentar: "22.11. Owner: so") == "22.11. · Owner: so")
|
||||
#expect(FeaturesText.grund(datum: "22.11.", kommentar: "22.11.: so") == "22.11. · so")
|
||||
#expect(FeaturesText.grund(datum: "22.11.", kommentar: "anders") == "22.11. · anders")
|
||||
#expect(FeaturesText.grund(datum: nil, kommentar: "nur Text") == "nur Text")
|
||||
#expect(FeaturesText.grund(datum: nil, kommentar: nil) == "")
|
||||
}
|
||||
|
||||
@Test("Gruppe: Zahl, davon neu")
|
||||
func gruppe() throws {
|
||||
let g = try #require(features()?.gruppen)
|
||||
#expect(FeaturesText.gruppeWert(g[0]) == "2 an · 1 neu")
|
||||
#expect(FeaturesText.gruppeWert(g[2]) == "1 an")
|
||||
#expect(FeaturesText.gruppeHinweis(g[2]) == "Spielt nur, wenn der Motor ausfällt (Ante, Splash, Nicht-NLHE, Ausfall).")
|
||||
#expect(FeaturesText.gruppeHinweis(g[0]) == nil)
|
||||
}
|
||||
|
||||
@Test("Tipp eines Schalters: Zeile und Kommentarblock ohne Leerzeilen")
|
||||
func tipp() throws {
|
||||
var s = try #require(features()?.gruppen[0].schalter[0])
|
||||
s.block = ["", "a", "", "b"]
|
||||
s.zeile = 266
|
||||
#expect(FeaturesText.schalterTipp(s) == "Zeile 266\na\nb")
|
||||
}
|
||||
|
||||
@Test("Programme: Zustand, Ton, Zaehler")
|
||||
func exes() throws {
|
||||
let f = try #require(features())
|
||||
#expect(FeaturesText.exeZustand(f.exes[0]) == ("gruen", "läuft gerade"))
|
||||
#expect(FeaturesText.exeZustand(f.exes[1]) == ("rot", "Datei fehlt!"))
|
||||
var e = f.exes[0]
|
||||
e.laeuft = false
|
||||
#expect(FeaturesText.exeZustand(e) == ("grau", "liegt bereit"))
|
||||
e.an = false
|
||||
#expect(FeaturesText.exeZustand(e) == ("grau", "ausgeschaltet"))
|
||||
#expect(FeaturesText.exesWert(f.exes) == "1 von 2 laufen")
|
||||
#expect(FeaturesText.exeUnter(f.exes[0], zoneSekunden: utc) == "30.11. 00:53 · läuft gerade")
|
||||
#expect(FeaturesText.exeUnter(f.exes[1], zoneSekunden: utc) == " · Datei fehlt!")
|
||||
}
|
||||
|
||||
@Test("Zeilen der zugeklappten Listen")
|
||||
func zeilen() throws {
|
||||
let f = try #require(features())
|
||||
let aus = FeaturesText.zeilenAus(f.aus)
|
||||
#expect(aus.first?.name == "MDF_UNREAD")
|
||||
#expect(aus.first?.wert == "= 0")
|
||||
#expect(aus.first?.unter.hasPrefix("14.11. · ") == true)
|
||||
let ruht = FeaturesText.zeilenRuht(f.ruht)
|
||||
#expect(ruht.first == FeaturesText.Zeile(name: "MOTOR_NL2_X", wert: "= 5", unter: "wirkt nicht: MOTOR_NL2 ist aus"))
|
||||
let leer = FeaturesText.zeilenLeerUnbekannt(leer: f.leerZeilen, unbekannt: f.unbekannt)
|
||||
#expect(leer == [
|
||||
FeaturesText.Zeile(name: "VORWISSEN=", wert: "Zeile 12", unter: "leer überschreibt nicht – es gilt weiter a.json"),
|
||||
FeaturesText.Zeile(name: "LEER2=", wert: "Zeile 13", unter: "leer – der Schalter ist nicht gesetzt"),
|
||||
FeaturesText.Zeile(name: "WAS_NEUES", wert: "= 1", unter: "Zeile 77: kein bekannter Schalter (entscheiden/decide.py) – wirkt nicht"),
|
||||
])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
{
|
||||
"stand": 1796062048.0,
|
||||
"laeufer": {
|
||||
"seit": 1796041000.0,
|
||||
"pid": 1,
|
||||
"marke_von": 1796046000.0,
|
||||
"marke_seit_start": false,
|
||||
"geaendert": 2,
|
||||
"weg": [
|
||||
{
|
||||
"name": "ALT_SCHALTER",
|
||||
"vorher": "1",
|
||||
"jetzt": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"gruppen": [
|
||||
{
|
||||
"id": "motor",
|
||||
"titel": "Motor · SHARINGAN",
|
||||
"schalter": [
|
||||
{
|
||||
"name": "MOTOR_SCHATTEN",
|
||||
"wert": "D:\\Projects\\pokerfreak",
|
||||
"zeile": 266,
|
||||
"datum": "24.11.",
|
||||
"kommentar": "Owner 24.11.: der neue Motor SPIELT (entscheiden/schatten.py); der alte Kern nur bei Ante/",
|
||||
"block": [
|
||||
"",
|
||||
"Owner 24.11.: der neue Motor SPIELT (entscheiden/schatten.py); der alte Kern nur bei Ante/Splash/Nicht-NLHE/Ausfall."
|
||||
],
|
||||
"sharingan": false,
|
||||
"pfad": true,
|
||||
"neu_seit_start": null
|
||||
},
|
||||
{
|
||||
"name": "MOTOR_SPIELT",
|
||||
"wert": "1",
|
||||
"zeile": 267,
|
||||
"datum": "24.11.",
|
||||
"kommentar": "Owner 24.11.: der neue Motor SPIELT (entscheiden/schatten.py); der alte Kern nur bei Ante/",
|
||||
"block": [
|
||||
"",
|
||||
"Owner 24.11.: der neue Motor SPIELT (entscheiden/schatten.py); der alte Kern nur bei Ante/Splash/Nicht-NLHE/Ausfall."
|
||||
],
|
||||
"sharingan": false,
|
||||
"pfad": false,
|
||||
"neu_seit_start": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "laeufer",
|
||||
"titel": "Läufer · Tisch",
|
||||
"schalter": [
|
||||
{
|
||||
"name": "TISCHWAHL",
|
||||
"wert": "1",
|
||||
"zeile": 114,
|
||||
"datum": "17.11.",
|
||||
"kommentar": "17.11. abends (Owner: \"bitte nicht mehr so komische testphasen gebunden an uhrzeiten\"): ke",
|
||||
"block": [
|
||||
"Orchestrator-Entscheid 17.11. (Owner: \"Ja, einschalten\"): Tischwahl nach Gegnerstaerke als Live-A/B. Der Laeufer",
|
||||
"schaltet TISCHWAHL selbst in ABBA-Bloecken zu 2 h ab Mitternacht und markiert jede Hand mit tischwahl-an/-aus."
|
||||
],
|
||||
"sharingan": false,
|
||||
"pfad": false,
|
||||
"neu_seit_start": true
|
||||
},
|
||||
{
|
||||
"name": "VORWISSEN",
|
||||
"wert": "C:\\Users\\marcm\\pokerfreak-vorwissen\\speicher-1117-h90v.json.gz",
|
||||
"zeile": 238,
|
||||
"datum": "22.11.",
|
||||
"kommentar": "Orchestrator-Entscheid 22.11. (Go-live-Paket e06fa141 = 0b0545d3, messung/vorwissen/GOLIVE",
|
||||
"block": [
|
||||
"",
|
||||
"Orchestrator-Entscheid 22.11. (Go-live-Paket e06fa141 = 0b0545d3, messung/vorwissen/GOLIVE.md): VORFLOP_POP +jamread"
|
||||
],
|
||||
"sharingan": false,
|
||||
"pfad": true,
|
||||
"neu_seit_start": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "kern",
|
||||
"titel": "Alter Kern",
|
||||
"schalter": [
|
||||
{
|
||||
"name": "KERN_AUS",
|
||||
"wert": "1",
|
||||
"zeile": 9,
|
||||
"datum": "01.11.",
|
||||
"kommentar": "01.11.: Probe.",
|
||||
"block": [
|
||||
"01.11.: Probe."
|
||||
],
|
||||
"sharingan": true,
|
||||
"pfad": false,
|
||||
"neu_seit_start": null
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"an": 5,
|
||||
"aus": [
|
||||
{
|
||||
"name": "MDF_UNREAD",
|
||||
"wert": "0",
|
||||
"datum": "14.11.",
|
||||
"kommentar": "Gegner. Live 14.11.: 17 MDF-Boden-Calls, 15 verloren, -388,5"
|
||||
}
|
||||
],
|
||||
"ruht": [
|
||||
{
|
||||
"name": "MOTOR_NL2_X",
|
||||
"wert": "5",
|
||||
"elter": "MOTOR_NL2",
|
||||
"datum": "01.11.",
|
||||
"kommentar": "x"
|
||||
}
|
||||
],
|
||||
"unbekannt": [
|
||||
{
|
||||
"name": "WAS_NEUES",
|
||||
"wert": "1",
|
||||
"zeile": 77
|
||||
}
|
||||
],
|
||||
"leer": [
|
||||
{
|
||||
"name": "VORWISSEN",
|
||||
"zeile": 12,
|
||||
"gilt": "a.json"
|
||||
},
|
||||
{
|
||||
"name": "LEER2",
|
||||
"zeile": 13,
|
||||
"gilt": null
|
||||
}
|
||||
],
|
||||
"exes": [
|
||||
{
|
||||
"rolle": "Motor (Cash)",
|
||||
"pfad": "D:\\Projects\\pokerfreak/entscheiden/motor/target/pokerbench-motor-schatten.exe",
|
||||
"an": true,
|
||||
"name": "pokerbench-motor-schatten.exe",
|
||||
"da": true,
|
||||
"datum": 1796000000.0,
|
||||
"md5": "a1b2c3d4",
|
||||
"laeuft": true
|
||||
},
|
||||
{
|
||||
"rolle": "SHARINGAN Vorflop/Flop",
|
||||
"an": true,
|
||||
"pfad": "D:/pokerfreak-fremd/sharingan/code/target/serve/pokerbench-pruef6-hybrid.exe",
|
||||
"name": "pokerbench-pruef6-hybrid.exe",
|
||||
"da": false,
|
||||
"datum": null,
|
||||
"md5": null,
|
||||
"laeuft": false
|
||||
}
|
||||
],
|
||||
"sitzungen": {
|
||||
"liste": [
|
||||
{
|
||||
"von": 1796040000.0,
|
||||
"bis": 1796046000.0,
|
||||
"haende": 80,
|
||||
"turnier": 0,
|
||||
"roh": {
|
||||
"mittel": 12.5,
|
||||
"halb95": 4.0,
|
||||
"n": 80
|
||||
},
|
||||
"aivat": {
|
||||
"mittel": 12.5,
|
||||
"halb95": 4.0,
|
||||
"n": 80
|
||||
},
|
||||
"netto_bb": 10.0,
|
||||
"anders": [
|
||||
{
|
||||
"name": "MOTOR_EINSATZ",
|
||||
"vorher": null,
|
||||
"nachher": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"von": 1796000000.0,
|
||||
"bis": 1796006000.0,
|
||||
"haende": 70,
|
||||
"turnier": 0,
|
||||
"roh": {
|
||||
"mittel": -3.25,
|
||||
"halb95": 5.0,
|
||||
"n": 70
|
||||
},
|
||||
"aivat": {
|
||||
"mittel": -3.25,
|
||||
"halb95": 5.0,
|
||||
"n": 70
|
||||
},
|
||||
"netto_bb": -2.275,
|
||||
"anders": []
|
||||
},
|
||||
{
|
||||
"von": 1795900000.0,
|
||||
"bis": 1795906000.0,
|
||||
"haende": 60,
|
||||
"turnier": 0,
|
||||
"roh": {
|
||||
"mittel": 1.0,
|
||||
"halb95": 6.0,
|
||||
"n": 60
|
||||
},
|
||||
"aivat": {
|
||||
"mittel": 1.0,
|
||||
"halb95": 6.0,
|
||||
"n": 60
|
||||
},
|
||||
"netto_bb": 0.6,
|
||||
"anders": []
|
||||
}
|
||||
],
|
||||
"vergleich": {
|
||||
"diff": 15.75,
|
||||
"halb95": 6.4,
|
||||
"urteil": "besser",
|
||||
"anders": [
|
||||
{
|
||||
"name": "MOTOR_EINSATZ",
|
||||
"vorher": null,
|
||||
"nachher": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"klein": 2,
|
||||
"mindest": 50
|
||||
},
|
||||
"wirkung": {
|
||||
"features": [
|
||||
{
|
||||
"id": "nl2_daten",
|
||||
"titel": "NL2-Daten",
|
||||
"erklaerung": "Ändert Call/Fold.",
|
||||
"art": "regel",
|
||||
"schalter": [
|
||||
"MOTOR_NL2"
|
||||
],
|
||||
"zustand": {
|
||||
"MOTOR_NL2": "1"
|
||||
},
|
||||
"entscheidungen": 14,
|
||||
"ueberstimmt": 2,
|
||||
"haende": 12,
|
||||
"aivat": {
|
||||
"mittel": -2.5833333333333335,
|
||||
"halb95": 6.0,
|
||||
"n": 12,
|
||||
"summe": -31.0
|
||||
},
|
||||
"roh": {
|
||||
"mittel": -2.9583333333333335,
|
||||
"halb95": 7.0,
|
||||
"n": 12,
|
||||
"summe": -35.5
|
||||
},
|
||||
"haupt": {
|
||||
"haende": 10,
|
||||
"aivat": {
|
||||
"mittel": -3.1,
|
||||
"halb95": 5.5,
|
||||
"n": 10,
|
||||
"summe": -31.0
|
||||
},
|
||||
"roh": {
|
||||
"mittel": -3.55,
|
||||
"halb95": 6.0,
|
||||
"n": 10,
|
||||
"summe": -35.5
|
||||
}
|
||||
},
|
||||
"ton": "rot",
|
||||
"satz": "3 Hände kosten −30 bb. Ansehen.",
|
||||
"urteil": "ansehen",
|
||||
"wechsel": [
|
||||
{
|
||||
"name": "MOTOR_NL2",
|
||||
"vorher": null,
|
||||
"nachher": "1",
|
||||
"kommentar": "30.11.: neu an",
|
||||
"datum": "30.11."
|
||||
}
|
||||
],
|
||||
"vorher": {
|
||||
"haupt": {
|
||||
"haende": 20,
|
||||
"aivat": {
|
||||
"mittel": 0.1,
|
||||
"halb95": 3.0,
|
||||
"n": 20,
|
||||
"summe": 2.0
|
||||
},
|
||||
"roh": {
|
||||
"mittel": 0.05,
|
||||
"halb95": 3.0,
|
||||
"n": 20,
|
||||
"summe": 1.0
|
||||
}
|
||||
},
|
||||
"ton": "grau",
|
||||
"urteil": "unauffällig"
|
||||
},
|
||||
"vergleich": {
|
||||
"diff": -3.1,
|
||||
"halb95": 1.0,
|
||||
"urteil": "schlechter"
|
||||
},
|
||||
"verlierer": [
|
||||
{
|
||||
"hand": "h-100",
|
||||
"t": 1796040500.0,
|
||||
"raum": "A",
|
||||
"roh": -20.0,
|
||||
"aivat": -22.5,
|
||||
"entscheidungen": [],
|
||||
"letzte": true,
|
||||
"haupt": [
|
||||
"nl2_daten"
|
||||
],
|
||||
"alle": [
|
||||
{
|
||||
"street": "PREFLOP",
|
||||
"aktion": "RAISE",
|
||||
"groesse": 2.5,
|
||||
"grund": "SHARINGAN Blueprint",
|
||||
"wer": [
|
||||
"blueprint"
|
||||
],
|
||||
"ueberstimmt": []
|
||||
},
|
||||
{
|
||||
"street": "FLOP",
|
||||
"aktion": "CALL",
|
||||
"groesse": null,
|
||||
"grund": "NL2-Daten: Call",
|
||||
"wer": [
|
||||
"nl2_daten"
|
||||
],
|
||||
"ueberstimmt": [
|
||||
"blueprint"
|
||||
]
|
||||
},
|
||||
{
|
||||
"street": "TURN",
|
||||
"aktion": "FOLD",
|
||||
"groesse": null,
|
||||
"grund": "Preis",
|
||||
"wer": [
|
||||
"motor_preis",
|
||||
"nl2_typ"
|
||||
],
|
||||
"ueberstimmt": []
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"gewinner": [
|
||||
{
|
||||
"hand": "h-101",
|
||||
"t": 1796041500.0,
|
||||
"raum": "A",
|
||||
"roh": 8.0,
|
||||
"aivat": 6.0,
|
||||
"entscheidungen": [],
|
||||
"letzte": true,
|
||||
"haupt": [
|
||||
"blueprint"
|
||||
],
|
||||
"alle": [
|
||||
{
|
||||
"street": "PREFLOP",
|
||||
"aktion": "RAISE",
|
||||
"groesse": 2.5,
|
||||
"grund": "SHARINGAN Blueprint",
|
||||
"wer": [
|
||||
"blueprint"
|
||||
],
|
||||
"ueberstimmt": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "splash",
|
||||
"titel": "Splash",
|
||||
"erklaerung": "",
|
||||
"art": "art",
|
||||
"schalter": [],
|
||||
"zustand": {},
|
||||
"entscheidungen": 0,
|
||||
"ueberstimmt": 0,
|
||||
"haende": 0,
|
||||
"aivat": null,
|
||||
"roh": null,
|
||||
"haupt": {
|
||||
"haende": 0,
|
||||
"aivat": null,
|
||||
"roh": null
|
||||
},
|
||||
"ton": "grau",
|
||||
"satz": "Hat nicht entschieden.",
|
||||
"urteil": "zu wenig",
|
||||
"wechsel": [],
|
||||
"vorher": null,
|
||||
"vergleich": null,
|
||||
"verlierer": [],
|
||||
"gewinner": []
|
||||
}
|
||||
],
|
||||
"sitzung": {
|
||||
"von": 1796040000.0,
|
||||
"bis": 1796046000.0,
|
||||
"haende": 80,
|
||||
"netto_bb": 10.0,
|
||||
"aivat_bb": 10.0
|
||||
},
|
||||
"vorige": null,
|
||||
"ohne_zuege": 0,
|
||||
"regeln": {
|
||||
"min_haende": 10,
|
||||
"klumpen_bb": 15.0,
|
||||
"klumpen_anteil": 0.5
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,11 +96,11 @@ struct HauptknopfSpec {
|
||||
struct SpielplanSpec {
|
||||
@Test("als Daten für spielplan_setzen")
|
||||
func daten() {
|
||||
// tischform, stufen und stufen_tische gehen immer mit (wie WinUI): fehlen sie, behielte der Server die alten
|
||||
// tischform, stufen, stufen_tische und aus gehen immer mit (wie WinUI): fehlen sie, behielte der Server die alten
|
||||
#expect(Spielplan(modus: .echt, tische: 3, budget: 250).datenText
|
||||
== #"{"budget":250,"modus":"cash","stufen":{},"stufen_tische":{},"tische":3,"tischform":"multiway"}"#)
|
||||
== #"{"aus":[],"budget":250,"modus":"cash","stufen":{},"stufen_tische":{},"tische":3,"tischform":"multiway"}"#)
|
||||
#expect(Spielplan(modus: .uebung, tische: 1, budget: 99).datenText
|
||||
== #"{"modus":"uebung","stufen":{},"stufen_tische":{},"tische":1,"tischform":"multiway"}"#)
|
||||
== #"{"aus":[],"modus":"uebung","stufen":{},"stufen_tische":{},"tische":1,"tischform":"multiway"}"#)
|
||||
}
|
||||
|
||||
@Test("aus dem Kopf gelesen")
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import CockpitKern
|
||||
import Testing
|
||||
|
||||
// Die Rasterkachel als kleiner Tisch (Owner 30.11., wie WinUI 011d6f44): eigene Karten, Board, Topf,
|
||||
// letzte eigene Aktion, am Zug eine ablaufende Uhr.
|
||||
|
||||
private func kachel(_ json: String) -> LiveKachelDaten? {
|
||||
var a = Ansicht()
|
||||
_ = a.anwenden(#"{"typ":"ansicht","teile":{"sitzen":{"live":{"kacheln":["# + json + "]}}}}")
|
||||
return a.sitzen?.live?.kacheln.first
|
||||
}
|
||||
|
||||
@Suite("Minitisch: was die Rasterkachel zeigt")
|
||||
struct MinitischSpec {
|
||||
@Test("die eigene Aktion steht am eigenen Platz; nach dem Fold ist die Hand raus")
|
||||
func ichAktion() {
|
||||
let k = kachel(#"{"raum":"A","sitze":[{"stelle":0,"ich":false,"aktion":"Raise 0,06"},{"stelle":1,"ich":true,"aktion":"Fold"}]}"#)
|
||||
#expect(k?.ichAktion == "Fold")
|
||||
#expect(k?.ichRaus == true)
|
||||
#expect(kachel(#"{"raum":"A","sitze":[{"stelle":1,"ich":true,"aktion":"Call 0,02"}]}"#)?.ichRaus == false)
|
||||
#expect(kachel(#"{"raum":"A","sitze":[]}"#)?.ichAktion == "")
|
||||
}
|
||||
|
||||
@Test("Farbe der Aktion: Fold grau, Call/Check grün, Raise/Bet/All-in orange")
|
||||
func aktionTon() {
|
||||
#expect(LiveAktion.ton("Fold") == "grau")
|
||||
#expect(LiveAktion.ton("Check") == "gruen")
|
||||
#expect(LiveAktion.ton("Call 0,02") == "gruen")
|
||||
#expect(LiveAktion.ton("Raise 0,06") == "orange")
|
||||
#expect(LiveAktion.ton("Bet 0,04") == "orange")
|
||||
#expect(LiveAktion.ton("All-in") == "orange")
|
||||
#expect(LiveAktion.ton("Sitzt aus") == "")
|
||||
}
|
||||
|
||||
@Test("Zug-Uhr: Rest der Frist als Anteil, ohne Frist voll, nie unter 0 oder über 1")
|
||||
func uhr() {
|
||||
let z = Zug(offen: true, fristS: 20, bis: 110, seit: nil)
|
||||
#expect(z.restAnteil(jetzt: 100) == 0.5)
|
||||
#expect(z.restAnteil(jetzt: 120) == 0)
|
||||
#expect(z.restAnteil(jetzt: 80) == 1)
|
||||
#expect(Zug(offen: true, fristS: nil, bis: 110, seit: nil).restAnteil(jetzt: 100) == 1)
|
||||
#expect(Zug(offen: true, fristS: 20, bis: nil, seit: nil).restAnteil(jetzt: 100) == nil)
|
||||
#expect(Zug(offen: false, fristS: 20, bis: 110, seit: nil).restAnteil(jetzt: 100) == nil)
|
||||
}
|
||||
|
||||
@Test("Ton der Uhr: grün, unter der Hälfte orange, unter einem Viertel rot")
|
||||
func uhrTon() {
|
||||
#expect(Zug.uhrTon(0.8) == "gruen")
|
||||
#expect(Zug.uhrTon(0.4) == "orange")
|
||||
#expect(Zug.uhrTon(0.2) == "rot")
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ struct ZeitplanSpec {
|
||||
var p = Spielplan(modus: .uebung, tische: 4, budget: nil)
|
||||
p.tischeBis = 8
|
||||
// tischform geht immer mit (Spielplan.daten: robuster Round-Trip, wie geld.reserve)
|
||||
#expect(p.datenText == #"{"modus":"uebung","stufen":{},"stufen_tische":{},"tische":4,"tische_bis":8,"tischform":"multiway"}"#)
|
||||
#expect(p.datenText == #"{"aus":[],"modus":"uebung","stufen":{},"stufen_tische":{},"tische":4,"tische_bis":8,"tischform":"multiway"}"#)
|
||||
p.tischeBis = 3 // unter der Untergrenze: keine Spanne
|
||||
#expect(p.tischeBis == nil)
|
||||
p.zeitplan = Zeitplan(sitzung: Spanne(30, 60), pause: Spanne(5, 10), sitzungen: 3,
|
||||
|
||||
Reference in New Issue
Block a user