Bisher 12 an fuenf Stellen (geld, spielplan, Rust/WinUI/Swift-Cockpit), laufwache 6, harter Prozessdeckel 14 per Umgebung. Jetzt eine Zahl in lesen/geld.py; spielplan, laufwache und tischdeckel (hart = Grenze + 2 Tauschluft) lesen sie, der Server liefert sie als kopf.tische_hoechstens, die drei Cockpits lesen sie von dort. Wie viele Tische wirklich laufen, entscheidet weiter der Spielplan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
5.0 KiB
Swift
107 lines
5.0 KiB
Swift
import CockpitKern
|
|
import Foundation
|
|
|
|
// Ohne `import Testing` in dieser Datei: die Command Line Tools liefern das Overlay
|
|
// _Testing_Foundation leer aus, es darf nie zusammen mit Foundation importiert werden.
|
|
|
|
enum Hilfen {
|
|
/// Die Tisch-Obergrenze, wie der Server sie schickt (kopf.tische_hoechstens) - fuer die Pruefungen 12.
|
|
static func grenze() -> Int {
|
|
Spielplan.hoechstensSetzen(12)
|
|
return 12
|
|
}
|
|
|
|
static func ersetzt(_ text: String, _ alt: String, _ neu: String) -> String {
|
|
text.replacingOccurrences(of: alt, with: neu)
|
|
}
|
|
|
|
static func fixture(_ name: String = "ansicht") -> String? {
|
|
guard let url = Bundle.module.url(forResource: name, withExtension: "json", subdirectory: "Fixtures") else { return nil }
|
|
return try? String(contentsOf: url, encoding: .utf8)
|
|
}
|
|
|
|
/// Die Ansicht "Stimme & KI", wie sicht/anbieter_knoepfe.py sie schickt (Fixtures/anbieter.json) -
|
|
/// auf Wunsch mit einer Ersetzung im Text.
|
|
static func anbieter(ersetzt: (String, String)? = nil) -> Anbieter? {
|
|
guard let text = fixture("anbieter") else { return nil }
|
|
let t = ersetzt.map { text.replacingOccurrences(of: $0.0, with: $0.1) } ?? text
|
|
return Anbieter.aus(try? JSONSerialization.jsonObject(with: Data(t.utf8)))
|
|
}
|
|
|
|
/// Die Antwort eines Knopfs, die die Ansicht "Stimme & KI" mitbringt.
|
|
static func rueckmeldungMitAnbieter() -> Rueckmeldung? {
|
|
guard let text = fixture("anbieter"), let objekt = try? JSONSerialization.jsonObject(with: Data(text.utf8)) else { return nil }
|
|
return Rueckmeldung(json: ["ok": true, "text": "ElevenLabs gesichert", "anbieter": objekt])
|
|
}
|
|
|
|
static func rueckmeldung(_ json: [String: Any]) -> Rueckmeldung? {
|
|
Rueckmeldung(json: json)
|
|
}
|
|
|
|
/// Die Ansicht "Sendung", wie sicht/sendung_knoepfe.py sie schickt (Fixtures/sendung*.json, echte Antworten).
|
|
static func sendung(_ name: String = "sendung", ersetzt: (String, String)? = nil) -> Sendung? {
|
|
guard let text = fixture(name) else { return nil }
|
|
let t = ersetzt.map { text.replacingOccurrences(of: $0.0, with: $0.1) } ?? text
|
|
return Sendung.aus(try? JSONSerialization.jsonObject(with: Data(t.utf8)))
|
|
}
|
|
|
|
/// Eine Rueckmeldung, die die Ansicht "Sendung" mitbringt - ein Knopf oder eine Meldung des Chatfadens.
|
|
static func rueckmeldungMitSendung(aktion: String) -> Rueckmeldung? {
|
|
guard let text = fixture("sendung"), let objekt = try? JSONSerialization.jsonObject(with: Data(text.utf8)) else { return nil }
|
|
return Rueckmeldung(json: ["ok": true, "text": "", "aktion": aktion, "sendung": objekt])
|
|
}
|
|
|
|
/// Was Sendung.verbindenDaten / zuruecknehmenDaten zum Server schicken, wieder gelesen.
|
|
static func gesendetObjekt(_ text: String) -> [String: String] {
|
|
let j = (try? JSONSerialization.jsonObject(with: Data(text.utf8))) as? [String: Any] ?? [:]
|
|
return j.mapValues { "\($0)" }
|
|
}
|
|
|
|
/// Was Anbieter.daten zum Server schickt, wieder gelesen.
|
|
static func gesendet(_ text: String) -> (art: String?, anbieter: String?, werte: [String: String]?) {
|
|
let j = (try? JSONSerialization.jsonObject(with: Data(text.utf8))) as? [String: Any]
|
|
return (j?["art"] as? String, j?["anbieter"] as? String, j?["werte"] as? [String: String])
|
|
}
|
|
|
|
/// Ein Spielplan, wie ihn kopf.spielplan schickt.
|
|
static func spielplan(_ json: String) -> Spielplan? {
|
|
try? JSONDecoder().decode(Spielplan.self, from: Data(json.utf8))
|
|
}
|
|
|
|
/// Kurven eines Modus (wachstum.je_modus.uebung), so dekodiert wie in der App.
|
|
static func kurven(_ json: String) -> Kurven? {
|
|
try? JSONDecoder().decode(Kurven.self, from: Data(json.utf8))
|
|
}
|
|
|
|
/// Ein `modus`-Objekt der Ansicht, so dekodiert wie in der App.
|
|
static func modus(_ json: String) -> TischModus? {
|
|
try? JSONDecoder().decode(TischModus.self, from: Data(json.utf8))
|
|
}
|
|
|
|
/// Ein `konto`-Objekt der Kopfzeile, so dekodiert wie in der App.
|
|
static func kopf(_ json: String) -> Kopf? {
|
|
try? JSONDecoder().decode(Kopf.self, from: Data(json.utf8))
|
|
}
|
|
|
|
static func konto(_ json: String) -> Konto? {
|
|
try? JSONDecoder().decode(Konto.self, from: Data(json.utf8))
|
|
}
|
|
|
|
/// (rect, zeit) aus der Rahmendatei, wie hand/act.py sie liest.
|
|
static func rahmenLesen(_ d: Data) -> ([Int]?, Double?) {
|
|
let j = (try? JSONSerialization.jsonObject(with: d)) as? [String: Any]
|
|
return (j?["rect"] as? [Int], j?["zeit"] as? Double)
|
|
}
|
|
|
|
/// Form, Seite und Mindestbreite aus der Rahmendatei, wie sicht/tische.py sie liest.
|
|
static func rahmenAngaben(_ d: Data) -> (form: String?, seite: String?, mindestbreite: Double?) {
|
|
let j = (try? JSONSerialization.jsonObject(with: d)) as? [String: Any]
|
|
return (j?["form"] as? String, j?["seite"] as? String, (j?["mindestbreite"] as? NSNumber)?.doubleValue)
|
|
}
|
|
|
|
/// Ein Leistenziel aus dem Text von cockpit_ziel.json.
|
|
static func ziel(_ text: String) -> Leistenziel? {
|
|
Leistenziel.lesen(Data(text.utf8))
|
|
}
|
|
}
|