Files
pokerfreak/mac/Sources/CockpitKern/Fenster.swift
T
mmintel f2650dc3be Cockpit and runner 5.11. late: no ESC stop, hidden tables stay open, gapless tiling, teacher core
- ESC no longer triggers the emergency stop (an ESC in another app stopped the run at 20:29);
  stopping only via ctrl-opt-cmd-S or the stop button
- a table whose program runs counts as open even when its window is not visible (other
  desktop, Cockpit without screen recording): no reopening, no giving up, correct table
  count; teardown and closing a full table work over the channel
- Cockpit checks and requests the screen recording permission
- gapless tiling (sicht/kacheln.py): tables fill the full height, the Cockpit bar takes the
  rest and never goes below its minimum width; own animated resize no longer stored as minimum
- earlier today: top-up safety net, leave after the hand (sit out next hand), tournament lock,
  waitlist left on close, Cockpit start lock, warning throttle, preflop raise-war reading,
  Bomb Pot practice, tournament break and level-up on the stage
- teacher core for the streamer mode (betrieb/lehrer.py, betrieb/grund_lesen.py) and its plan
2026-11-05 22:39:41 +01:00

107 lines
4.7 KiB
Swift

import Foundation
// Regeln fuer das Panel ueber den Tischen. Die Dateien in sicht/scratch/ sind der Vertrag mit dem
// Laeufer (hand/act.py, sicht/tische.py).
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 - fuer den Kachler (sicht/tische.py) auch Form ("leiste",
/// "pille"), Seite und die Mindestbreite der Leiste: er kachelt lueckenlos und gibt ihr den Rest.
public static func datei(rect: [Int], zeit: Double, form: String? = nil, seite: String? = nil,
mindestbreite: Double? = nil) -> Data {
var d: [String: Any] = ["rect": rect, "zeit": zeit]
if let form { d["form"] = form }
if let seite { d["seite"] = seite }
if let mindestbreite { d["mindestbreite"] = mindestbreite }
return (try? JSONSerialization.data(withJSONObject: d)) ?? Data()
}
}
/// So breit soll die Leiste werden: der Rest neben den lueckenlosen Kacheln (sicht/tische.py schreibt
/// sicht/scratch/cockpit_ziel.json). Es gilt nur fuer genau den Tischstand, fuer den gerechnet wurde -
/// bis neu gekachelt ist, die eigene Breite; nie schmaler als sie.
public struct Leistenziel: Equatable, Sendable {
public var breite: Double
public var tische: Int
public init(breite: Double, tische: Int) {
self.breite = breite; self.tische = tische
}
public static func lesen(_ d: Data) -> Leistenziel? {
guard let j = (try? JSONSerialization.jsonObject(with: d)) as? [String: Any],
let breite = (j["breite"] as? NSNumber)?.doubleValue,
let tische = (j["tische"] as? NSNumber)?.intValue else { return nil }
return Leistenziel(breite: breite, tische: tische)
}
public static func wirksam(mindest: Double, ziel: Leistenziel?, tischeOffen: Int?) -> Double {
guard let z = ziel, let offen = tischeOffen, offen > 0, z.tische == offen else { return mindest }
return max(mindest, z.breite)
}
}
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)
}
/// Die Leiste als Rest neben den Kacheln (Leistenziel): am Rand, so breit wie verlangt - auch ueber
/// die halbe Bildschirmbreite hinaus, hoechstens der ganze Bildschirm.
public static func restleiste(in s: Flaeche, seite: Seite, breite: Double) -> Flaeche {
let b = min(breite, s.breite)
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 ⌃⌥⌘S
/// und dem Not-Aus-Knopf 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 }
}
}