diff --git a/README.md b/README.md index 1d04f64..a31f36e 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ der goldene Kasten): `gold`, `tunnel`, `fein`, `monogramm`, `hell`, `kasten`, `s (Apple Vision, auf dem Gerät), Team über die Farbe bestimmen, Code `w10` → Spieler aus den Code-Ersetzungen. 3. Bilder mit Vorschlag tragen ein blaues `#10`-Abzeichen, der Filter „Vorschläge“ zeigt nur diese. 4. Mit **I** prüfen: Die Nummer ist im Bild markiert. **⌘J** (Annehmen) trägt den Spieler in die erste Zeile der - Beschreibung und unter „Persons shown“ ein, ✕ verwirft den Vorschlag. Danach wie gewohnt ⌘B = Speichern & nächstes. + Beschreibung ein (auf Wunsch zusätzlich unter „Persons shown“, Trikot-Erkennung einrichten), ✕ verwirft den Vorschlag. Danach wie gewohnt ⌘B = Speichern & nächstes. ## Spieltag-Assistent (⌘⇧N) diff --git a/Sources/Lichtkasten/Services/AppState.swift b/Sources/Lichtkasten/Services/AppState.swift index 0446b9d..df0f739 100644 --- a/Sources/Lichtkasten/Services/AppState.swift +++ b/Sources/Lichtkasten/Services/AppState.swift @@ -233,6 +233,7 @@ final class AppState: ObservableObject { } seedDefaultsIfNeeded() startLightroomPolling() + updateLightroomPluginIfNeeded() // PM "Automatically reload code replacement files when they change" codeReloadTimer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { [weak self] _ in Task { @MainActor in @@ -1153,6 +1154,24 @@ final class AppState: ObservableObject { } } + /// A newer Lichtkasten brings a newer Lightroom plugin (e.g. source paths for the export) – an old one in + /// Lightroom's Modules folder is replaced automatically, so the export mapping works without manual steps. + private func updateLightroomPluginIfNeeded() { + guard LightroomBridge.pluginInstalled, + let bundled = Bundle.main.url(forResource: "LichtkastenBridge", withExtension: "lrplugin") else { return } + let installed = LightroomBridge.lightroomModulesFolder.appendingPathComponent("LichtkastenBridge.lrplugin") + let files = (try? FileManager.default.contentsOfDirectory(atPath: bundled.path)) ?? [] + let differs = files.contains { name in + (try? Data(contentsOf: bundled.appendingPathComponent(name))) != (try? Data(contentsOf: installed.appendingPathComponent(name))) + } + guard differs else { return } + do { + try LightroomBridge.installPlugin(from: bundled) + alert = AppAlert(title: "Lightroom-Plugin aktualisiert", + message: "Die Lichtkasten Bridge in Lightroom Classic wurde auf die neue Version gebracht. Bitte Lightroom Classic einmal neu starten.") + } catch { report(error) } + } + private func startLightroomPolling() { lrPollTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { [weak self] _ in Task { @MainActor in self?.pollLightroom() } @@ -1605,6 +1624,8 @@ final class AppState: ObservableObject { var v = values let reps = suggestions.compactMap(\.replacement) v.text["caption"] = JerseyLogic.insertIntoCaption(v.text["caption"] ?? "", names: reps, separator: settings.jersey.separator) + // "Persons shown" only if switched on – by default the player goes into the caption only + guard settings.jersey.writePersonsShown else { return v } var persons = v.lists["personInImage"] ?? [] for s in suggestions { guard let rep = s.replacement, let code = s.code else { continue } @@ -1618,7 +1639,7 @@ final class AppState: ObservableObject { /// Accept directly (contact sheet / context menu): writes caption + persons and marks as done. func acceptSuggestions(_ s: [JerseySuggestion], for item: PhotoItem) { guard !s.isEmpty else { return } - let fields = ["caption", "personInImage"].compactMap { IPTCField.byID[$0] } + let fields = (settings.jersey.writePersonsShown ? ["caption", "personInImage"] : ["caption"]).compactMap { IPTCField.byID[$0] } let values = applying(s, to: item.iptc) Task { if await applyIPTCAndWait(values, fields: fields, to: [item]) { @@ -1678,6 +1699,21 @@ final class AppState: ObservableObject { let number = code.flatMap { c in Int(c.drop { !$0.isNumber }) } return PlayerInfo(name: name, number: number, team: code.flatMap { team(forCode: $0, in: teamsOfPhoto) }, confirmed: true) } + // accepted players now only live in the first caption line → find a known player name there + let firstLine = (item.iptc.text["caption"] ?? "").components(separatedBy: "\n").first ?? "" + if !firstLine.trimmingCharacters(in: .whitespaces).isEmpty { + for t in teamsOfPhoto { + guard let set = t.codeSetID.flatMap({ id in codeLibrary.sets.first { $0.id == id } }) else { continue } + for e in set.entries { + guard let rep = e.columns.first else { continue } + let name = JerseyLogic.personName(replacement: rep, columns: e.columns) + if name.count > 3, firstLine.contains(name) { + let number = Int(e.code.drop { !$0.isNumber }) + return PlayerInfo(name: name, number: number, team: t, confirmed: true) + } + } + } + } if let s = openSuggestions(for: item.id).first, let rep = s.replacement { let name = JerseyLogic.personName(replacement: rep, columns: codes.table[(s.code ?? "").lowercased()] ?? []) let team = (teamsOfPhoto + settings.jersey.teams).first { $0.id == s.teamID } diff --git a/Sources/Lichtkasten/Services/Persistence.swift b/Sources/Lichtkasten/Services/Persistence.swift index 208b62f..1716579 100644 --- a/Sources/Lichtkasten/Services/Persistence.swift +++ b/Sources/Lichtkasten/Services/Persistence.swift @@ -68,7 +68,7 @@ struct LightroomSettings: Codable, Hashable { /// Jersey number recognition settings (teams of the current match). struct JerseySettings: Codable, Hashable { enum CodingKeys: String, CodingKey { - case teams, useShirt, useShorts, minConfidence, autoAfterIngest, separator + case teams, useShirt, useShorts, minConfidence, autoAfterIngest, separator, writePersonsShown case matchday = "matchdayEnabled" // new key: the old default (on) is not carried over } @@ -78,6 +78,8 @@ struct JerseySettings: Codable, Hashable { var minConfidence = 0.35 var autoAfterIngest = false var separator = ", " + /// Accepted players also go into "Persons shown" (off: only the first line of the caption) + var writePersonsShown = false /// Matchday view (team header, player list, team-colored cards) – opt-in, needs two teams var matchday = false @@ -91,6 +93,7 @@ struct JerseySettings: Codable, Hashable { minConfidence = (try? c.decode(Double.self, forKey: .minConfidence)) ?? d.minConfidence autoAfterIngest = (try? c.decode(Bool.self, forKey: .autoAfterIngest)) ?? d.autoAfterIngest separator = (try? c.decode(String.self, forKey: .separator)) ?? d.separator + writePersonsShown = (try? c.decode(Bool.self, forKey: .writePersonsShown)) ?? d.writePersonsShown matchday = (try? c.decode(Bool.self, forKey: .matchday)) ?? d.matchday } } diff --git a/Sources/Lichtkasten/Views/IPTCInfoWindow.swift b/Sources/Lichtkasten/Views/IPTCInfoWindow.swift index a7bc181..17ca53c 100644 --- a/Sources/Lichtkasten/Views/IPTCInfoWindow.swift +++ b/Sources/Lichtkasten/Views/IPTCInfoWindow.swift @@ -155,7 +155,7 @@ struct IPTCInfoWindow: View { } } - /// Fills caption (first line) and "Persons shown" in the form – saved with ⌘B / OK as usual. + /// Fills the first caption line (and "Persons shown" if switched on) in the form – saved with ⌘B / OK as usual. private func accept(_ s: [JerseySuggestion]) { guard let item else { return } let updated = state.applying(s, to: IPTCValues(texts: texts)) diff --git a/Sources/Lichtkasten/Views/JerseySetupView.swift b/Sources/Lichtkasten/Views/JerseySetupView.swift index 067179b..8e10526 100644 --- a/Sources/Lichtkasten/Views/JerseySetupView.swift +++ b/Sources/Lichtkasten/Views/JerseySetupView.swift @@ -110,6 +110,8 @@ struct JerseySetupView: View { TextField("", text: jersey.separator).frame(width: 60).textFieldStyle(.roundedBorder) } Toggle("Nach dem Ingest automatisch erkennen", isOn: jersey.autoAfterIngest) + Toggle("Angenommene Spieler:innen zusätzlich in „Persons shown“ eintragen", isOn: jersey.writePersonsShown) + .help("Aus: nur in die erste Zeile der Beschreibung (Standard)") } .padding(6) }