// The EPISODE face, still-led (Codex round 2, series-1; review.md): the cream// card with the episode's still laid across its head (`photo`, the record's// own picture; while there is none, the old television with the series'// name on its screen), then its number and title typed heavy on one line// ("S2 · E3 Cicadas": `subtitle`, said by the core's line, then `title`),// its length and air day under them in pencil (`length`, `place`), and the// series' name typed small over the heading (`source`) for a card met// outside its series' crumb line. At the foot, once watched, the day by hand// after its label (`date`, "Watched") and the rating in stars under it// (`count`); part way, the slim rule (`used` of `limit`). Every word is the// core's (`DeckCard`).importCottonPaperimportCottonValuesimportSwiftUIenumEpisodeFaceKnobs {staticlet inset = EdgeInsets(top: 22, leading: 24, bottom: 22, trailing: 24)/// A still, width to height: as tall as the card leaves room for,/// between the widest and the tallest.staticlet stillWidest: CGFloat = 1.78staticlet stillTallest: CGFloat = 1.3staticlet border: CGFloat = 5staticlet seriesSize: CGFloat = 11.5staticlet headingSize: CGFloat = 24staticlet headingGap: CGFloat = 14staticlet lineSize: CGFloat = 13.5staticlet lineGap: CGFloat = 5staticlet dateHand: CGFloat = 23staticlet dateGap: CGFloat = 10staticlet star: CGFloat = 22staticlet screenSize: CGFloat = 13}publicstructEpisodeFace<Still: View>: View {let card: DeckCard/// The still filling its frame; nil draws the television.var still: Still? @Environment(\.theme) privatevar themepublicinit(card: DeckCard, still: Still? = nil) {self.card = cardself.still = still }publicvar body: someView {GeometryReader { sheet inlet width = sheet.size.width - EpisodeFaceKnobs.inset.leading - EpisodeFaceKnobs.inset.trailing VStack(alignment: .leading, spacing: 0) {Group {iflet still { ZStack {Rectangle().fill(theme.faceStocks.printMount)MountedPrint(photo: still).padding(EpisodeFaceKnobs.border) } .shadow(color: theme.colors.shadow.color.opacity(0.22), radius: 2, x: 0, y: 1.5) .facePart(.picture) } else {SeriesScreen(words: card.text("source") ?? card.text("title")) } } .frame(width: width) .frame(minHeight: width / EpisodeFaceKnobs.stillWidest, maxHeight: width / EpisodeFaceKnobs.stillTallest) .accessibilityHidden(true)iflet series = card.text("source") {Text(series.uppercased()) .font(CottonFonts.type(EpisodeFaceKnobs.seriesSize)) .tracking(1.2) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.pencil) .padding(.top, EpisodeFaceKnobs.headingGap) .accessibilityIdentifier("face-series") }iflet heading = Self.heading(card) {HeavyType(words: heading, size: EpisodeFaceKnobs.headingSize) .lineLimit(2) .minimumScaleFactor(0.7) .padding(.top, card.text("source") == nil ? EpisodeFaceKnobs.headingGap : EpisodeFaceKnobs.lineGap) .accessibilityIdentifier("deck-title") .facePart(.title) }iflet line = Self.line(card) {Text(line) .font(CottonFonts.type(EpisodeFaceKnobs.lineSize)) .lineLimit(1) .minimumScaleFactor(0.8) .faceInk(.ink) .padding(.top, EpisodeFaceKnobs.lineGap) }EpisodeStanding(card: card) .padding(.top, EpisodeFaceKnobs.dateGap) } .padding(EpisodeFaceKnobs.inset) } .onCardPaper(EpisodeFaceCatalogue.stock.laid(card.pace)) }/// Its number then its title, as one heading ("S2 · E3 Cicadas").staticfunc heading(_ card: DeckCard) -> String? {let words = [card.text("subtitle"), card.text("title")].compactMap { $0 }return words.isEmpty ? nil : words.joined(separator: " ") }/// Its length and the day it aired, as the cards join words.staticfunc line(_ card: DeckCard) -> String? {let words = [card.text("length"), card.text("place")].compactMap { $0 }return words.isEmpty ? nil : words.joined(separator: ShellLines.line("cards", "join")) }/// The day it was watched by hand after its label ("Watched Sun 11 Oct").staticfunc watched(_ card: DeckCard) -> String? {guardlet day = card.dated else { returnnil }guardlet label = card.label("date") else { return day }return"\(label) \(day)" }}/// Where the watcher stands: watched, the day by hand and the stars under/// it; part way, the rule and the stars under it; not begun, the stars/// alone, if any.privatestructEpisodeStanding: View {let card: DeckCardvar body: someView {let foot = MediaFoot(card) VStack(alignment: .leading, spacing: EpisodeFaceKnobs.lineGap) {iflet watched = EpisodeFace<EmptyView>.watched(card) {Text(HandRun.tail(watched)) .font(CottonFonts.hand(EpisodeFaceKnobs.dateHand)) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.ink) .accessibilityIdentifier("face-finished") .facePart(.when) } elseiflet progress = foot.progress {ReadingRule(progress: progress) }iflet rating = foot.rating { StarRow(rating: rating, size: EpisodeFaceKnobs.star) } } }}/// The old television with the series' name glowing on its screen, while/// the episode keeps no still.privatestructSeriesScreen: View {let words: String? @Environment(\.theme) privatevar themevar body: someView {FaceArt(name: "face-art-tv") .overlay {GeometryReader { box iniflet words {Text(words) .font(CottonFonts.type(EpisodeFaceKnobs.screenSize)) .lineLimit(2) .minimumScaleFactor(0.6) .multilineTextAlignment(.center) .foregroundStyle(theme.colors.paper.color.opacity(0.85)) .frame(width: box.size.width * 0.5, height: box.size.height * 0.45) .position(x: box.size.width * 0.38, y: box.size.height * 0.4) } } } .frame(maxWidth: .infinity) }}/// The episode face, by the kind's name, and the cards it is reviewed in.publicenumEpisodeFaceCatalogue {publicstaticlet stock: FaceStock = .creampublicstaticlet ground: FaceGround = .paperpublicstaticlet face = Face(id: "episode", specimens: [Specimen("episode", episode, picture: "verandah-wide"), Specimen("half", episodeHalf), ]) { card, picture, _ inEpisodeFace(card: card, still: picture) }/// An episode watched and rated, its still a picture.publicstaticlet episode = DeckCard(face: .episode, fields: ["source": .text("Example Valley"),"subtitle": .text("S2 \u{00B7} E5"),"title": .text("The Night the Invented Bridge Came Down"),"length": .text("52 min"),"place": .text("Fri 9 Oct"),"photo": .text("verandah-wide"),"date": .text("Sun 11 Oct"),"count": .text("5"), ])/// An episode part way watched, with no still kept.publicstaticlet episodeHalf = DeckCard(face: .episode, fields: ["source": .text("Invented Precinct"),"subtitle": .text("S1 \u{00B7} E3"),"title": .text("Lanterns"),"length": .text("47 min"),"used": .number(31),"limit": .number(47),"date": .text("Add date"), ])}