// The MOOD face (KINDS, 7f4a5f0fb; house references 97 and 98): a moment// of a day on the framed cream card — the day written large by hand at the// top, the line the owner said typed heavy under it, as large as the card// lets it stand, the emotions named in it on little paper tags under that// (`subtitle`: the core's list of words, or words it joined), and under them// a house watercolour chosen by those emotions (`MoodScene`): the night sky// of reference 97 for a quiet moment, the rain cloud of 98 for a heavy one;// a moment that names neither keeps the sprig in the corner. Every word is// the core's (`DeckCard`); the face lays them out.importCottonPaperimportCottonValuesimportSwiftUIenumMoodFaceKnobs {staticlet inset = EdgeInsets(top: 30, leading: 30, bottom: 26, trailing: 28)staticlet dayHand: CGFloat = 34staticlet lineSize: CGFloat = 24staticlet lineLines = 7staticlet artShare: CGFloat = 0.3staticlet gap: CGFloat = 16staticlet chipGap: CGFloat = 10/// The scenes a moment may be drawn under, each with the emotions that/// call it. A picture, not a score: the vocabulary itself stays flat and/// alphabetical (`Emotions`), and a word in neither set draws neither.staticlet scenes: [(art: String, emotions: Set<String>)] = [ ("face-art-night-sky", ["bored", "calm", "content", "numb", "okay", "relieved", "tired"]), ("face-art-rain-cloud", ["afraid", "angry", "anxious", "ashamed", "awful", "frustrated", "guilty", "hurt", "lonely", "low","overwhelmed", "restless", "sad", "stressed", ]), ]staticlet sceneGap: CGFloat = 18}/// The house watercolour a moment is drawn under: the scene most of its/// emotions call, the one its first such emotion calls on a tie; none when/// no emotion calls one.enumMoodScene {staticfunc art(for emotions: [String]) -> String? {let called = emotions.compactMap { word inMoodFaceKnobs.scenes.firstIndex { $0.emotions.contains(word.lowercased()) } }guardlet first = called.first else { returnnil }let most = Dictionary(called.map { ($0, 1) }, uniquingKeysWith: +).max { a, b in a.value < b.value || (a.value == b.value && a.key != first) }?.key ?? firstreturnMoodFaceKnobs.scenes[most].art }}publicstructMoodFace: View {let card: DeckCardpublicinit(card: DeckCard) {self.card = card }publicvar body: someView {let emotions = card.words("subtitle")let scene = MoodScene.art(for: emotions)GeometryReader { sheet in ZStack(alignment: .bottomTrailing) {if scene == nil {FaceArt(name: "face-art-sprig") .frame(width: sheet.size.width * MoodFaceKnobs.artShare) .padding(.trailing, 18) .padding(.bottom, 16) } VStack(alignment: .leading, spacing: 0) {iflet day = card.text("date") {Text(HandRun.tail(day)) .font(CottonFonts.hand(MoodFaceKnobs.dayHand)) .lineLimit(1) .minimumScaleFactor(0.6) .faceInk(.ink) .accessibilityIdentifier("face-date") .facePart(.when) }iflet line = card.text("title") {HeavyType(words: line, size: MoodFaceKnobs.lineSize) .lineLimit(MoodFaceKnobs.lineLines) .minimumScaleFactor(0.6) .padding(.top, MoodFaceKnobs.gap) .accessibilityIdentifier("deck-title") .facePart(.title) }if !emotions.isEmpty {ChipWrap(spacing: MoodFaceKnobs.chipGap) {ForEach(Array(emotions.enumerated()), id: \.offset) { _, emotion inPaperChip(words: emotion) } } .padding(.top, MoodFaceKnobs.gap + 4) .accessibilityElement(children: .combine) .accessibilityIdentifier("face-chips") }iflet scene {FaceArt(name: scene) .frame(maxWidth: .infinity, maxHeight: .infinity) .padding(.top, MoodFaceKnobs.sceneGap) .layoutPriority(-1) }Spacer(minLength: 0) } .padding(MoodFaceKnobs.inset) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) } } .onCardPaper(MoodFaceCatalogue.stock.laid(card.pace)) }}/// The mood face, by the kind's name, and the cards it is reviewed in.publicenumMoodFaceCatalogue {publicstaticlet stock: FaceStock = .framedpublicstaticlet ground: FaceGround = .paperpublicstaticlet face = Face(id: "mood", specimens: [Specimen("evening", eveningMood), Specimen("quiet", quietMood)]) { card, _, _ inMoodFace(card: card) }/// A moment of an invented evening, two emotions named in it.publicstaticlet eveningMood = DeckCard(face: .mood, fields: ["date": .text("Fri 23 Oct"),"title": .text("Tired, but the example build finally went green and the evening is quiet."),"subtitle": .text("Tired \u{00B7} Relieved \u{00B7} Hopeful"), ])/// A moment nobody has named an emotion in yet.publicstaticlet quietMood = DeckCard(face: .mood, fields: ["date": .text("Thu 22 Oct"),"title": .text("Slow morning."), ])}