// 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`). import CottonPaper import CottonValues import SwiftUI enum EpisodeFaceKnobs { static let 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. static let stillWidest: CGFloat = 1.78 static let stillTallest: CGFloat = 1.3 static let border: CGFloat = 5 static let seriesSize: CGFloat = 11.5 static let headingSize: CGFloat = 24 static let headingGap: CGFloat = 14 static let lineSize: CGFloat = 13.5 static let lineGap: CGFloat = 5 static let dateHand: CGFloat = 23 static let dateGap: CGFloat = 10 static let star: CGFloat = 22 static let screenSize: CGFloat = 13 } public struct EpisodeFace: View { let card: DeckCard /// The still filling its frame; nil draws the television. var still: Still? @Environment(\.theme) private var theme public init(card: DeckCard, still: Still? = nil) { self.card = card self.still = still } public var body: some View { GeometryReader { sheet in let width = sheet.size.width - EpisodeFaceKnobs.inset.leading - EpisodeFaceKnobs.inset.trailing VStack(alignment: .leading, spacing: 0) { Group { if let 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) if let 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") } if let 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) } if let 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"). static func 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. static func 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"). static func watched(_ card: DeckCard) -> String? { guard let day = card.dated else { return nil } guard let 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. private struct EpisodeStanding: View { let card: DeckCard var body: some View { let foot = MediaFoot(card) VStack(alignment: .leading, spacing: EpisodeFaceKnobs.lineGap) { if let watched = EpisodeFace.watched(card) { Text(HandRun.tail(watched)) .font(CottonFonts.hand(EpisodeFaceKnobs.dateHand)) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.ink) .accessibilityIdentifier("face-finished") .facePart(.when) } else if let progress = foot.progress { ReadingRule(progress: progress) } if let 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. private struct SeriesScreen: View { let words: String? @Environment(\.theme) private var theme var body: some View { FaceArt(name: "face-art-tv") .overlay { GeometryReader { box in if let 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. public enum EpisodeFaceCatalogue { public static let stock: FaceStock = .cream public static let ground: FaceGround = .paper public static let face = Face(id: "episode", specimens: [ Specimen("episode", episode, picture: "verandah-wide"), Specimen("half", episodeHalf), ]) { card, picture, _ in EpisodeFace(card: card, still: picture) } /// An episode watched and rated, its still a picture. public static let 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. public static let 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"), ]) }