Cotton code
217 lines · 12.5 KB · TypeScriptRaw
/** * The invented world the seed writes about: names nobody carries, towns on no * map, shops and services that do not trade, and plain English sentences * about an ordinary year. Every proper noun here is made up; mail goes to the * reserved `.example` names (RFC 2606), numbers to the stand-in shape the * no-real-identities guard admits (four zeros in a row). */import type { Rng } from "./rng.ts";export const FIRST_NAMES = [  "Tavrin", "Elsko", "Marivo", "Quenna", "Iduro", "Rasvel", "Nolwe", "Sefany", "Kelvo", "Ombrisa",  "Juvel", "Pellio", "Yarrin", "Zoveth", "Ilkra", "Bremi", "Dasko", "Fennimo", "Galvi", "Ivro",  "Kesti", "Lumo", "Mervane", "Orrel", "Pimsa", "Quillo", "Rovanne", "Sulvi", "Tesko", "Ulme",  "Vessa", "Wenlo", "Yelva", "Corvi", "Amrel", "Brannoc", "Desmi", "Falke", "Hollis-Ann", "Jorvi",] as const;export const LAST_NAMES = [  "Ambersole", "Brackwind", "Corrowan", "Dellimere", "Everhollow", "Farrowgate", "Glimmerby", "Vaskhollin",  "Junipeak", "Kestrelmoor", "Larkwhistle", "Mossbridge", "Nettlefold", "Oakhallow", "Quarrystone",  "Rookwell", "Saffronby", "Thistlecombe", "Umberlane", "Vellacourt", "Wrenhallow", "Yarrowdene",  "Pellucine", "Hartsvane", "Ivelmore", "Cindersby", "Tallowmere", "Brindlecote",] as const;export const TOWNS = ["Kelmoor", "Ondravel", "Saltmere", "Brindlecove", "Tavelholm", "Quorrin", "Mirrowdale", "Pelland Cross", "Vessick", "Hollowford"] as const;export const VENUES = [  "Fennick's Teahouse", "the Glassbell Hall", "Umbra Park", "Kelmoor Library", "the Saltmere pier", "Quorrin Market",  "the Lantern Rooms", "Mirrowdale Common", "the boathouse at Tavelholm", "Ondravel Clinic", "Vessick Pool", "the Copperkettle Diner",  "Hollowford Station", "the studio on Wick Lane", "Brindlecove Gardens", "the old mill at Pelland Cross",] as const;export const ORGS = ["Lumenfold Works", "Driftnote Studio", "Quillfeather Press", "Saltmere Cooperative", "Orrin Telecom", "Kelmoor Council", "Velvetmoss Design", "Hearthstone Clinic", "Tidewell Labs", "Ashgrove School"] as const;export const ROLES = ["designer", "teacher", "nurse", "carpenter", "editor", "engineer", "baker", "librarian", "gardener", "pharmacist", "architect", "musician", "accountant", "translator"] as const;const FOODS = ["dal", "lemon rice", "a pot of soup", "flatbreads", "a plum cake", "noodles", "a big salad", "roasted squash", "dumplings", "a pan of eggs", "ginger tea", "pancakes"] as const;const THINGS = ["the bike", "the kitchen shelf", "the balcony plants", "the spare room", "the old radio", "the blue lamp", "the garden gate", "the tool box", "the bookcase", "the window seal"] as const;const DAYS = ["on Sunday", "this weekend", "tomorrow morning", "after work", "next Tuesday", "before the rains", "at the end of the month", "on Friday evening"] as const;const FEELINGS = ["tired but glad", "quietly happy", "restless", "calm", "a bit low", "full of plans", "relieved", "grateful"] as const;const NOTE_TITLES = [  "Garden plan", "Things to fix at home", "Recipe: lemon rice", "Trip to Saltmere", "Ideas for the studio", "Books to look for",  "Notes from the council meeting", "Packing list", "Weekly reset", "What the plumber said", "Birthday ideas", "A slower morning",  "Questions for the clinic", "The balcony project", "Learning the guitar", "Money this quarter", "Rainy-season checklist", "Letters to write",  "Walking routes around Kelmoor", "On keeping a notebook",] as const;const NOTE_SENTENCES = [  "I keep coming back to {thing}; it needs an afternoon, not a weekend.",  "{person} suggested we try {venue} {day}, and I think we should.",  "Made {food} again and it was better with less salt.",  "The light in the morning is different now, softer and later.",  "Wrote down three things I want from the next month: rest, a clean desk, and more walks.",  "The repair on {thing} cost less than I feared.",  "I want to keep this list short so I actually finish it.",  "{person} lent me a book and I have not opened it yet.",  "Felt {feeling} after the long walk to {venue}.",  "The bus from {town} was late again, so I read on the bench.",  "Next time, start earlier and pack lighter.",  "Ask {person} about the recipe they mentioned.",  "There is a market in {town} on the first Saturday of every month.",  "I should write more often, even a line a day.",  "The plan is simple: one room at a time.",  "Bought seeds for tomatoes, basil and marigolds.",  "It rained all afternoon and the garden looked grateful.",  "Spent the evening sorting old photos into boxes.",  "Called the clinic and moved the appointment to {day}.",  "Remember to water the plants before leaving.",  "The new shelf fits, just, with a finger's width to spare.",  "{person} and I talked for an hour about nothing in particular, which was perfect.",  "Tried a new route home along the river; it adds ten minutes and is worth it.",  "Budget is fine this month if I skip the second coffee.",  "I would like to learn to fix {thing} myself.",  "Quiet day. Cleaned, cooked {food}, read on the balcony.",] as const;const MESSAGE_LINES = [  "Are you free {day}?", "On my way!", "Running ten minutes late, sorry", "Did you get home okay?", "That sounds lovely",  "Can you bring {food}?", "Ha, yes", "I saw this and thought of you", "Call me when you can", "Thank you so much!",  "See you at {venue}", "How did it go?", "Happy birthday! 🎉", "Good morning ☀️", "Let's do it", "I'll check and tell you",  "Not today, maybe {day}", "The bus is stuck in traffic", "Did you try {food}? So good", "Sending you the address now",  "Miss you all", "Who's coming {day}?", "I can pick you up", "Done ✅", "Ok 👍", "Wait, really?", "Sounds like a plan",  "Sorry, missed your call", "Back home now", "Fixed {thing} finally!", "What time works for you?", "I'm in",  "Let me know if you need anything", "Haha that's so true", "Drinking ginger tea and reading", "Can we move it to {day}?",] as const;const EVENT_TITLES: ReadonlyArray<{ title: string; kind: string; hours: number; allDay?: boolean }> = [  { title: "Coffee with {person}", kind: "coffee", hours: 1 },  { title: "Dinner at {venue}", kind: "dinner", hours: 2 },  { title: "Lunch with {person}", kind: "lunch", hours: 1.5 },  { title: "Dentist", kind: "doctor", hours: 1 },  { title: "Yoga class", kind: "yoga", hours: 1 },  { title: "Swim at Vessick Pool", kind: "swim", hours: 1 },  { title: "Team meeting", kind: "meeting", hours: 1 },  { title: "Call with {person}", kind: "call", hours: 0.5 },  { title: "Train to {town}", kind: "train", hours: 3 },  { title: "Pottery class", kind: "class", hours: 2 },  { title: "Morning run", kind: "run", hours: 1 },  { title: "Gym", kind: "gym", hours: 1 },  { title: "Rent due", kind: "payment", hours: 0.5 },  { title: "Parcel delivery", kind: "delivery", hours: 2 },  { title: "Haircut", kind: "appointment", hours: 1 },  { title: "Market run", kind: "errand", hours: 1 },  { title: "{person}'s birthday", kind: "birthday", hours: 0, allDay: true },  { title: "Film night at {venue}", kind: "show", hours: 3 },  { title: "Walk around {venue}", kind: "walk", hours: 1.5 },  { title: "Project deadline", kind: "deadline", hours: 0, allDay: true },];const TRIPS = ["Trip to {town}", "Weekend in {town}", "Visiting family in {town}", "Workshop in {town}"] as const;const TODO_TITLES = [  "Fix {thing}", "Buy seeds for the balcony", "Return {person}'s book", "Book the dentist", "Renew the bus pass", "Pay the water bill",  "Call {person}", "Clean out the fridge", "Back up the phone", "Send the birthday card", "Order a new kettle", "Water the plants",  "Sort the old photos", "Write to {person}", "Take the bike for a service", "Pick up the parcel", "Plan the trip to {town}",  "Cook {food} for the weekend", "Recycle the old newspapers", "Measure the window for curtains", "Find the warranty for the radio",  "Make a list for the market", "Read twenty pages", "Change the bedsheets", "Look up the pottery class times",] as const;const MEMORY_LINES = [  "I prefer mornings for writing and afternoons for errands.",  "{person} is allergic to peanuts; bring something else when cooking for them.",  "The spare key is with {person} on the second floor.",  "I like my tea with ginger and no sugar.",  "My bike is a blue three-speed; the lock code is kept in Passwords, not here.",  "I take the bus from {town} on weekdays and walk on weekends.",  "{person}'s birthday dinner is always at {venue}.",  "I am learning the guitar, slowly, with a teacher on Thursdays.",  "The landlord prefers messages to calls.",  "I keep a notebook by the bed for ideas at night.",  "I avoid meetings before ten when I can.",  "My usual market is Quorrin Market on Saturdays.",  "{person} and I swap books every month.",  "I am vegetarian on weekdays.",  "I would like a quieter December this year.",  "I sleep better when the phone stays in the kitchen.",  "The plants on the balcony need water every two days in summer.",  "I am saving for a trip to {town} next spring.",  "Pottery is on Wednesday evenings at the studio on Wick Lane.",  "I like long walks along the river after rain.",  "When I am stuck, a walk around {venue} helps.",  "{person} is the person to ask about plants.",] as const;export const FILM_TITLES = [  "The Lantern Keeper", "Seven Rivers of Glass", "A Summer in Ondravel", "The Clockmaker's Daughter", "Northbound Quietly",  "Paper Moons over Saltmere", "The Last Ferry", "Small Hours", "Where the Kites Go", "The Copper Orchard", "Halfway to Morning", "Glasswing",] as const;export const BOOK_TITLES = [  "The Salt Road Letters", "An Atlas of Small Towns", "The Weaver's Year", "Notes on Rain", "The Hollow Lighthouse",  "Gardens of the Low Hills", "A Field Guide to Ordinary Birds", "The Patient Kettle", "Ink and Ember", "Stories from Pelland Cross",  "The Long Table", "Under the Mirrowdale Bridge",] as const;export const GROUPS = ["Family", "Wick Lane neighbours", "Pottery Wednesdays", "Saltmere trip", "Book swap"] as const;export const SERVICE_MAIL: ReadonlyArray<{ from: string; address: string; subjects: readonly string[] }> = [  { from: "Tallowmere Water Board", address: "billing@tallowmere.example", subjects: ["Your water bill for {month}", "Planned maintenance on your street"] },  { from: "Kelmoor Library", address: "hello@kelmoor-library.example", subjects: ["Your books are due {day}", "New this month at the library"] },  { from: "Orrin Telecom", address: "no-reply@orrin.example", subjects: ["Your {month} statement is ready", "Your plan renews soon"] },  { from: "Quillfeather Press", address: "club@quillfeather.example", subjects: ["Your next book ships soon", "A note from the editors"] },];const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] as const;/** Every slot a template may name, filled from the stream. */export interface Cast {  person: () => string;}export function fill(rng: Rng, template: string, cast: Cast): string {  return template.replace(/\{(\w+)\}/g, (_, slot: string) => {    switch (slot) {      case "person":        return cast.person();      case "venue":        return rng.pick(VENUES);      case "town":        return rng.pick(TOWNS);      case "food":        return rng.pick(FOODS);      case "thing":        return rng.pick(THINGS);      case "day":        return rng.pick(DAYS);      case "feeling":        return rng.pick(FEELINGS);      case "month":        return rng.pick(MONTHS);      default:        throw new Error(`no slot {${slot}}`);    }  });}export const capitalise = (s: string): string => (s ? s[0]!.toUpperCase() + s.slice(1) : s);export function noteTitle(rng: Rng): string {  return rng.pick(NOTE_TITLES);}export function paragraphs(rng: Rng, cast: Cast, count: number): string {  const out: string[] = [];  for (let p = 0; p < count; p += 1) {    const n = rng.int(2, 5);    out.push(rng.some(NOTE_SENTENCES, n).map((s) => capitalise(fill(rng, s, cast))).join(" "));  }  return out.join("\n\n");}export const messageLine = (rng: Rng, cast: Cast): string => fill(rng, rng.pick(MESSAGE_LINES), cast);export const eventShape = (rng: Rng): (typeof EVENT_TITLES)[number] => rng.pick(EVENT_TITLES);export const tripTitle = (rng: Rng, cast: Cast): string => fill(rng, rng.pick(TRIPS), cast);export const todoTitle = (rng: Rng, cast: Cast): string => fill(rng, rng.pick(TODO_TITLES), cast);export const memoryLine = (rng: Rng, cast: Cast, n: number): string => fill(rng, MEMORY_LINES[n % MEMORY_LINES.length]!, cast);export const sentence = (rng: Rng, cast: Cast): string => capitalise(fill(rng, rng.pick(NOTE_SENTENCES), cast));