The data layer already sends `modus` on jetzt and on each decision row. The app now decodes it (TischModus, lenient like the other models) and shows it on every live tile and in the opened decision: tournament level, blinds, a pulsing Bubble / green "im Geld" capsule and one tick per remaining player (filled = paid place, a bar above 40 players); K-Poker as key caps with sizes and the move clock; Cash as a quiet chip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
4.7 KiB
Swift
128 lines
4.7 KiB
Swift
import Foundation
|
||
|
||
/// Restzeit des offenen Zugs - die App zaehlt selbst, der Server schickt nur `bis`.
|
||
public struct Countdown: Equatable, Sendable {
|
||
public var rest: Double
|
||
public var anteil: Double
|
||
|
||
public init?(zug: Zug?, jetzt: Double) {
|
||
guard let z = zug, z.offen, let bis = z.bis, let frist = z.fristS, frist > 0 else { return nil }
|
||
rest = max(0, bis - jetzt)
|
||
anteil = min(1, rest / frist)
|
||
}
|
||
}
|
||
|
||
public enum ErgebnisFilter: String, Sendable, CaseIterable { case gewonnen, verloren, null, offen }
|
||
|
||
/// Die Filterregel von ansicht.filtern: jeder gesetzte Filter muss passen; die Suche (ohne
|
||
/// Gross/klein, Leerraum am Rand zaehlt nicht) steht in Grund, Klartext, Karten, Hand oder Raum.
|
||
public struct EntscheidungsFilter: Equatable, Sendable {
|
||
public var aktion: String?
|
||
public var stake: String?
|
||
public var spielart: String?
|
||
public var ergebnis: ErgebnisFilter?
|
||
public var suche: String
|
||
|
||
public init(aktion: String? = nil, stake: String? = nil, spielart: String? = nil,
|
||
ergebnis: ErgebnisFilter? = nil, suche: String = "") {
|
||
self.aktion = aktion; self.stake = stake; self.spielart = spielart; self.ergebnis = ergebnis; self.suche = suche
|
||
}
|
||
|
||
public var istLeer: Bool { aktion == nil && stake == nil && spielart == nil && ergebnis == nil && sucheText.isEmpty }
|
||
|
||
private var sucheText: String { suche.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() }
|
||
|
||
public func anwenden(_ zeilen: [EntscheidungsZeile]) -> [EntscheidungsZeile] {
|
||
let s = sucheText
|
||
return zeilen.filter { z in
|
||
if let a = aktion, z.aktion != a { return false }
|
||
if let st = stake, z.stake != st { return false }
|
||
if let sp = spielart, z.spielart != sp { return false }
|
||
if let e = ergebnis, !Self.passt(e, z.ergebnisBB) { return false }
|
||
if !s.isEmpty {
|
||
let felder: [String?] = [z.grund, z.klartext, z.karten.joined(separator: " "), z.hand, z.raum]
|
||
return felder.contains { ($0 ?? "").lowercased().contains(s) }
|
||
}
|
||
return true
|
||
}
|
||
}
|
||
|
||
private static func passt(_ e: ErgebnisFilter, _ x: Double?) -> Bool {
|
||
switch e {
|
||
case .gewonnen: return (x ?? 0) > 0
|
||
case .verloren: return (x ?? 0) < 0
|
||
case .null: return x == 0
|
||
case .offen: return x == nil
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Zahlen, wie die App sie zeigt: deutsch, Strich fuer unbekannt.
|
||
public enum Format {
|
||
private static func formatter(_ stellen: Int) -> NumberFormatter {
|
||
let f = NumberFormatter()
|
||
f.locale = Locale(identifier: "de_DE")
|
||
f.numberStyle = .decimal
|
||
f.minimumFractionDigits = 0
|
||
f.maximumFractionDigits = stellen
|
||
return f
|
||
}
|
||
|
||
/// Ohne Gruppierung und Locale - fuer Texte, die aus Zahlen werden (Platz, Blinds).
|
||
public static func roh(_ x: Double) -> String {
|
||
x == x.rounded() && abs(x) < 1e15 ? String(Int(x)) : String(x)
|
||
}
|
||
|
||
public static func zahl(_ x: Double?, stellen: Int = 2) -> String {
|
||
guard let x, x.isFinite else { return "–" }
|
||
return formatter(stellen).string(from: x as NSNumber) ?? "–"
|
||
}
|
||
|
||
/// Stellen nach Groesse: ab 100 keine, ab 10 eine, sonst zwei.
|
||
public static func auto(_ x: Double?) -> String {
|
||
guard let x else { return "–" }
|
||
let a = abs(x)
|
||
return zahl(x, stellen: a >= 100 ? 0 : a >= 10 ? 1 : 2)
|
||
}
|
||
|
||
public static func prozent(_ x: Double?) -> String {
|
||
guard let x else { return "–" }
|
||
return zahl(x * 100, stellen: 0) + " %"
|
||
}
|
||
|
||
public static func vorzeichen(_ x: Double?, stellen: Int = 2) -> String {
|
||
guard let x else { return "–" }
|
||
let t = zahl(abs(x), stellen: stellen)
|
||
return x > 0 ? "+" + t : x < 0 ? "−" + t : t
|
||
}
|
||
}
|
||
|
||
public enum Farbe: Sendable {
|
||
case herz, karo, pik, kreuz
|
||
|
||
public var symbol: String {
|
||
switch self { case .herz: "♥"; case .karo: "♦"; case .pik: "♠"; case .kreuz: "♣" }
|
||
}
|
||
|
||
public var rot: Bool { self == .herz || self == .karo }
|
||
}
|
||
|
||
public struct Karte: Equatable, Sendable {
|
||
public var rang: String
|
||
public var farbe: Farbe
|
||
|
||
/// "Qh" -> Q♥, "Ts" -> 10♠; alles andere (Platzhalter wie "FLOP") ist keine Karte.
|
||
public init?(_ s: String) {
|
||
guard s.count == 2, let r = s.first, let f = s.last else { return nil }
|
||
switch f.lowercased() {
|
||
case "h": farbe = .herz
|
||
case "d": farbe = .karo
|
||
case "s": farbe = .pik
|
||
case "c": farbe = .kreuz
|
||
default: return nil
|
||
}
|
||
guard "23456789TJQKA".contains(r.uppercased()) else { return nil }
|
||
rang = r.uppercased() == "T" ? "10" : r.uppercased()
|
||
}
|
||
}
|