Betrug: Kennzeichen haengen der Sitzung an; schwarze Stunden 0-5 gemessen; drei Hebel (lesen, Verhalten, Nachpruefung) und Selbststart zum Testen
This commit is contained in:
@@ -3,7 +3,9 @@ import SwiftUI
|
||||
|
||||
/// Was gespielt wird: je Format eine Karte mit Tischzahl. Mehrere Formate gleichzeitig; die Summe
|
||||
/// ist die Tischzahl. Ein Format, dessen Lobby-Weg nicht gemessen ist, lässt sich wählen - der
|
||||
/// Läufer öffnet dort aber nichts und sagt es (lesen/formate.py).
|
||||
/// Läufer öffnet dort aber nichts und sagt es (lesen/formate.py). Mit "Ausweichen" zählt ein
|
||||
/// Tischziel: die Zahlen sind Obergrenzen, gefüllt wird in der gezeigten Folge, und ein Format ohne
|
||||
/// freie Tische wird übersprungen (betrieb/spielplan.py).
|
||||
struct FormatWahl: View {
|
||||
@Environment(Cockpit.self) private var cockpit
|
||||
private let spalten = [GridItem(.flexible(), spacing: 6), GridItem(.flexible(), spacing: 6)]
|
||||
@@ -16,16 +18,32 @@ struct FormatWahl: View {
|
||||
Text("Was spielen").font(.caption2.weight(.medium)).foregroundStyle(.secondary)
|
||||
Spacer()
|
||||
Text(zusammen(w)).font(.caption2).foregroundStyle(.secondary).monospacedDigit()
|
||||
Toggle("Ausweichen", isOn: Binding(get: { w.ziel != nil }, set: { cockpit.wahl.ausweichen(an: $0) }))
|
||||
.toggleStyle(.button).controlSize(.mini).font(.caption2)
|
||||
.help("Ein Tischziel: gibt es von einem Format zu wenig freie Tische, nimmt er das nächste")
|
||||
}
|
||||
if let ziel = w.ziel {
|
||||
Stepper("Ziel: \(ziel) Tisch\(ziel == 1 ? "" : "e") · Zahlen unten sind Obergrenzen", value: Binding(
|
||||
get: { ziel }, set: { cockpit.wahl.ziel = $0 }), in: 1...Spielplan.hoechstens)
|
||||
.font(.caption2).foregroundStyle(.secondary)
|
||||
}
|
||||
LazyVGrid(columns: spalten, spacing: 6) {
|
||||
ForEach(SpielFormat.allCases) { f in
|
||||
ForEach(reihe(w)) { f in
|
||||
let rang = w.ziel == nil ? nil : w.folge.firstIndex(of: f)
|
||||
FormatKarte(format: f, anzahl: w.anzahl(f), gemessen: gemessen.contains(f),
|
||||
voll: w.tische >= Spielplan.hoechstens) { cockpit.wahl.setzen(f, $0) }
|
||||
voll: w.ziel == nil ? w.tische >= Spielplan.hoechstens : w.anzahl(f) >= Spielplan.hoechstens,
|
||||
rang: rang, vorziehen: { cockpit.wahl.vorziehen(f) }) { cockpit.wahl.setzen(f, $0) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Mit Ausweichen die gewählten in Füllfolge zuerst; sonst fest wie immer.
|
||||
private func reihe(_ w: Spielplan) -> [SpielFormat] {
|
||||
guard w.ziel != nil else { return SpielFormat.allCases }
|
||||
return w.folge + SpielFormat.allCases.filter { !w.folge.contains($0) }
|
||||
}
|
||||
|
||||
private func zusammen(_ w: Spielplan) -> String {
|
||||
w.tische == 0 ? "nichts gewählt" : "\(w.tische) Tisch\(w.tische == 1 ? "" : "e") zusammen"
|
||||
}
|
||||
@@ -36,6 +54,8 @@ private struct FormatKarte: View {
|
||||
var anzahl: Int
|
||||
var gemessen: Bool
|
||||
var voll: Bool
|
||||
var rang: Int? // Platz in der Füllfolge (nur mit Ausweichen)
|
||||
var vorziehen: () -> Void
|
||||
var setzen: (Int) -> Void
|
||||
|
||||
private var an: Bool { anzahl > 0 }
|
||||
@@ -53,6 +73,10 @@ private struct FormatKarte: View {
|
||||
}
|
||||
}
|
||||
Spacer(minLength: 2)
|
||||
if let rang, rang > 0 {
|
||||
Button(action: vorziehen) { Image(systemName: "arrow.up").frame(width: 14, height: 18) }
|
||||
.help("In der Füllfolge nach vorn (jetzt Platz \(rang + 1))")
|
||||
}
|
||||
if an {
|
||||
Button { setzen(anzahl - 1) } label: { Image(systemName: "minus").frame(width: 16, height: 18) }
|
||||
Text("\(anzahl)").font(.system(.callout, design: .rounded).weight(.semibold)).monospacedDigit()
|
||||
|
||||
@@ -68,7 +68,7 @@ struct PlanKacheln: View {
|
||||
.frame(maxWidth: .infinity, alignment: .leading).contentTransition(.numericText())
|
||||
.animation(.snappy, value: w.tische)
|
||||
} fuss: {
|
||||
Text(cockpit.laeuft == true ? "\(cockpit.ansicht.kopf?.tischeOffen ?? 0) offen" : "füllt der Läufer auf")
|
||||
Text(cockpit.laeuft == true ? "\(cockpit.ansicht.kopf?.tischeOffen ?? 0) von \(w.tische) offen" : "füllt der Läufer auf")
|
||||
}
|
||||
Kachel(titel: w.live ? "Budget" : "Geld") {
|
||||
if w.live {
|
||||
|
||||
@@ -52,7 +52,7 @@ private struct ZuschauerTischKarte: View {
|
||||
farbe: t.modus == "uebung" ? .blue : .red)
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
MiniTisch(plaetze: max(t.tisch.spieler.map(\.sitz).max() ?? 6, 6), board: t.board, topf: nil, zug: nil, tisch: t.tisch)
|
||||
MiniTisch(plaetze: max(t.tisch.spieler.map(\.sitz).max() ?? 6, 6), board: t.board, topf: t.topf, zug: nil, tisch: t.tisch)
|
||||
if let n = t.amZug?.name {
|
||||
Text("Am Zug: \(n)" + (t.amZug?.fristS.map { " · Frist \(Int($0)) s" } ?? ""))
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
|
||||
@@ -14,10 +14,29 @@ public struct Spielplan: Equatable, Sendable, Decodable {
|
||||
public private(set) var formate: [SpielFormat: Int]
|
||||
/// Welche Formate der Läufer öffnen kann (kopf.spielplan.formate_liste) - nur vom Server, nie gesendet.
|
||||
public var gemessen: Set<SpielFormat> = [.cash]
|
||||
/// Alle Tische zusammen. Setzen ändert Cash (die anderen Formate bleiben).
|
||||
/// Tische insgesamt (Ausweichen): die Zahl je Format ist dann die Obergrenze. Ohne: die Summe zählt.
|
||||
public var ziel: Int? {
|
||||
didSet {
|
||||
ziel = ziel.map { max(1, min(Self.hoechstens, $0)) }
|
||||
tischeBis = Self.spanne(tische, tischeBis)
|
||||
}
|
||||
}
|
||||
/// Füllfolge, wenn sie von der Vorgabe abweicht (betrieb/spielplan.py `reihenfolge`).
|
||||
private var reihenfolge: [SpielFormat] = []
|
||||
/// Alle Tische zusammen. Setzen ändert das Ziel oder sonst Cash (die anderen Formate bleiben).
|
||||
public var tische: Int {
|
||||
get { formate.values.reduce(0, +) }
|
||||
set { setzen(.cash, newValue - (tische - anzahl(.cash))) }
|
||||
get {
|
||||
let summe = formate.values.reduce(0, +)
|
||||
return ziel.map { min($0, summe) } ?? summe
|
||||
}
|
||||
set {
|
||||
if ziel != nil { ziel = newValue } else { setzen(.cash, newValue - (tische - anzahl(.cash))) }
|
||||
}
|
||||
}
|
||||
/// Die gewählten Formate in Füllfolge.
|
||||
public var folge: [SpielFormat] {
|
||||
let genannt = reihenfolge.filter { anzahl($0) > 0 }
|
||||
return genannt + SpielFormat.allCases.filter { anzahl($0) > 0 && !genannt.contains($0) }
|
||||
}
|
||||
public var budget: Double?
|
||||
/// Tischspanne tische..tischeBis, je Sitzung gewürfelt; nil oder nicht über tische: keine Spanne.
|
||||
@@ -41,15 +60,48 @@ public struct Spielplan: Equatable, Sendable, Decodable {
|
||||
|
||||
/// Tische eines Formats: nicht unter 0, die Summe nicht über `hoechstens`.
|
||||
public mutating func setzen(_ f: SpielFormat, _ n: Int) {
|
||||
let andere = tische - anzahl(f)
|
||||
let neu = max(0, min(n, Self.hoechstens - andere))
|
||||
let grenze = ziel != nil ? Self.hoechstens : Self.hoechstens - (tische - anzahl(f))
|
||||
let neu = max(0, min(n, grenze))
|
||||
let davor = folge
|
||||
formate[f] = neu > 0 ? neu : nil
|
||||
ordnen(davor.filter { anzahl($0) > 0 } + folge.filter { !davor.contains($0) })
|
||||
tischeBis = Self.spanne(tische, tischeBis)
|
||||
}
|
||||
|
||||
/// Ausweichen an: das Ziel ist die jetzige Tischzahl. Aus: die Summe zählt wieder, die Formate
|
||||
/// hinten in der Füllfolge werden unter `hoechstens` gekürzt.
|
||||
public mutating func ausweichen(an: Bool) {
|
||||
if an {
|
||||
ziel = max(1, tische)
|
||||
return
|
||||
}
|
||||
let reihe = folge
|
||||
ziel = nil
|
||||
var rest = Self.hoechstens
|
||||
for f in reihe {
|
||||
let n = min(anzahl(f), rest)
|
||||
formate[f] = n > 0 ? n : nil
|
||||
rest -= n
|
||||
}
|
||||
tischeBis = Self.spanne(tische, tischeBis)
|
||||
}
|
||||
|
||||
/// Ein Format in der Füllfolge einen Platz nach vorn.
|
||||
public mutating func vorziehen(_ f: SpielFormat) {
|
||||
var reihe = folge
|
||||
guard let i = reihe.firstIndex(of: f), i > 0 else { return }
|
||||
reihe.swapAt(i, i - 1)
|
||||
ordnen(reihe)
|
||||
}
|
||||
|
||||
/// Die Vorgabe (Folge wie `allCases`) bleibt leer - so vergleichen sich Pläne und die Datei bleibt schlank.
|
||||
private mutating func ordnen(_ reihe: [SpielFormat]) {
|
||||
reihenfolge = reihe == SpielFormat.allCases.filter(reihe.contains) ? [] : reihe
|
||||
}
|
||||
private static func spanne(_ von: Int, _ bis: Int?) -> Int? { bis.flatMap { $0 > von ? min($0, hoechstens) : nil } }
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case modus, tische, budget, zeiger, tischeBis = "tische_bis", zeitplan, geld, formate
|
||||
case modus, tische, budget, ziel, reihenfolge, zeiger, tischeBis = "tische_bis", zeitplan, geld, formate
|
||||
case formateListe = "formate_liste"
|
||||
}
|
||||
|
||||
@@ -61,6 +113,7 @@ public struct Spielplan: Equatable, Sendable, Decodable {
|
||||
throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "kein Spielplan"))
|
||||
}
|
||||
self.init(modus: m, tische: Int(n), budget: c.zahl(.budget))
|
||||
ziel = c.zahl(.ziel).map { Int($0) }
|
||||
tischeBis = Self.spanne(tische, c.zahl(.tischeBis).map { Int($0) })
|
||||
zeiger = c.wahr(.zeiger)
|
||||
zeitplan = ((try? c.decodeIfPresent(Zeitplan.self, forKey: .zeitplan)) ?? nil) ?? .ohne
|
||||
@@ -68,6 +121,11 @@ public struct Spielplan: Equatable, Sendable, Decodable {
|
||||
if let roh = (try? c.decodeIfPresent([String: Double].self, forKey: .formate)) ?? nil {
|
||||
formate = [:]
|
||||
for f in SpielFormat.allCases { if let n = roh[f.rawValue] { setzen(f, Int(n)) } }
|
||||
tischeBis = Self.spanne(tische, c.zahl(.tischeBis).map { Int($0) })
|
||||
}
|
||||
if let namen = (try? c.decodeIfPresent([String].self, forKey: .reihenfolge)) ?? nil {
|
||||
let genannt = namen.compactMap(SpielFormat.init(rawValue:))
|
||||
ordnen(genannt.filter { anzahl($0) > 0 } + folge.filter { !genannt.contains($0) })
|
||||
}
|
||||
if let liste = (try? c.decodeIfPresent([FormatInfo].self, forKey: .formateListe)) ?? nil {
|
||||
gemessen = Set(liste.filter(\.gemessen).compactMap { SpielFormat(rawValue: $0.format) })
|
||||
@@ -80,6 +138,8 @@ public struct Spielplan: Equatable, Sendable, Decodable {
|
||||
if Set(formate.keys) != [.cash] { // nur Cash ist die Vorgabe und bleibt weg
|
||||
d["formate"] = Dictionary(uniqueKeysWithValues: formate.map { ($0.key.rawValue, $0.value) })
|
||||
}
|
||||
if let ziel { d["ziel"] = ziel }
|
||||
if !reihenfolge.isEmpty { d["reihenfolge"] = reihenfolge.map(\.rawValue) }
|
||||
if live, let budget { d["budget"] = budget }
|
||||
if let tischeBis { d["tische_bis"] = tischeBis }
|
||||
if zeiger { d["zeiger"] = true }
|
||||
|
||||
@@ -110,14 +110,16 @@ public struct ZuschauerTisch: Decodable, Equatable, Sendable {
|
||||
public var raum: String?
|
||||
public var modus: String?
|
||||
public var board: [String] = []
|
||||
/// In Chips, wie der Tisch ihn zeigt (game.potInfo); fehlt, solange die Hand keinen meldet.
|
||||
public var topf: Double?
|
||||
public var amZug: AmZug?
|
||||
public var hinweis: String?
|
||||
public var tisch: TischAnsicht
|
||||
|
||||
enum CodingKeys: String, CodingKey { case raum, modus, board, hinweis, amZug = "am_zug" }
|
||||
enum CodingKeys: String, CodingKey { case raum, modus, board, topf, hinweis, amZug = "am_zug" }
|
||||
public init(from d: Decoder) throws {
|
||||
let c = try d.container(keyedBy: CodingKeys.self)
|
||||
raum = c.text(.raum); modus = c.text(.modus); board = c.liste(.board); hinweis = c.text(.hinweis)
|
||||
raum = c.text(.raum); modus = c.text(.modus); board = c.liste(.board); topf = c.zahl(.topf); hinweis = c.text(.hinweis)
|
||||
amZug = (try? c.decodeIfPresent(AmZug.self, forKey: .amZug)) ?? nil
|
||||
tisch = try TischAnsicht(from: d)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user