Fix: Absturz beim Entfernen von Teams (Bindings per ID); Matchday nur per Schalter (Einstellungen, Bild-Menü ⌘⌥M, Trikot-Erkennung); Ereignis/Datum vom aktuellen Bild; 'Spieler:innen'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
This commit is contained in:
1 parent
cea5decdb6
commit
2989e51553
7 files changed
+60
-23
No files matched your search
@@ -74,9 +74,9 @@ struct JerseySetupView: View {
|
||||
Text("Pro Spiel die Teams wählen und die Trikotfarbe festlegen. Lichtkasten liest Nummern auf Trikot und Hose, bestimmt das Team über die Farbe und schlägt den Spieler aus deinen Code-Ersetzungen vor (Präfix + Nummer, z. B. w10).")
|
||||
.font(.callout).foregroundStyle(.secondary)
|
||||
|
||||
ForEach(state.settings.jersey.teams) { t in
|
||||
if let i = state.settings.jersey.teams.firstIndex(where: { $0.id == t.id }) { teamRow(i) }
|
||||
}
|
||||
Toggle("Matchday-Ansicht verwenden (Teamleiste, Spieler:innen-Liste, Teamfarben in den Kacheln)",
|
||||
isOn: jersey.matchday)
|
||||
ForEach(state.settings.jersey.teams) { t in teamRow(t.id) }
|
||||
HStack {
|
||||
Menu("Team hinzufügen") {
|
||||
ForEach(state.codeLibrary.sets) { set in
|
||||
@@ -126,9 +126,28 @@ struct JerseySetupView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Binding by id – stays valid while a team is being removed (index-based bindings crashed here).
|
||||
private func teamBinding(_ id: UUID) -> Binding<JerseyTeam> {
|
||||
Binding(
|
||||
get: { state.settings.jersey.teams.first { $0.id == id }
|
||||
?? JerseyTeam(name: "", prefix: "", shirtColor: KitColor(r: 0, g: 0, b: 0)) },
|
||||
set: { new in
|
||||
if let i = state.settings.jersey.teams.firstIndex(where: { $0.id == id }) { state.settings.jersey.teams[i] = new }
|
||||
})
|
||||
}
|
||||
|
||||
private func remove(_ id: UUID) {
|
||||
if target?.team == id { target = nil }
|
||||
// after the current view update – removing inside it invalidates the row's bindings
|
||||
DispatchQueue.main.async {
|
||||
state.settings.jersey.teams.removeAll { $0.id == id }
|
||||
if target == nil, let first = state.settings.jersey.teams.first { target = PickTarget(team: first.id, shorts: false) }
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func teamRow(_ i: Int) -> some View {
|
||||
let team = jersey.teams[i]
|
||||
private func teamRow(_ id: UUID) -> some View {
|
||||
let team = teamBinding(id)
|
||||
GroupBox {
|
||||
HStack(spacing: 12) {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
@@ -136,34 +155,34 @@ struct JerseySetupView: View {
|
||||
HStack {
|
||||
Text("Code-Präfix")
|
||||
TextField("w", text: team.prefix).frame(width: 50).textFieldStyle(.roundedBorder)
|
||||
Text(example(state.settings.jersey.teams[i]))
|
||||
Text(example(team.wrappedValue))
|
||||
.font(.caption).foregroundStyle(.secondary).lineLimit(1)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
swatchButton(i, shorts: false)
|
||||
swatchButton(team.wrappedValue, shorts: false)
|
||||
Toggle("Hose", isOn: Binding(
|
||||
get: { state.settings.jersey.teams[i].shortsColor != nil },
|
||||
get: { team.wrappedValue.shortsColor != nil },
|
||||
set: { on in
|
||||
state.settings.jersey.teams[i].shortsColor = on ? state.settings.jersey.teams[i].shirtColor : nil
|
||||
if on { target = PickTarget(team: state.settings.jersey.teams[i].id, shorts: true) }
|
||||
team.wrappedValue.shortsColor = on ? team.wrappedValue.shirtColor : nil
|
||||
if on { target = PickTarget(team: id, shorts: true) }
|
||||
}))
|
||||
.toggleStyle(.checkbox)
|
||||
.help("Eigene Hosenfarbe (z. B. weißes Trikot, grüne Hose)")
|
||||
if state.settings.jersey.teams[i].shortsColor != nil { swatchButton(i, shorts: true) }
|
||||
if team.wrappedValue.shortsColor != nil { swatchButton(team.wrappedValue, shorts: true) }
|
||||
ColorPicker("", selection: cgBinding(team.shirtColor), supportsOpacity: false)
|
||||
.labelsHidden()
|
||||
.help("Alternativ: Farbe manuell wählen")
|
||||
Button(role: .destructive) { state.settings.jersey.teams.remove(at: i) } label: { Image(systemName: "trash") }
|
||||
Button(role: .destructive) { remove(id) } label: { Image(systemName: "trash") }
|
||||
.buttonStyle(.borderless)
|
||||
.help("Team entfernen")
|
||||
}
|
||||
.padding(4)
|
||||
}
|
||||
}
|
||||
|
||||
/// Color swatch; click = "next click in the photo sets this color".
|
||||
private func swatchButton(_ i: Int, shorts: Bool) -> some View {
|
||||
let team = state.settings.jersey.teams[i]
|
||||
private func swatchButton(_ team: JerseyTeam, shorts: Bool) -> some View {
|
||||
let c = shorts ? (team.shortsColor ?? team.shirtColor) : team.shirtColor
|
||||
let active = target == PickTarget(team: team.id, shorts: shorts)
|
||||
return Button { target = PickTarget(team: team.id, shorts: shorts) } label: {
|
||||
|
||||
Reference in new issue
Block a user