diff --git a/Sources/Lichtkasten/Views/SettingsView.swift b/Sources/Lichtkasten/Views/SettingsView.swift index bb1cbbe..ed6825a 100644 --- a/Sources/Lichtkasten/Views/SettingsView.swift +++ b/Sources/Lichtkasten/Views/SettingsView.swift @@ -367,7 +367,9 @@ struct PreflightSettings: View { /// fields offered as "Pflichtfeld" private static let candidates = ["caption", "headline", "creator", "copyright", "credit", "source", "event", "city", "sublocation", "state", "country", "countryCode", "dateCreated", - "keywords", "objectName", "captionWriter"] + "keywords", "objectName", "captionWriter", + // "Locations Taken and Shown" (many agencies require it) + "lcSublocation", "lcCity", "lcState", "lcCountry", "lcCountryCode", "lcWorldRegion"] private var opts: Binding { $state.settings.preflight } @@ -377,7 +379,7 @@ struct PreflightSettings: View { LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())], alignment: .leading, spacing: 8) { ForEach(Self.candidates, id: \.self) { id in if let f = IPTCField.byID[id] { - Toggle(f.label, isOn: Binding( + Toggle(f.section == .locationCreated ? "\(f.label) (Aufnahmeort)" : f.label, isOn: Binding( get: { state.settings.preflight.requiredFields.contains(id) }, set: { on in state.settings.preflight.requiredFields.removeAll { $0 == id } diff --git a/Sources/Lichtkasten/Views/SpieltagView.swift b/Sources/Lichtkasten/Views/SpieltagView.swift index cf9dea9..3fec80a 100644 --- a/Sources/Lichtkasten/Views/SpieltagView.swift +++ b/Sources/Lichtkasten/Views/SpieltagView.swift @@ -315,6 +315,8 @@ struct SpieltagView: View { TextField("Bundesland", text: v.state).textFieldStyle(.roundedBorder) TextField("Land", text: v.country).textFieldStyle(.roundedBorder) TextField("DEU", text: v.countryCode).textFieldStyle(.roundedBorder).frame(width: 56) + TextField("Weltregion", text: v.worldRegion).textFieldStyle(.roundedBorder).frame(width: 90) + .help("Locations Taken and Shown → World Region") } } } diff --git a/Sources/LichtkastenCore/Matchday/Spieltag.swift b/Sources/LichtkastenCore/Matchday/Spieltag.swift index fcf5915..735088e 100644 --- a/Sources/LichtkastenCore/Matchday/Spieltag.swift +++ b/Sources/LichtkastenCore/Matchday/Spieltag.swift @@ -7,9 +7,27 @@ public struct Venue: Codable, Hashable, Sendable { public var state: String = "" // "Niedersachsen" public var country: String = "Deutschland" public var countryCode: String = "DEU" + /// "Locations Taken and Shown" → World Region (agencies require the complete block) + public var worldRegion: String = "Europa" - public init(name: String = "", city: String = "", state: String = "", country: String = "Deutschland", countryCode: String = "DEU") { + public init(name: String = "", city: String = "", state: String = "", country: String = "Deutschland", + countryCode: String = "DEU", worldRegion: String = "Europa") { self.name = name; self.city = city; self.state = state; self.country = country; self.countryCode = countryCode + self.worldRegion = worldRegion + } + + enum CodingKeys: String, CodingKey { case name, city, state, country, countryCode, worldRegion } + + /// Tolerant: venues saved before a field existed keep their stadium. + public init(from decoder: Decoder) throws { + let c = try decoder.container(keyedBy: CodingKeys.self) + let d = Venue() + name = (try? c.decode(String.self, forKey: .name)) ?? d.name + city = (try? c.decode(String.self, forKey: .city)) ?? d.city + state = (try? c.decode(String.self, forKey: .state)) ?? d.state + country = (try? c.decode(String.self, forKey: .country)) ?? d.country + countryCode = (try? c.decode(String.self, forKey: .countryCode)) ?? d.countryCode + worldRegion = (try? c.decode(String.self, forKey: .worldRegion)) ?? d.worldRegion } public var isEmpty: Bool { name.isEmpty && city.isEmpty } @@ -283,7 +301,9 @@ public enum SpieltagGenerator { } public static let generatedFields = ["headline", "event", "caption", "city", "sublocation", "state", "country", - "countryCode", "keywords", "dateCreated"] + "countryCode", "keywords", "dateCreated", + // "Locations Taken and Shown" – agencies reject images without it + "lcSublocation", "lcCity", "lcState", "lcCountry", "lcCountryCode", "lcWorldRegion"] /// The IPTC template of the match: base template (creator, copyright, …) + everything generated. public static func makeTemplate(match: MatchPlan, home: TeamProfile, away: TeamProfile, competition: Competition?, @@ -303,14 +323,14 @@ public enum SpieltagGenerator { v.text["countryCode"] = match.venue.countryCode.isEmpty ? nil : match.venue.countryCode v.lists["keywords"] = keywords(match: match, home: home, away: away, competition: competition, patterns: patterns, ctx: ctx) v.text["dateCreated"] = "{capturetime}" - // "Location created" only if the base template uses it – then it must not keep the old stadium - if t.values.text["lcCity"] != nil || t.values.text["lcSublocation"] != nil { - v.text["lcCity"] = match.venue.city - v.text["lcSublocation"] = match.venue.name - v.text["lcState"] = match.venue.state - v.text["lcCountry"] = match.venue.country - v.text["lcCountryCode"] = match.venue.countryCode - } + // "Locations Taken and Shown" (Location Created) – always filled, the agency needs the complete block + func set(_ id: String, _ value: String) { v.text[id] = value.isEmpty ? nil : value } + set("lcSublocation", match.venue.name) + set("lcCity", match.venue.city) + set("lcState", match.venue.state) + set("lcCountry", match.venue.country) + set("lcCountryCode", match.venue.countryCode) + set("lcWorldRegion", match.venue.worldRegion.isEmpty ? (t.values.text["lcWorldRegion"] ?? "") : match.venue.worldRegion) t.values = v t.dateFromCapture = true if var applied = t.appliedFields { diff --git a/Tests/LichtkastenCoreTests/CoreTests.swift b/Tests/LichtkastenCoreTests/CoreTests.swift index f9da120..4be5563 100644 --- a/Tests/LichtkastenCoreTests/CoreTests.swift +++ b/Tests/LichtkastenCoreTests/CoreTests.swift @@ -325,6 +325,13 @@ final class SpieltagTests: XCTestCase { XCTAssertTrue(t.appliedFields?.contains("headline") == true) XCTAssertTrue(t.appliedFields?.contains("creator") == true) XCTAssertNotEqual(t.id, base.id) + // "Locations Taken and Shown" always complete (agency requirement), even if the base has none + for id in ["lcSublocation", "lcCity", "lcState", "lcCountry", "lcCountryCode", "lcWorldRegion"] { + XCTAssertTrue(t.appliedFields?.contains(id) == true, id) + } + XCTAssertEqual(t.values.text["lcSublocation"], m.venue.name) + XCTAssertEqual(t.values.text["lcCity"], m.venue.city) + XCTAssertEqual(t.values.text["lcWorldRegion"], "Europa") } }