91 lines · 4.3 KB · SwiftRaw
// STORY'S LOOK (shared/DECISIONS.md "Look"): Settings' Look row opens the shared Look screen (Chrome/LookScreen.swift)// in Story's Ink: a few script lines drawn live (a heading, an action, a name and its words, the core's preview) in// the paper, ink, face and size chosen; Reset asked in Story's own panel. Every Story screen reads the standing look// through `Ink` and `InkType` (InkLook.swift); Read's pages, the PDF and the Final Draft file keep the standard 12 pt// typewriter face and layout whatever is chosen.#if os(iOS)import CottonKitimport CottonWritingimport SwiftUIstruct StoryLookPage: View { let story: InkStory @State private var look = LookModel.standing("story") @State private var asking = false var body: some View { Group { if let answer = look.answer { LookScreen(choices: LookChoices(answer), words: LookWords(answer), skin: Self.skin, gutter: Ink.gutter, choose: { pick in Task { await look.choose(pick, core: story.core); tellRefusal() } }, reset: { asking = true }) { dark in StoryLookPreview(answer: answer, dark: dark) } more: { EmptyView() } } else { Color.clear.frame(height: 200) } } .task { await look.read(story.core) } .lookPanel(isPresented: $asking, style: Ink.panel) { if let answer = look.answer { InkActsSheet(title: answer.word("reset_title"), acts: [InkAct(words: answer.word("reset_yes")) { asking = false Task { await look.reset(core: story.core); tellRefusal() } }], line: answer.word("reset_ask")) } } } private func tellRefusal() { if let refused = look.refused { story.notice = refused; look.refused = nil } } /// The screen in Story's Ink: its ground, navy and quiet, the ballpoint for what is chosen, Plex Mono (or the face chosen). @MainActor static var skin: LookSkin { LookSkin(ground: Ink.ground, ink: Ink.ink, quiet: Ink.quiet, accent: Ink.blue, onAccent: Ink.onBlue, sheet: Ink.under, rule: Ink.rule, font: { size, weight in InkType.mono(size, weight == .bold || weight == .semibold ? .semibold : weight == .medium ? .medium : .regular) }, face: { id, size in id == "own" ? InkType.own(size) : Font(WritingFonts.font(LookFaces.drawn(id, own: "mono"), size: size)) }) }}/// The core's sample lines in the paper of one appearance, laid as the scene lays them: a heading, an action, a/// character's name indented and their words under it.struct StoryLookPreview: View { let answer: LookAnswer let dark: Bool private func colour(_ token: String, _ fallback: Color) -> Color { answer.colour(token, dark: dark) ?? fallback } var body: some View { let ink = colour("ink", Ink.ink) VStack(alignment: .leading, spacing: 10) { ForEach(Array((answer.preview?.lines ?? []).enumerated()), id: \.offset) { _, line in switch line.kind { case "heading": Text(line.text).font(InkType.mono(14.5, .semibold)).foregroundStyle(ink) case "character": Text(line.text).font(InkType.mono(13, .medium)).foregroundStyle(ink) .frame(maxWidth: .infinity, alignment: .center) case "dialogue": Text(line.text).font(InkType.line).foregroundStyle(ink) .padding(.horizontal, 28) .fixedSize(horizontal: false, vertical: true) default: Text(line.text).font(InkType.line).foregroundStyle(ink) .fixedSize(horizontal: false, vertical: true) } } Capsule().fill(colour("accent", Ink.blue)).frame(width: 24, height: 3) } .padding(18) .frame(maxWidth: .infinity, alignment: .leading) .background(RoundedRectangle(cornerRadius: 14).fill(colour("sheet", Ink.ground))) .overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(colour("rule", Ink.rule), lineWidth: 1)) }}#endif