Code-Ersetzungen nach Liga sortiert
- Teams haben eine Liga; beim Import ist das der Ordner der TXT (Codes/1. Bundesliga/…, 2. Bundesliga/…) - „Hinzufügen …“ nimmt auch ganze Ordner: jede TXT darin wird ein Team in ihrer Liga - Code-Fenster: Teams in Liga-Abschnitten, ganze Liga per Haken an/aus, einklappen, Suche, „In Liga verschieben“, Liga-Feld beim Team, Reihenfolge innerhalb der Liga per Ziehen - vorhandene Teams bekommen ihre Liga automatisch aus dem Ordner ihrer TXT - Spieltag-Assistent und Trikot-Erkennung zeigen die Code-Teams nach Liga gegliedert - Priorität bei doppelten Codes folgt der angezeigten Reihenfolge; Löschen ohne Index-Absturz 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
c9d43aba9c
commit
239e3de0aa
7 files changed
+223
-44
No files matched your search
@@ -977,20 +977,32 @@ final class AppState: ObservableObject {
|
||||
}
|
||||
|
||||
/// PM "Add…": each TXT becomes a team – or, if the team exists already, only new players are added.
|
||||
func importCodeFiles(into setID: UUID? = nil) {
|
||||
/// Folders can be chosen too: every TXT inside becomes a team, sorted under the league = its folder
|
||||
/// ("Codes/1. Bundesliga/…", "Codes/2. Bundesliga/…").
|
||||
func importCodeFiles(into setID: UUID? = nil, league: String? = nil) {
|
||||
let panel = NSOpenPanel()
|
||||
panel.allowsMultipleSelection = setID == nil
|
||||
panel.message = setID == nil ? "Code-Dateien (TXT, Tab-getrennt wie in PM) – jede Datei wird ein Team"
|
||||
panel.canChooseDirectories = setID == nil
|
||||
panel.message = setID == nil ? "TXT-Dateien oder Liga-Ordner wählen – jede TXT wird ein Team, der Ordner ist die Liga"
|
||||
: "TXT mit neuen Spielern – vorhandene Codes bleiben unverändert"
|
||||
guard panel.runModal() == .OK else { return }
|
||||
var lines: [String] = []
|
||||
var lib = codeLibrary
|
||||
var results: [(team: String, added: Int, existing: Int)] = []
|
||||
for url in panel.urls {
|
||||
do {
|
||||
let r = try codeLibrary.importFile(url, into: setID)
|
||||
lines.append("\(r.team): \(r.added) neu" + (r.existing > 0 ? ", \(r.existing) schon vorhanden" : ""))
|
||||
if (try? url.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) == true {
|
||||
results += try lib.importFolder(url)
|
||||
} else {
|
||||
results.append(try lib.importFile(url, into: setID, league: league))
|
||||
}
|
||||
} catch { report(error) }
|
||||
}
|
||||
statusText = lines.joined(separator: " · ")
|
||||
codeLibrary = lib // one save / rebuild for the whole import
|
||||
let added = results.reduce(0) { $0 + $1.added }
|
||||
statusText = results.count > 3
|
||||
? "\(results.count) Teams importiert, \(added) neue Codes"
|
||||
: results.map { "\($0.team): \($0.added) neu" + ($0.existing > 0 ? ", \($0.existing) schon vorhanden" : "") }
|
||||
.joined(separator: " · ")
|
||||
}
|
||||
|
||||
func reloadAllCodes() {
|
||||
|
||||
@@ -11,12 +11,14 @@ struct CodesWindow: View {
|
||||
@State private var newText = ""
|
||||
@State private var test = "w10 trifft gegen h10, "
|
||||
@State private var search = ""
|
||||
@State private var teamSearch = ""
|
||||
@State private var collapsed: Set<String> = []
|
||||
|
||||
private var teamIndex: Int? { state.codeLibrary.sets.firstIndex { $0.id == selectedTeam } }
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("Diese Teams werden für Code-Ersetzungen verwendet. Bei doppelten Codes gewinnt das obere Team.")
|
||||
Text("Teams nach Liga sortiert (Ordner der TXT). Aktive Teams werden für Code-Ersetzungen verwendet, bei doppelten Codes gewinnt das obere Team.")
|
||||
.font(.callout).foregroundStyle(.secondary)
|
||||
HSplitView {
|
||||
teamList.frame(minWidth: 300, idealWidth: 360)
|
||||
@@ -34,35 +36,30 @@ struct CodesWindow: View {
|
||||
|
||||
private var teamList: some View {
|
||||
VStack(spacing: 6) {
|
||||
TextField("Team oder Liga suchen", text: $teamSearch).textFieldStyle(.roundedBorder)
|
||||
List(selection: $selectedTeam) {
|
||||
ForEach($state.codeLibrary.sets) { $set in
|
||||
HStack {
|
||||
Toggle("", isOn: $set.enabled).toggleStyle(.checkbox).labelsHidden()
|
||||
.help("Aktiv (PM: Enable)")
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text(set.name).lineLimit(1)
|
||||
Text(set.sourcePath.map { URL(fileURLWithPath: $0).lastPathComponent } ?? "manuell")
|
||||
.font(.caption2).foregroundStyle(.secondary).lineLimit(1)
|
||||
ForEach(state.codeLibrary.leagues, id: \.self) { league in
|
||||
let list = teams(in: league)
|
||||
if !list.isEmpty {
|
||||
Section {
|
||||
if !collapsed.contains(league) || !teamSearch.isEmpty {
|
||||
ForEach(list) { set in teamRow(set) }
|
||||
.onMove(perform: teamSearch.isEmpty ? { from, to in
|
||||
state.codeLibrary.move(inLeague: league, from: from, to: to)
|
||||
} : nil)
|
||||
}
|
||||
} header: {
|
||||
leagueHeader(league)
|
||||
}
|
||||
Spacer()
|
||||
Text("\(set.entries.count)").font(.caption.monospacedDigit()).foregroundStyle(.secondary)
|
||||
}
|
||||
.tag(set.id)
|
||||
.contextMenu {
|
||||
Button("Neue Spieler aus TXT nachladen …") { state.importCodeFiles(into: set.id) }
|
||||
Button("Im Finder zeigen") {
|
||||
if let p = set.sourcePath { NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: p)]) }
|
||||
}.disabled(set.sourcePath == nil)
|
||||
Button("Löschen", role: .destructive) { remove(set.id) }
|
||||
}
|
||||
}
|
||||
.onMove { state.codeLibrary.sets.move(fromOffsets: $0, toOffset: $1) }
|
||||
}.scrollContentBackground(.hidden).background(LK.deep)
|
||||
HStack(spacing: 6) {
|
||||
Button("Hinzufügen …") { state.importCodeFiles() }
|
||||
.help("TXT-Dateien als Teams importieren (wie PM „Add…“)")
|
||||
.help("TXT-Dateien oder ganze Liga-Ordner importieren – der Ordner einer TXT wird ihre Liga")
|
||||
Button("Neues Team") {
|
||||
let s = CodeSet(name: "Neues Team")
|
||||
let league = state.codeLibrary.sets.first { $0.id == selectedTeam }?.league ?? ""
|
||||
let s = CodeSet(name: "Neues Team", league: league)
|
||||
state.codeLibrary.sets.append(s)
|
||||
selectedTeam = s.id
|
||||
}
|
||||
@@ -75,6 +72,85 @@ struct CodesWindow: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func teams(in league: String) -> [CodeSet] {
|
||||
let q = teamSearch.trimmingCharacters(in: .whitespaces)
|
||||
return state.codeLibrary.sets.filter { set in
|
||||
set.league == league && (q.isEmpty || set.name.localizedCaseInsensitiveContains(q)
|
||||
|| league.localizedCaseInsensitiveContains(q))
|
||||
}
|
||||
}
|
||||
|
||||
/// League header: checkbox for the whole league (all / none / mixed), fold, number of active teams.
|
||||
private func leagueHeader(_ league: String) -> some View {
|
||||
let all = state.codeLibrary.sets.filter { $0.league == league }
|
||||
let active = all.filter(\.enabled).count
|
||||
let icon = active == all.count ? "checkmark.square.fill" : (active == 0 ? "square" : "minus.square.fill")
|
||||
return HStack(spacing: 6) {
|
||||
Button {
|
||||
let on = active != all.count
|
||||
for i in state.codeLibrary.sets.indices where state.codeLibrary.sets[i].league == league {
|
||||
state.codeLibrary.sets[i].enabled = on
|
||||
}
|
||||
} label: { Image(systemName: icon).foregroundStyle(active > 0 ? LK.amber : LK.muted) }
|
||||
.buttonStyle(.borderless)
|
||||
.help(active == all.count ? "Ganze Liga deaktivieren" : "Ganze Liga aktivieren")
|
||||
Button {
|
||||
if collapsed.contains(league) { collapsed.remove(league) } else { collapsed.insert(league) }
|
||||
} label: {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: collapsed.contains(league) ? "chevron.right" : "chevron.down").font(.system(size: 9, weight: .bold))
|
||||
Text(league.isEmpty ? "Ohne Liga" : league).font(.system(size: 12, weight: .bold)).foregroundStyle(LK.text)
|
||||
}
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
Spacer()
|
||||
Text("\(active)/\(all.count) aktiv").font(.caption.monospacedDigit()).foregroundStyle(LK.muted)
|
||||
}
|
||||
.contextMenu {
|
||||
Button("Weitere Teams in diese Liga importieren …") { state.importCodeFiles(league: league) }
|
||||
Button("Ganze Liga löschen", role: .destructive) {
|
||||
let ids = Set(all.map(\.id))
|
||||
if let sel = selectedTeam, ids.contains(sel) { selectedTeam = nil }
|
||||
DispatchQueue.main.async { state.codeLibrary.sets.removeAll { ids.contains($0.id) } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func teamRow(_ set: CodeSet) -> some View {
|
||||
HStack {
|
||||
Toggle("", isOn: Binding(
|
||||
get: { state.codeLibrary.sets.first { $0.id == set.id }?.enabled ?? false },
|
||||
set: { on in if let i = state.codeLibrary.sets.firstIndex(where: { $0.id == set.id }) { state.codeLibrary.sets[i].enabled = on } }))
|
||||
.toggleStyle(.checkbox).labelsHidden()
|
||||
.help("Aktiv (PM: Enable)")
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text(set.name).lineLimit(1)
|
||||
Text(set.sourcePath.map { URL(fileURLWithPath: $0).lastPathComponent } ?? "manuell")
|
||||
.font(.caption2).foregroundStyle(.secondary).lineLimit(1)
|
||||
}
|
||||
Spacer()
|
||||
Text("\(set.entries.count)").font(.caption.monospacedDigit()).foregroundStyle(.secondary)
|
||||
}
|
||||
.tag(set.id)
|
||||
.contextMenu {
|
||||
Button("Neue Spieler aus TXT nachladen …") { state.importCodeFiles(into: set.id) }
|
||||
Menu("In Liga verschieben") {
|
||||
ForEach(state.codeLibrary.leagues.filter { $0 != set.league && !$0.isEmpty }, id: \.self) { l in
|
||||
Button(l) { setLeague(set.id, l) }
|
||||
}
|
||||
if !set.league.isEmpty { Divider(); Button("Ohne Liga") { setLeague(set.id, "") } }
|
||||
}
|
||||
Button("Im Finder zeigen") {
|
||||
if let p = set.sourcePath { NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: p)]) }
|
||||
}.disabled(set.sourcePath == nil)
|
||||
Button("Löschen", role: .destructive) { remove(set.id) }
|
||||
}
|
||||
}
|
||||
|
||||
private func setLeague(_ id: UUID, _ league: String) {
|
||||
if let i = state.codeLibrary.sets.firstIndex(where: { $0.id == id }) { state.codeLibrary.sets[i].league = league }
|
||||
}
|
||||
|
||||
// MARK: Players of the selected team
|
||||
|
||||
@ViewBuilder
|
||||
@@ -83,6 +159,8 @@ struct CodesWindow: View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
HStack {
|
||||
TextField("Teamname", text: $state.codeLibrary.sets[i].name).font(.headline).textFieldStyle(.roundedBorder)
|
||||
TextField("Liga", text: $state.codeLibrary.sets[i].league).textFieldStyle(.roundedBorder).frame(width: 150)
|
||||
.help("Liga, unter der das Team einsortiert wird (z. B. 1. Bundesliga)")
|
||||
Button("TXT nachladen …") { state.importCodeFiles(into: state.codeLibrary.sets[i].id) }
|
||||
.help("Neue Spieler aus einer TXT hinzufügen – vorhandene bleiben unverändert")
|
||||
}
|
||||
@@ -176,8 +254,9 @@ struct CodesWindow: View {
|
||||
}
|
||||
|
||||
private func remove(_ id: UUID) {
|
||||
state.codeLibrary.sets.removeAll { $0.id == id }
|
||||
if selectedTeam == id { selectedTeam = state.codeLibrary.sets.first?.id }
|
||||
// leave the detail view (index bindings) first, then remove – avoids "Index out of range"
|
||||
if selectedTeam == id { selectedTeam = nil }
|
||||
DispatchQueue.main.async { state.codeLibrary.sets.removeAll { $0.id == id } }
|
||||
}
|
||||
|
||||
private func export(_ set: CodeSet) {
|
||||
|
||||
@@ -79,8 +79,10 @@ struct JerseySetupView: View {
|
||||
ForEach(state.settings.jersey.teams) { t in teamRow(t.id) }
|
||||
HStack {
|
||||
Menu("Team hinzufügen") {
|
||||
ForEach(state.codeLibrary.sets) { set in
|
||||
Button(set.name) { add(set) }
|
||||
ForEach(state.codeLibrary.grouped, id: \.league) { g in
|
||||
Menu(g.league.isEmpty ? "Ohne Liga" : g.league) {
|
||||
ForEach(g.sets) { set in Button(set.name) { add(set) } }
|
||||
}
|
||||
}
|
||||
if state.codeLibrary.sets.isEmpty { Text("Zuerst Teams in den Code-Ersetzungen anlegen (⌘⇧K)") }
|
||||
}
|
||||
|
||||
@@ -220,8 +220,13 @@ struct SpieltagView: View {
|
||||
Button("Leeres Team") { sel.wrappedValue = newTeam(from: nil); edit.wrappedValue = true }
|
||||
if !state.codeLibrary.sets.isEmpty {
|
||||
Divider()
|
||||
ForEach(state.codeLibrary.sets) { set in
|
||||
Button("Aus Code-Team „\(set.name)“") { sel.wrappedValue = newTeam(from: set); edit.wrappedValue = true }
|
||||
// one submenu per league (1. Bundesliga, 2. Bundesliga …)
|
||||
ForEach(state.codeLibrary.grouped, id: \.league) { g in
|
||||
Menu(g.league.isEmpty ? "Ohne Liga" : g.league) {
|
||||
ForEach(g.sets) { set in
|
||||
Button("Aus Code-Team „\(set.name)“") { sel.wrappedValue = newTeam(from: set); edit.wrappedValue = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} label: { Image(systemName: "plus") }
|
||||
@@ -249,7 +254,11 @@ struct SpieltagView: View {
|
||||
row("Spieler-Codes") {
|
||||
Picker("", selection: b.codeSetID) {
|
||||
Text("– keine –").tag(UUID?.none)
|
||||
ForEach(state.codeLibrary.sets) { set in Text(set.name).tag(UUID?.some(set.id)) }
|
||||
ForEach(state.codeLibrary.grouped, id: \.league) { g in
|
||||
Section(g.league.isEmpty ? "Ohne Liga" : g.league) {
|
||||
ForEach(g.sets) { set in Text(set.name).tag(UUID?.some(set.id)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
.labelsHidden()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user