import Foundation // Die Bereiche der Ansicht, wie sicht/ANSICHT.md sie beschreibt. Alles ist nachsichtig dekodiert: // fehlende Felder sind nil oder leer, nie ein Fehler - die Datenschicht darf wachsen. public enum Bereich: String, CaseIterable, Sendable { case kopf, jetzt, wachstum, entscheidungen, geld, sitzen, stil, ticker, zuschauer } public enum Ton: String, Sendable { case rot, gelb, gruen, blau, grau public init(farbe: String?) { self = farbe.flatMap(Ton.init(rawValue:)) ?? .grau } } public struct Status: Decodable, Equatable, Sendable { public var zustand: String? public var farbe: String? public var satz: String? public var ton: Ton { Ton(farbe: farbe) } } public struct Kopf: Decodable, Equatable, Sendable { public var leer: String? public var laeuft = false public var text: String? public var seit: Double? public var zuletzt: Double? public var laufzeitS: Double? public var tische: [String] = [] public var tischeOffen: Int? public var tischeText: String? public var modus: String? public var modusQuelle: String? public var klon = false public var notAus = false public var guthaben: Double? public var pid: Int? public var status: Status? /// Laeuft der CoinPoker-Client? nil: unbekannt (Klon, aeltere Datenschicht). public var client: Bool? /// Laeuft der Client mit Debug-Port? false: Lobby-Steuerung (Tische oeffnen) geht nicht. public var clientPort: Bool? /// Wie der letzte Lauf endete (nil, solange er laeuft oder nie lief). public var ende: Ende? /// Der Spielplan, den der Laeufer liest (nil: keiner gesetzt). public var spielplan: Spielplan? public var phase: Phase? /// Kontostatus des Raums: Betrugsverdacht, Sperre, Ruhezeit, Rake - was uns gefaehrlich wird. public var konto: Konto? enum CodingKeys: String, CodingKey { case leer, laeuft, text, seit, zuletzt, laufzeitS = "laufzeit_s", tische, tischeOffen = "tische_offen" case tischeText = "tische_text", modus, modusQuelle = "modus_quelle", klon, notAus = "not_aus" case guthaben, pid, status, client, ende, spielplan, phase, clientPort = "client_port", konto } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) leer = c.text(.leer) laeuft = c.wahr(.laeuft) text = c.text(.text) seit = c.zahl(.seit) zuletzt = c.zahl(.zuletzt) laufzeitS = c.zahl(.laufzeitS) tische = c.liste(.tische) tischeOffen = c.zahl(.tischeOffen).map { Int($0) } tischeText = c.text(.tischeText) modus = c.text(.modus) modusQuelle = c.text(.modusQuelle) klon = c.wahr(.klon) notAus = c.wahr(.notAus) guthaben = c.zahl(.guthaben) pid = c.zahl(.pid).map { Int($0) } status = try? c.decodeIfPresent(Status.self, forKey: .status) client = (try? c.decodeIfPresent(Bool.self, forKey: .client)) ?? nil clientPort = (try? c.decodeIfPresent(Bool.self, forKey: .clientPort)) ?? nil ende = try? c.decodeIfPresent(Ende.self, forKey: .ende) spielplan = (try? c.decodeIfPresent(Spielplan.self, forKey: .spielplan)) ?? nil phase = (try? c.decodeIfPresent(Phase.self, forKey: .phase)) ?? nil konto = (try? c.decodeIfPresent(Konto.self, forKey: .konto)) ?? nil } } /// Konto- und Raumstatus (hand/fraud.py, lesen/vorteile.py, lesen/rake.py). Die Zeilen kommen /// fertig vom Server - die GUI rechnet nichts nach, sie zeigt nur. public struct Konto: Decodable, Equatable, Sendable { public var status: String? public var felder: [String] = [] public var warn = false public var verdacht: Bool? public var gesperrt: Bool? /// Diese Tische laufen gerade in der Ruhezeit des Raums - kein neuer Tisch. public var schwarzJetzt = false public var schwarzeStunden: [Int] = [] /// Nur was gerade gefaehrlich ist: das gehoert in die Kopfzeile, der Rest in die Konto-Karte. public var alarme: [String] { felder.filter { $0.hasPrefix("Verdacht: ja") || $0.hasPrefix("Gesperrt: ja") || $0.contains("(JETZT)") } } enum CodingKeys: String, CodingKey { case status, felder, warn, verdacht, gesperrt case schwarzJetzt = "schwarz_jetzt", schwarzeStunden = "schwarze_stunden" } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) status = c.text(.status) felder = c.liste(.felder) warn = c.wahr(.warn) verdacht = (try? c.decodeIfPresent(Bool.self, forKey: .verdacht)) ?? nil gesperrt = (try? c.decodeIfPresent(Bool.self, forKey: .gesperrt)) ?? nil schwarzJetzt = c.wahr(.schwarzJetzt) schwarzeStunden = c.liste(.schwarzeStunden).compactMap(Int.init) } } public struct Ende: Decodable, Equatable, Sendable { public var zeit: Double? public var abbruch = false public var grund: String? enum CodingKeys: String, CodingKey { case zeit, abbruch, grund } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) zeit = c.zahl(.zeit); abbruch = c.wahr(.abbruch); grund = c.text(.grund) } } public struct Zug: Decodable, Equatable, Sendable { public var offen = false public var fristS: Double? public var bis: Double? public var seit: Double? public init(offen: Bool, fristS: Double?, bis: Double?, seit: Double?) { self.offen = offen; self.fristS = fristS; self.bis = bis; self.seit = seit } enum CodingKeys: String, CodingKey { case offen, fristS = "frist_s", bis, seit } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) offen = c.wahr(.offen); fristS = c.zahl(.fristS); bis = c.zahl(.bis); seit = c.zahl(.seit) } } public struct Entscheidung: Decodable, Equatable, Sendable { public var aktion: String? public var aktionText: String? public var betrag: Double? public var betragBB: Double? public var grund: String? public var klartext: String? public var equity: Double? public var confidence: Double? public var gedenkzeitS: Double? public var zeit: Double? enum CodingKeys: String, CodingKey { case aktion, aktionText = "aktion_text", betrag, betragBB = "betrag_bb", grund, klartext, equity case confidence, gedenkzeitS = "gedenkzeit_s", zeit } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) aktion = c.text(.aktion); aktionText = c.text(.aktionText); betrag = c.zahl(.betrag) betragBB = c.zahl(.betragBB); grund = c.text(.grund); klartext = c.text(.klartext) equity = c.zahl(.equity); confidence = c.zahl(.confidence); gedenkzeitS = c.zahl(.gedenkzeitS) zeit = c.zahl(.zeit) } } public struct Klick: Decodable, Equatable, Sendable { public var status: String? public var warum: String? public var beleg: String? public init(status: String?, warum: String?, beleg: String?) { self.status = status; self.warum = warum; self.beleg = beleg } } public struct Jetzt: Decodable, Equatable, Sendable { public var leer: String? public var raum: String? public var hand: String? public var strasse: String? public var karten: [String] = [] public var board: [String] = [] public var topf: Double? public var zuZahlen: Double? public var stack: Double? public var zug: Zug? public var entscheidung: Entscheidung? public var klick: Klick? public var modus: TischModus? enum CodingKeys: String, CodingKey { case leer, raum, hand, strasse, karten, board, topf, zuZahlen = "zu_zahlen", stack, zug, entscheidung, klick, modus } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) leer = c.text(.leer); raum = c.text(.raum); hand = c.text(.hand); strasse = c.text(.strasse) karten = c.liste(.karten); board = c.liste(.board); topf = c.zahl(.topf); zuZahlen = c.zahl(.zuZahlen) stack = c.zahl(.stack) zug = try? c.decodeIfPresent(Zug.self, forKey: .zug) entscheidung = try? c.decodeIfPresent(Entscheidung.self, forKey: .entscheidung) klick = try? c.decodeIfPresent(Klick.self, forKey: .klick) modus = try? c.decodeIfPresent(TischModus.self, forKey: .modus) } } public struct EntscheidungsZeile: Decodable, Equatable, Sendable, Identifiable { public var zeit: Double? public var raum: String? public var hand: String? public var strasse: String? public var karten: [String] public var board: [String] public var aktion: String? public var aktionText: String? public var betragBB: Double? public var grund: String? public var klartext: String? public var equity: Double? public var confidence: Double? public var stake: String? public var spielart: String? public var ergebnisBB: Double? public var ergebnisText: String? public var klick: String? public var klickWarum: String? public var beleg: String? public var gedenkzeitS: Double? public var modus: TischModus? public var id: String { "\(zeit ?? 0)|\(hand ?? "")|\(raum ?? "")|\(aktion ?? "")" } public init(zeit: Double?, raum: String?, hand: String?, strasse: String?, karten: [String], board: [String], aktion: String?, aktionText: String?, betragBB: Double?, grund: String?, klartext: String?, equity: Double?, confidence: Double?, stake: String?, spielart: String?, ergebnisBB: Double?, ergebnisText: String?, klick: String?, klickWarum: String?, beleg: String?, gedenkzeitS: Double?) { self.zeit = zeit; self.raum = raum; self.hand = hand; self.strasse = strasse; self.karten = karten self.board = board; self.aktion = aktion; self.aktionText = aktionText; self.betragBB = betragBB self.grund = grund; self.klartext = klartext; self.equity = equity; self.confidence = confidence self.stake = stake; self.spielart = spielart; self.ergebnisBB = ergebnisBB; self.ergebnisText = ergebnisText self.klick = klick; self.klickWarum = klickWarum; self.beleg = beleg; self.gedenkzeitS = gedenkzeitS } enum CodingKeys: String, CodingKey { case zeit, raum, hand, strasse, karten, board, aktion, aktionText = "aktion_text", betragBB = "betrag_bb" case grund, klartext, equity, confidence, stake, spielart, ergebnisBB = "ergebnis_bb" case ergebnisText = "ergebnis_text", klick, klickWarum = "klick_warum", beleg, gedenkzeitS = "gedenkzeit_s", modus } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) self.init(zeit: c.zahl(.zeit), raum: c.text(.raum), hand: c.text(.hand), strasse: c.text(.strasse), karten: c.liste(.karten), board: c.liste(.board), aktion: c.text(.aktion), aktionText: c.text(.aktionText), betragBB: c.zahl(.betragBB), grund: c.text(.grund), klartext: c.text(.klartext), equity: c.zahl(.equity), confidence: c.zahl(.confidence), stake: c.text(.stake), spielart: c.text(.spielart), ergebnisBB: c.zahl(.ergebnisBB), ergebnisText: c.text(.ergebnisText), klick: c.text(.klick), klickWarum: c.text(.klickWarum), beleg: c.text(.beleg), gedenkzeitS: c.zahl(.gedenkzeitS)) modus = try? c.decodeIfPresent(TischModus.self, forKey: .modus) } } public struct Facetten: Decodable, Equatable, Sendable { public var aktion: [String] = [] public var stake: [String] = [] public var spielart: [String] = [] public var ergebnis: [String] = [] enum CodingKeys: String, CodingKey { case aktion, stake, spielart, ergebnis } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) aktion = c.liste(.aktion); stake = c.liste(.stake); spielart = c.liste(.spielart); ergebnis = c.liste(.ergebnis) } } public struct Entscheidungen: Decodable, Equatable, Sendable { public var leer: String? public var zeilen: [EntscheidungsZeile] = [] public var facetten: Facetten? public var gesamt: Int? public var angezeigt: Int? public var gekappt = false public var ausschnitt = false public var hinweis: String? enum CodingKeys: String, CodingKey { case leer, zeilen, facetten, gesamt, angezeigt, gekappt, ausschnitt, hinweis } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) leer = c.text(.leer); zeilen = c.objekte(.zeilen) facetten = try? c.decodeIfPresent(Facetten.self, forKey: .facetten) gesamt = c.zahl(.gesamt).map { Int($0) }; angezeigt = c.zahl(.angezeigt).map { Int($0) } gekappt = c.wahr(.gekappt); ausschnitt = c.wahr(.ausschnitt); hinweis = c.text(.hinweis) } } public struct GeldZeile: Decodable, Equatable, Sendable, Identifiable { public var zeit: Double? public var raum: String? public var art: String? public var betrag: Double? public var betragBB: Double? public var grund: String? public var uebung: Bool? public var id: String { "\(zeit ?? 0)|\(raum ?? "")|\(art ?? "")|\(grund ?? "")" } enum CodingKeys: String, CodingKey { case zeit, raum, art, betrag, betragBB = "betrag_bb", grund, uebung } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) zeit = c.zahl(.zeit); raum = c.text(.raum); art = c.text(.art); betrag = c.zahl(.betrag) betragBB = c.zahl(.betragBB); grund = c.text(.grund); uebung = try? c.decodeIfPresent(Bool.self, forKey: .uebung) } } public struct Geld: Decodable, Equatable, Sendable { public var leer: String? public var zeilen: [GeldZeile] = [] public var uebung = false public var regeln: GeldRegeln? public var stand: GeldStand? /// Ergebnis, Rake, Rakeback und netto in einer Zeile - brutto ist keine Zahl, auf die man spielt. public var netto: String? enum CodingKeys: String, CodingKey { case leer, zeilen, uebung, regeln, stand, netto } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) leer = c.text(.leer); zeilen = c.objekte(.zeilen); uebung = c.wahr(.uebung) regeln = try? c.decodeIfPresent(GeldRegeln.self, forKey: .regeln) stand = try? c.decodeIfPresent(GeldStand.self, forKey: .stand) netto = c.text(.netto) } } public struct Handlung: Decodable, Equatable, Sendable { public var art: String? public var grund: String? public var zeit: Double? enum CodingKeys: String, CodingKey { case art, grund, zeit } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) art = c.text(.art); grund = c.text(.grund); zeit = c.zahl(.zeit) } } public struct Raum: Decodable, Equatable, Sendable, Identifiable { public var raum: String /// Der Name wie im Spiel ("NLH 1676973 - 1K/2K") - `raum` ist die interne Kennung. public var titel: String? public var zustand: String? public var platz: String? public var stack: Double? public var groesse: Int? public var bb: String? public var modus: String? public var handlung: Handlung? public var fenster: Int? /// Die laufende Hand aus dem Client-Log (sicht/ansicht._haende_im_log) - auch ohne Läufer. public var hand: LogHand? /// Alle Plätze mit Namen, Stack, Rolle, Aktion und Gegnerwerten (sicht/ansicht._tisch_ansicht). public var tisch: TischAnsicht? public var id: String { raum } public struct LogHand: Decodable, Equatable, Sendable { public var hand: String? public var karten: [String] = [] public var board: [String] = [] public var topf: Double? enum CodingKeys: String, CodingKey { case hand, karten, board, topf } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) hand = c.text(.hand); karten = c.liste(.karten); board = c.liste(.board); topf = c.zahl(.topf) } } enum CodingKeys: String, CodingKey { case raum, titel, zustand, platz, stack, groesse, bb, modus, handlung, fenster, hand, tisch } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) raum = c.text(.raum) ?? "?"; titel = c.text(.titel); zustand = c.text(.zustand); platz = c.text(.platz); stack = c.zahl(.stack) groesse = c.zahl(.groesse).map { Int($0) }; bb = c.text(.bb); modus = c.text(.modus) handlung = try? c.decodeIfPresent(Handlung.self, forKey: .handlung); fenster = c.zahl(.fenster).map { Int($0) } hand = (try? c.decodeIfPresent(LogHand.self, forKey: .hand)) ?? nil tisch = (try? c.decodeIfPresent(TischAnsicht.self, forKey: .tisch)) ?? nil } } public struct Sitzen: Decodable, Equatable, Sendable { public struct Fenster: Decodable, Equatable, Sendable { public var zahl: Int? public var ueberzaehlig: [String] = [] enum CodingKeys: String, CodingKey { case zahl, ueberzaehlig } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) zahl = c.zahl(.zahl).map { Int($0) }; ueberzaehlig = c.liste(.ueberzaehlig) } } public var leer: String? public var raeume: [Raum] = [] public var fenster: Fenster? enum CodingKeys: String, CodingKey { case leer, raeume, fenster } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) leer = c.text(.leer); raeume = c.objekte(.raeume); fenster = try? c.decodeIfPresent(Fenster.self, forKey: .fenster) } } public struct Anteile: Decodable, Equatable, Sendable { public var t: Double? public var fold = 0.0, check = 0.0, call = 0.0, raise = 0.0, allin = 0.0 public var n: Int? enum CodingKeys: String, CodingKey { case t, fold, check, call, raise, allin, n } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) t = c.zahl(.t); fold = c.zahl(.fold) ?? 0; check = c.zahl(.check) ?? 0; call = c.zahl(.call) ?? 0 raise = c.zahl(.raise) ?? 0; allin = c.zahl(.allin) ?? 0; n = c.zahl(.n).map { Int($0) } } } public struct Stil: Decodable, Equatable, Sendable { public struct Groesse: Decodable, Equatable, Sendable { public var betragBB: Double? public var topfAnteil: Double? enum CodingKeys: String, CodingKey { case betragBB = "betrag_bb", topfAnteil = "topf_anteil" } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) betragBB = c.zahl(.betragBB); topfAnteil = c.zahl(.topfAnteil) } } public struct Denkzeit: Decodable, Equatable, Sendable { public var median: Double? public var streuung: Double? public var vk: Double? public var n: Int? enum CodingKeys: String, CodingKey { case median, streuung, vk, n } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) median = c.zahl(.median); streuung = c.zahl(.streuung); vk = c.zahl(.vk); n = c.zahl(.n).map { Int($0) } } } public var leer: String? public var verlauf: [Anteile] = [] public var groessen: [Groesse] = [] public var denkzeiten: [Double] = [] public var denkzeit: Denkzeit? public var anteile: Anteile? enum CodingKeys: String, CodingKey { case leer, verlauf, groessen, denkzeiten, denkzeit, anteile } private struct S: Decodable { var s: Double? } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) leer = c.text(.leer); verlauf = c.objekte(.verlauf); groessen = c.objekte(.groessen) denkzeiten = (c.objekte(.denkzeiten) as [S]).compactMap(\.s) denkzeit = try? c.decodeIfPresent(Denkzeit.self, forKey: .denkzeit) anteile = try? c.decodeIfPresent(Anteile.self, forKey: .anteile) } } public struct TickerZeile: Decodable, Equatable, Sendable, Identifiable { public var zeit: Double? public var art: String? public var raum: String? public var text: String? public var id: String { "\(zeit ?? 0)|\(art ?? "")|\(raum ?? "")|\(text ?? "")" } enum CodingKeys: String, CodingKey { case zeit, art, raum, text } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) zeit = c.zahl(.zeit); art = c.text(.art); raum = c.text(.raum); text = c.text(.text) } } public struct Ticker: Decodable, Equatable, Sendable { public var leer: String? public var zeilen: [TickerZeile] = [] public var gedanken: [String] = [] enum CodingKeys: String, CodingKey { case leer, zeilen, gedanken } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) leer = c.text(.leer); zeilen = c.objekte(.zeilen); gedanken = c.liste(.gedanken) } }