// A development build's invented screenplay, for looking at the Ink screens// on a simulator: brought in once, by the launch argument `-story-ink-seed// YES`, through the core's own script reader (`story.bring_in`). Never in a store build, and// never anyone's real script.#if os(iOS) && COTTON_DEVimportCottonKitimportFoundation@MainActorenumInkSeed {staticvar asked: Bool { UserDefaults.standard.bool(forKey: "story-ink-seed") }/// `-story-ink-crowd YES` brings in the crowded script instead: sixty invented/// characters, for the speaker chooser (`story-ink-crowd.json`).staticvar crowd: Bool { UserDefaults.standard.bool(forKey: "story-ink-crowd") }/// The invented screenplay is a bundled file (`Resources/Fixtures/story-ink-seed.json`),/// so no English a person reads is a Swift literal (as Story Dev's and Vault's seeds).privatestructInvented: Decodable { let name: String; let draft: String; let fountain: String }staticfunc seed(_ core: any CottonCalling, book: any StoryBook) asyncthrows {guard asked, tryawait book.list().stories.isEmpty else { return }guardlet url = Bundle.module.url(forResource: crowd ? "story-ink-crowd" : "story-ink-seed", withExtension: "json", subdirectory: "Fixtures"),let data = try? Data(contentsOf: url),let invented = try? JSONDecoder().decode(Invented.self, from: data) else { return }// Brought in as a picked file is (`story.bring_in`), from a copy of the words.let file = FileManager.default.temporaryDirectory.appendingPathComponent("story-ink-seed-\(UUID().uuidString).fountain")tryData(invented.fountain.utf8).write(to: file, options: .atomic)defer { try? FileManager.default.removeItem(at: file) } _ = tryawaitStoryShelf(core: core).bringIn(path: file.path(percentEncoded: false), name: invented.name)// One marked draft, so Drafts has a row to look at.iflet story = tryawait book.list().stories.first?.id {tryawaitStoryShelf(core: core).markDraft(story: story, name: invented.draft) } }}#endif