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>
83 lines
3.3 KiB
Swift
83 lines
3.3 KiB
Swift
import Foundation
|
|
|
|
// Regeln fuer das Panel ueber den Tischen. Die Dateien in sicht/scratch/ sind der Vertrag mit dem
|
|
// Bot (hand/act.py, hand/dialog.py, sicht/tische.py).
|
|
|
|
public enum EscFolge: Equatable, Sendable { case eigene, notAus, ruhe }
|
|
|
|
public enum EscRegel {
|
|
/// So lange gilt ein ESC als das eigene des Bots, nachdem er sicht/scratch/eigene_taste anlegte.
|
|
public static let eigeneFrist = 1.5
|
|
|
|
/// ESC gedrueckt: Not-Aus, wenn der Bot laeuft und die Taste nicht seine eigene war.
|
|
/// `laeuft == nil` (unbekannt): im Zweifel anhalten.
|
|
public static func entscheiden(eigeneTasteAlter: Double?, laeuft: Bool?) -> EscFolge {
|
|
if let a = eigeneTasteAlter, a < eigeneFrist { return .eigene }
|
|
return laeuft == false ? .ruhe : .notAus
|
|
}
|
|
}
|
|
|
|
public enum Ausweichen {
|
|
/// So lange tritt das Panel zur Seite, nachdem hand/act.py sicht/scratch/ausweichen schrieb.
|
|
public static let frist = 2.5
|
|
|
|
public static func aktiv(dateiAlter: Double?) -> Bool {
|
|
guard let a = dateiAlter else { return false }
|
|
return a < frist
|
|
}
|
|
}
|
|
|
|
public enum Rahmen {
|
|
/// AppKit-Rahmen (Ursprung unten links) in Bildschirmpunkte oben links, wie act.py klickt.
|
|
public static func obenLinks(x: Double, y: Double, breite: Double, hoehe: Double, hauptHoehe: Double) -> [Int] {
|
|
[x, hauptHoehe - y - hoehe, breite, hoehe].map { Int($0.rounded()) }
|
|
}
|
|
|
|
/// Inhalt von sicht/scratch/cockpit.json.
|
|
public static func datei(rect: [Int], zeit: Double) -> Data {
|
|
(try? JSONSerialization.data(withJSONObject: ["rect": rect, "zeit": zeit] as [String: Any])) ?? Data()
|
|
}
|
|
}
|
|
|
|
public struct Flaeche: Equatable, Sendable {
|
|
public var x, y, breite, hoehe: Double
|
|
|
|
public init(x: Double, y: Double, breite: Double, hoehe: Double) {
|
|
self.x = x; self.y = y; self.breite = breite; self.hoehe = hoehe
|
|
}
|
|
}
|
|
|
|
public enum Seite: String, Sendable, CaseIterable { case links, rechts }
|
|
|
|
/// Wohin das Panel gehoert - in AppKit-Koordinaten (Ursprung unten links), `in` ist der sichtbare
|
|
/// Bereich des Bildschirms (ohne Menueleiste und Dock).
|
|
public enum Platzierung {
|
|
public static let abstand = 12.0
|
|
|
|
public static func leiste(in s: Flaeche, seite: Seite, breite: Double) -> Flaeche {
|
|
let b = min(breite, (s.breite / 2).rounded(.down))
|
|
let x = seite == .links ? s.x : s.x + s.breite - b
|
|
return Flaeche(x: x, y: s.y, breite: b, hoehe: s.hoehe)
|
|
}
|
|
|
|
public static func pille(in s: Flaeche, seite: Seite, breite: Double, hoehe: Double) -> Flaeche {
|
|
let x = seite == .links ? s.x + abstand : s.x + s.breite - breite - abstand
|
|
return Flaeche(x: x, y: s.y + s.hoehe - hoehe - abstand, breite: breite, hoehe: hoehe)
|
|
}
|
|
|
|
public static func naechsteSeite(mitteX: Double, in s: Flaeche) -> Seite {
|
|
mitteX < s.x + s.breite / 2 ? .links : .rechts
|
|
}
|
|
}
|
|
|
|
/// Die Not-Aus-Dateien - dieselben wie mcp/stopp.py (STOPP_PFADE). Die App schreibt sie bei ESC
|
|
/// und ⌃⌥⌘S selbst: sofort und auch dann, wenn der Python-Server haengt oder fehlt.
|
|
public enum NotAusDateien {
|
|
public static let inhalt = "not-aus"
|
|
|
|
public static func pfade(shell: String) -> [String] {
|
|
let wurzel = shell.hasSuffix("/") ? String(shell.dropLast()) : shell
|
|
return ["scratch/stop", "hand/scratch/stop", "betrieb/scratch/stop"].map { wurzel + "/" + $0 }
|
|
}
|
|
}
|