Cotton code
150 lines · 6.4 KB · SwiftRaw
// Cotton Story's SCENE CARD (`scene.card`, contract 17 Nov 2026): the scene's// number and heading, then its summary if it has one, else its opening lines// laid out as a screenplay, and its length at the foot; its status quietly// beside the number. Flat and typographic: a sheet, a hairline, type.//// Slots: `number` (the scene's place in the story), `title` (the heading as// written), `subtitle` (the one-line summary), `lines` (its lines as the// core read them) or `body`, `length` ("2 pages", "under a page"), `state`// (its status, said only when it is not a draft). Every word is the core's.import CottonPaperimport CottonValuesimport SwiftUIenum StorySceneCardKnobs {    static let scriptSize: CGFloat = 13    static let headingSize: CGFloat = 17}struct StorySceneCardFace: View {    let card: DeckCard    init(card: DeckCard) {        self.card = card    }    var body: some View {        VStack(alignment: .leading, spacing: StoryCardKnobs.gap) {            HStack(alignment: .firstTextBaseline) {                if let number = card.text("number") {                    StoryQuietLine(text: number)                        .accessibilityIdentifier("scene-number")                        .facePart(.subtitle)                }                Spacer(minLength: 8)                if let state = card.text("state") {                    StoryQuietLine(text: state)                        .accessibilityIdentifier("scene-state")                }            }            if let heading = card.text("title") {                Text(verbatim: heading)                    .font(StoryType.script(StorySceneCardKnobs.headingSize, relativeTo: .headline).bold())                    .foregroundStyle(StoryMaterial.ink.colour)                    .fixedSize(horizontal: false, vertical: true)                    .accessibilityIdentifier("deck-title")                    .facePart(.title)            }            if let summary = card.text("subtitle") {                Text(verbatim: summary)                    .font(StoryType.sans(.body))                    .foregroundStyle(StoryMaterial.ink.colour)                    .fixedSize(horizontal: false, vertical: true)                    .accessibilityIdentifier("scene-summary")                Spacer(minLength: 0)            } else {                StoryScriptLines(lines: StoryLine.of(card), size: StorySceneCardKnobs.scriptSize)                    .storyFadesOut()                    .accessibilityIdentifier("scene-opening")                    .facePart(.body)            }            if let length = card.text("length") {                StoryQuietLine(text: length)                    .accessibilityIdentifier("scene-length")            }        }        .padding(StoryCardKnobs.inset)        .storySheet()        .accessibilityElement(children: .contain)        .accessibilityIdentifier("scene-card")    }}/// The scene card, and the cards it is reviewed in.public enum StorySceneCardFaceCatalogue {    public static let stock: FaceStock = .own    public static let ground: FaceGround = .blank    public static let face = Face(id: "scene.card", specimens: [        Specimen("opening", opening), Specimen("summary", summarised), Specimen("telugu", telugu), Specimen("empty", empty),    ]) { card, _, _ in        StorySceneCardFace(card: card)    }    /// A two-hander's first lines, no summary yet.    public static let opening = DeckCard(face: "scene.card", corner: nil, pressing: false, pace: nil, plate: nil, fields: [        "number": .text("3"),        "title": .text("INT. LIGHTHOUSE KITCHEN - NIGHT"),        "lines": StoryLine.fields(StorySpecimenLinesCatalogue.twoHander),        "length": .text("1 ⅜ pages"),    ])    /// A scene with its one-line summary, marked done.    public static let summarised = DeckCard(face: "scene.card", corner: nil, pressing: false, pace: nil, plate: nil, fields: [        "number": .text("12"),        "title": .text("EXT. HARBOUR WALL - DAY"),        "subtitle": .text("Ravi finally tells Meera the boat was never sold."),        "length": .text("under a page"),        "state": .text("Done"),    ])    /// A scene written in Telugu: the script face falls back to the    /// system's Telugu beside its Latin.    public static let telugu = DeckCard(face: "scene.card", corner: nil, pressing: false, pace: nil, plate: nil, fields: [        "number": .text("7"),        "title": .text("INT. వంటగది - రాత్రి"),        "lines": StoryLine.fields(StorySpecimenLinesCatalogue.telugu),        "length": .text("under a page"),    ])    /// A new scene: a heading and nothing else yet.    public static let empty = DeckCard(face: "scene.card", corner: nil, pressing: false, pace: nil, plate: nil, fields: [        "number": .text("1"),        "title": .text("INT. SOMEWHERE - DAY"),    ])}/// Invented scenes the Story faces are reviewed in.enum StorySpecimenLinesCatalogue {    static let twoHander: [StoryLine] = [        StoryLine(.action, "Rain on the glass. MEERA (30s) sets two cups down, too hard."),        StoryLine(.blank, ""),        StoryLine(.character, "MEERA"),        StoryLine(.dialogue, "You said the boat was sold."),        StoryLine(.blank, ""),        StoryLine(.character, "RAVI"),        StoryLine(.parenthetical, "(not looking up)"),        StoryLine(.dialogue, "I said someone wanted it."),        StoryLine(.blank, ""),        StoryLine(.action, "The lamp swings once. Neither of them moves."),        StoryLine(.blank, ""),        StoryLine(.character, "MEERA"),        StoryLine(.dialogue, "Then who has been paying for the mooring?"),        StoryLine(.blank, ""),        StoryLine(.character, "RAVI"),        StoryLine(.dialogue, "Drink your tea."),        StoryLine(.blank, ""),        StoryLine(.transition, "CUT TO:"),    ]    static let telugu: [StoryLine] = [        StoryLine(.action, "వర్షం. మీర కిటికీ దగ్గర నిలబడి ఉంది."),        StoryLine(.blank, ""),        StoryLine(.character, "మీర"),        StoryLine(.dialogue, "పడవ అమ్మేశావని చెప్పావు కదా?"),        StoryLine(.blank, ""),        StoryLine(.character, "రవి"),        StoryLine(.parenthetical, "(నెమ్మదిగా)"),        StoryLine(.dialogue, "ఎవరో అడిగారని మాత్రమే చెప్పాను."),    ]}