create-ifloom 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -2
  3. package/bin.js +4 -0
  4. package/dist/bin.js +391 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/examples/cafe/index.html +12 -0
  7. package/dist/examples/cafe/package.json +24 -0
  8. package/dist/examples/cafe/src/game.ts +41 -0
  9. package/dist/examples/cafe/src/layout.tsx +49 -0
  10. package/dist/examples/cafe/src/main.ts +7 -0
  11. package/dist/examples/cafe/src/rules.ts +38 -0
  12. package/dist/examples/cafe/src/story/hiring.ts +25 -0
  13. package/dist/examples/cafe/src/story/opening.ts +19 -0
  14. package/dist/examples/cafe/src/styles.css +7 -0
  15. package/dist/examples/cafe/src/world/actions.ts +40 -0
  16. package/dist/examples/cafe/src/world/menu.ts +14 -0
  17. package/dist/examples/cafe/src/world/staff.ts +12 -0
  18. package/dist/examples/cafe/src/world/stats.ts +10 -0
  19. package/dist/examples/cafe/src/world/triggers.ts +18 -0
  20. package/dist/examples/cafe/tsconfig.json +9 -0
  21. package/dist/examples/cafe/vite.config.ts +7 -0
  22. package/dist/examples/novel/index.html +12 -0
  23. package/dist/examples/novel/package.json +24 -0
  24. package/dist/examples/novel/src/game.ts +49 -0
  25. package/dist/examples/novel/src/layout.tsx +25 -0
  26. package/dist/examples/novel/src/main.ts +8 -0
  27. package/dist/examples/novel/src/story/ch1.ts +36 -0
  28. package/dist/examples/novel/src/story/ch2.ts +42 -0
  29. package/dist/examples/novel/src/story/ch3.ts +41 -0
  30. package/dist/examples/novel/src/styles.css +7 -0
  31. package/dist/examples/novel/src/world/stats.ts +6 -0
  32. package/dist/examples/novel/tsconfig.json +9 -0
  33. package/dist/examples/novel/vite.config.ts +7 -0
  34. package/dist/examples/showcase/.env +4 -0
  35. package/dist/examples/showcase/index.html +12 -0
  36. package/dist/examples/showcase/package.json +43 -0
  37. package/dist/examples/showcase/public/art/character/ava.svg +1 -0
  38. package/dist/examples/showcase/public/art/character/sam.svg +1 -0
  39. package/dist/examples/showcase/public/art/photo/ava.svg +1 -0
  40. package/dist/examples/showcase/public/art/photo/sam.svg +1 -0
  41. package/dist/examples/showcase/src/game.ts +168 -0
  42. package/dist/examples/showcase/src/layout.tsx +84 -0
  43. package/dist/examples/showcase/src/main.tsx +55 -0
  44. package/dist/examples/showcase/src/place.ts +8 -0
  45. package/dist/examples/showcase/src/rules.ts +51 -0
  46. package/dist/examples/showcase/src/story/ava.prose.ts +12 -0
  47. package/dist/examples/showcase/src/story/ava.ts +199 -0
  48. package/dist/examples/showcase/src/story/cafe.ts +157 -0
  49. package/dist/examples/showcase/src/story/flat.ts +90 -0
  50. package/dist/examples/showcase/src/story/high-street.ts +37 -0
  51. package/dist/examples/showcase/src/story/moving-day.ts +74 -0
  52. package/dist/examples/showcase/src/story/office.ts +26 -0
  53. package/dist/examples/showcase/src/story/park.ts +172 -0
  54. package/dist/examples/showcase/src/story/sam.ts +27 -0
  55. package/dist/examples/showcase/src/styles.css +8 -0
  56. package/dist/examples/showcase/src/ui.ts +44 -0
  57. package/dist/examples/showcase/src/unlocks/supporter.ts +40 -0
  58. package/dist/examples/showcase/src/world/achievements.ts +13 -0
  59. package/dist/examples/showcase/src/world/actions.ts +13 -0
  60. package/dist/examples/showcase/src/world/cast.ts +46 -0
  61. package/dist/examples/showcase/src/world/cheats.ts +33 -0
  62. package/dist/examples/showcase/src/world/phone.ts +88 -0
  63. package/dist/examples/showcase/src/world/settings.ts +24 -0
  64. package/dist/examples/showcase/src/world/stats.ts +24 -0
  65. package/dist/examples/showcase/src/world/strings.ts +7 -0
  66. package/dist/examples/showcase/src/world/things.ts +59 -0
  67. package/dist/examples/showcase/tsconfig.json +9 -0
  68. package/dist/examples/showcase/vite.config.ts +7 -0
  69. package/dist/templates/next/AGENTS.md +60 -0
  70. package/dist/templates/next/README.md +33 -0
  71. package/dist/templates/next/app/Game.tsx +46 -0
  72. package/dist/templates/next/app/layout.tsx +13 -0
  73. package/dist/templates/next/app/page.tsx +6 -0
  74. package/dist/templates/next/gitignore +6 -0
  75. package/dist/templates/next/next.config.ts +6 -0
  76. package/dist/templates/next/package.json +32 -0
  77. package/dist/templates/next/postcss.config.mjs +6 -0
  78. package/dist/templates/next/src/layout.tsx +73 -0
  79. package/dist/templates/next/src/styles.css +16 -0
  80. package/dist/templates/next/tsconfig.json +21 -0
  81. package/dist/templates/plugin/README.md +81 -0
  82. package/dist/templates/plugin/gitignore +2 -0
  83. package/dist/templates/plugin/package.json +64 -0
  84. package/dist/templates/plugin/src/index.ts +162 -0
  85. package/dist/templates/plugin/src/react/index.tsx +95 -0
  86. package/dist/templates/plugin/tests/contracts.test.ts +28 -0
  87. package/dist/templates/plugin/tests/plugin.test.ts +59 -0
  88. package/dist/templates/plugin/tests/react.test.tsx +47 -0
  89. package/dist/templates/plugin/tsconfig.json +21 -0
  90. package/dist/templates/plugin/tsdown.config.ts +14 -0
  91. package/dist/templates/react/package.json +28 -0
  92. package/dist/templates/react/src/layout.tsx +69 -0
  93. package/dist/templates/react/src/main.ts +11 -0
  94. package/dist/templates/react/src/styles.css +16 -0
  95. package/dist/templates/react/vite.config.ts +7 -0
  96. package/dist/templates/shared/AGENTS.md +58 -0
  97. package/dist/templates/shared/gitignore +3 -0
  98. package/dist/templates/shared/index.html +12 -0
  99. package/dist/templates/shared/src/game.ts +23 -0
  100. package/dist/templates/shared/src/story/opening.ts +34 -0
  101. package/dist/templates/shared/src/styles.css +228 -0
  102. package/dist/templates/shared/src/world/stats.ts +6 -0
  103. package/dist/templates/shared/tsconfig.json +9 -0
  104. package/dist/templates/shared/vite.config.ts +5 -0
  105. package/dist/templates/svelte/package.json +25 -0
  106. package/dist/templates/svelte/src/App.svelte +11 -0
  107. package/dist/templates/svelte/src/Beat.svelte +31 -0
  108. package/dist/templates/svelte/src/InputField.svelte +36 -0
  109. package/dist/templates/svelte/src/Layout.svelte +84 -0
  110. package/dist/templates/svelte/src/Line.svelte +26 -0
  111. package/dist/templates/svelte/src/Minigame.svelte +21 -0
  112. package/dist/templates/svelte/src/Panel.svelte +27 -0
  113. package/dist/templates/svelte/src/main.ts +5 -0
  114. package/dist/templates/svelte/src/runner.ts +29 -0
  115. package/dist/templates/svelte/vite.config.ts +5 -0
  116. package/dist/templates/vanilla/package.json +22 -0
  117. package/dist/templates/vanilla/src/layout.ts +35 -0
  118. package/dist/templates/vanilla/src/main.ts +253 -0
  119. package/dist/templates/vue/package.json +25 -0
  120. package/dist/templates/vue/src/App.vue +12 -0
  121. package/dist/templates/vue/src/Beat.vue +28 -0
  122. package/dist/templates/vue/src/InputField.vue +34 -0
  123. package/dist/templates/vue/src/Layout.vue +84 -0
  124. package/dist/templates/vue/src/Line.vue +41 -0
  125. package/dist/templates/vue/src/Minigame.vue +19 -0
  126. package/dist/templates/vue/src/Panel.vue +30 -0
  127. package/dist/templates/vue/src/main.ts +5 -0
  128. package/dist/templates/vue/src/runner.ts +32 -0
  129. package/dist/templates/vue/vite.config.ts +5 -0
  130. package/package.json +48 -4
  131. package/src/bin.ts +18 -0
  132. package/src/create.ts +89 -0
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Small Town, put together: its content, with a base that says what the game
3
+ * is and holds its code, its plugins and its rules. This file only
4
+ * assembles. What the whole town shares is in `world/`, one file per kind,
5
+ * and the story is in `story/`, one file per place or arc, its prose beside
6
+ * it. The game's own code is in `rules.ts`.
7
+ */
8
+ import { loadGame, type Content, type Game, type Pack, type Problem } from '@ifloom/engine'
9
+ import { defineGame, probe, type Probe, type ProbeStep } from '@ifloom/cli/game'
10
+ import { achievements } from '@ifloom/plugin-achievements'
11
+ import { calendar } from '@ifloom/plugin-calendar'
12
+ import { places } from '@ifloom/plugin-places'
13
+ import { cast } from '@ifloom/plugin-cast'
14
+ import { debug } from '@ifloom/plugin-debug'
15
+ import { statuses } from '@ifloom/plugin-statuses'
16
+ import { generators } from '@ifloom/plugin-generators'
17
+ import { jobs } from '@ifloom/plugin-jobs'
18
+ import { quests } from '@ifloom/plugin-quests'
19
+ import { shop } from '@ifloom/plugin-shop'
20
+ import { wardrobe } from '@ifloom/plugin-wardrobe'
21
+ import { inventory } from '@ifloom/plugin-inventory'
22
+ import { unlocks } from '@ifloom/plugin-unlocks'
23
+ import { devices } from '@ifloom/plugin-devices'
24
+ import { messages } from '@ifloom/plugin-messages'
25
+ import { feed } from '@ifloom/plugin-feed'
26
+ import { rules } from './rules.ts'
27
+ import { stats } from './world/stats.ts'
28
+ import { things } from './world/things.ts'
29
+ import { people } from './world/cast.ts'
30
+ import { settings } from './world/settings.ts'
31
+ import { actions } from './world/actions.ts'
32
+ import { phone } from './world/phone.ts'
33
+ import { achievements as achievementsContent } from './world/achievements.ts'
34
+ import { cheats as cheatsContent } from './world/cheats.ts'
35
+ import { strings } from './world/strings.ts'
36
+ import { movingDay } from './story/moving-day.ts'
37
+ import { ava } from './story/ava.ts'
38
+ import { flat } from './story/flat.ts'
39
+ import { highStreet } from './story/high-street.ts'
40
+ import { cafe } from './story/cafe.ts'
41
+ import { park } from './story/park.ts'
42
+ import { office } from './story/office.ts'
43
+ import { sam } from './story/sam.ts'
44
+
45
+ /**
46
+ * The town's content: what it all shares, then the story by arc and place.
47
+ * Lists keep this order, so triggers fire in it, and the quest log, the job
48
+ * board and the places list show things in it.
49
+ */
50
+ export const content: Content[] = [
51
+ // The phone first: its `photo` kind, for the camera's photos, and the phone with its apps, the texts and the feed.
52
+ phone,
53
+ strings,
54
+ stats,
55
+ things,
56
+ people,
57
+ settings,
58
+ actions,
59
+ achievementsContent,
60
+ cheatsContent,
61
+ movingDay,
62
+ ava,
63
+ flat,
64
+ highStreet,
65
+ cafe,
66
+ park,
67
+ office,
68
+ sam,
69
+ ]
70
+
71
+ /** The town's calendar: a turn is a day, and a new game starts on the night you move in. */
72
+ export const clock = calendar({ start: { day: 0, period: 'night' } })
73
+
74
+ /**
75
+ * Build the game. `withDebug` adds the debugger; leave it off in a release
76
+ * build. `unlocked` are the supporter packs the player's codes have opened
77
+ * (from `unlockedPacks`), and `mods` the packs of the player's mods, loaded
78
+ * over the town's content in that order.
79
+ */
80
+ export function smallTown({ withDebug = false, unlocked = [] as Pack[], mods = [] as Pack[] } = {}): { game: Game; problems: Problem[] } {
81
+ const { game, problems } = loadGame(
82
+ content,
83
+ {
84
+ id: 'small-town',
85
+ title: 'Small Town',
86
+ // The calendar first, so every other plugin sees the new day when one begins.
87
+ plugins: [
88
+ clock,
89
+ // After the calendar, so the header reads "Day 1 · Monday morning · Your flat".
90
+ places({ start: 'flat' }),
91
+ cast(),
92
+ // The phone is these three, put together in world/phone.ts: devices for its apps, and the texts and the feed they show.
93
+ devices(),
94
+ messages(),
95
+ feed(),
96
+ quests(),
97
+ statuses(),
98
+ achievements(),
99
+ shop(),
100
+ jobs(),
101
+ generators(),
102
+ wardrobe(),
103
+ // Using, dropping and giving away what you hold: the sandwich, the paper.
104
+ inventory(),
105
+ // Cheats and supporter codes, for players: one code opens a cheat and a scene. The debugger below is for the developer.
106
+ unlocks(),
107
+ ...(withDebug ? [debug()] : []),
108
+ ],
109
+ rules,
110
+ },
111
+ // Packs go over the content: what the player's codes opened, then their mods.
112
+ { packs: [...unlocked, ...mods] },
113
+ )
114
+ return { game, problems }
115
+ }
116
+
117
+ /** A command that opens the phone's camera, for tests and walkthroughs. */
118
+ export const openCamera = devices.open('camera')
119
+
120
+ /** A day goes by, and Ava says hello on it: her scene opened and left, as the player does. */
121
+ const helloFromAva: ProbeStep[] = [{ turn: true }, { play: { type: 'scene', id: 'ava.hi' } }, { play: { type: 'leave' } }]
122
+
123
+ /**
124
+ * The states `ifloom snapshot` renders every scene and place in, each made by
125
+ * playing: moving day; the first morning, after unpacking and a night's
126
+ * sleep; and a week in, with Ava's hello seen on four of its days, the cat
127
+ * named, a friendship grown, the raincoat off, a coffee inside you and
128
+ * people in the park.
129
+ */
130
+ function probes(game: Game): Probe[] {
131
+ const firstMorning = probe('first-morning', game, [{ play: { type: 'choose', id: 'unpack' } }, { play: calendar.sleep() }])
132
+ const aWeekIn = probe(
133
+ 'a-week-in',
134
+ game,
135
+ [
136
+ // Days 2, 3 and 4 with a hello each, a quiet day 5, a hello on day 6, then day 7's afternoon.
137
+ ...helloFromAva,
138
+ ...helloFromAva,
139
+ ...helloFromAva,
140
+ { turn: true },
141
+ ...helloFromAva,
142
+ { turn: true },
143
+ { 'calendar/set': { period: 'afternoon' } },
144
+ // The raincoat off, as the player takes it off.
145
+ { play: { 'wardrobe/takeOff': { id: 'coat' } } },
146
+ { kv: 'catName', to: 'Biscuit' },
147
+ { stat: 'charm', to: 5 },
148
+ { stat: 'friendship', of: 'character:ava', to: 30 },
149
+ // Still buzzing from the morning's coffee.
150
+ statuses.apply('caffeinated'),
151
+ // Two of the day's park visitors, made as the park's trigger makes them.
152
+ { 'generators/generate': { template: 'visitor', count: 2 } },
153
+ ],
154
+ firstMorning,
155
+ )
156
+ return [probe('moving-day', game, []), firstMorning, aWeekIn]
157
+ }
158
+
159
+ /**
160
+ * What the command line reads: the release build of the town, with the
161
+ * supporter content `ifloom check` passes as `unlocked`, read from
162
+ * src/unlocks/; moving day as the start; and the states `ifloom snapshot`
163
+ * renders every scene and place in.
164
+ */
165
+ export default defineGame({
166
+ build: ({ unlocked }) => smallTown({ unlocked }),
167
+ probes,
168
+ })
@@ -0,0 +1,84 @@
1
+ import {
2
+ Changes,
3
+ Clock,
4
+ Game,
5
+ GameMenu,
6
+ InputFields,
7
+ NoticeStrip,
8
+ Notices,
9
+ Overlay,
10
+ PanelHost,
11
+ RoomActions,
12
+ Scene,
13
+ Section,
14
+ Sidebar,
15
+ StatList,
16
+ Story,
17
+ Title,
18
+ useWords,
19
+ } from '@ifloom/react'
20
+ import { AchievementsButton } from '@ifloom/plugin-achievements/react'
21
+ import { PeopleHere, PeopleSection } from '@ifloom/plugin-cast/react'
22
+ import { CheatsButton } from '@ifloom/plugin-unlocks/react'
23
+ import { DebugCard } from '@ifloom/plugin-debug/react'
24
+ import { DeviceButtons } from '@ifloom/plugin-devices/react'
25
+ import { InventoryCard } from '@ifloom/plugin-inventory/react'
26
+ import { places } from '@ifloom/plugin-places'
27
+ import { Exits, LocationCard } from '@ifloom/plugin-places/react'
28
+ import { QuestsSection } from '@ifloom/plugin-quests/react'
29
+ import { StatusList } from '@ifloom/plugin-statuses/react'
30
+ import { WARDROBE_WORDS, WardrobeCard } from '@ifloom/plugin-wardrobe/react'
31
+
32
+ /**
33
+ * The showcase's layout: the React UI's own (`DefaultLayout`) with the
34
+ * plugins' parts placed by hand, and four changes. What the last command
35
+ * changed shows as pills under the scene. The notice strip sits
36
+ * over the story, a row of unread counts that open where they are. What
37
+ * you're wearing shows at home only: out and about, the wardrobe is the
38
+ * flat's "Open the wardrobe", which opens it as a panel. And the inventory
39
+ * has drop buttons.
40
+ */
41
+ export function Layout() {
42
+ const words = useWords(WARDROBE_WORDS)
43
+ return (
44
+ <Game>
45
+ <Sidebar>
46
+ <Title />
47
+ <Clock />
48
+ <GameMenu />
49
+ <Section id="stats" title={words('stats')} collapsible open>
50
+ <StatList />
51
+ <StatusList />
52
+ </Section>
53
+ <QuestsSection />
54
+ <PeopleSection />
55
+ <Section id="inventory" title={words('inventory')} collapsible>
56
+ {/* With a drop button: what you drop lies in the room, in the location card, until you pick it up. */}
57
+ <InventoryCard title={false} drop />
58
+ </Section>
59
+ <Section id="wardrobe" title={words('wardrobe')} collapsible when={places.at('flat')}>
60
+ <WardrobeCard title={false} />
61
+ </Section>
62
+ <AchievementsButton />
63
+ <CheatsButton />
64
+ <DeviceButtons />
65
+ </Sidebar>
66
+ <Story>
67
+ <NoticeStrip />
68
+ <Scene />
69
+ {/* What the last choice changed, as pills: the default layout leaves them out. */}
70
+ <Changes />
71
+ <InputFields />
72
+ <LocationCard />
73
+ <Exits />
74
+ <RoomActions />
75
+ <PeopleHere />
76
+ <DebugCard />
77
+ </Story>
78
+ <PanelHost />
79
+ <Overlay>
80
+ <Notices />
81
+ </Overlay>
82
+ </Game>
83
+ )
84
+ }
@@ -0,0 +1,55 @@
1
+ import { StrictMode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import { indexedDbDriver, localStorageDriver } from '@ifloom/browser'
4
+ import { createRunner, describeProblem, mods, profile, saves, startingState } from '@ifloom/engine'
5
+ import { GameShell, type PagesOptions } from '@ifloom/react'
6
+ import { unlockedPacks } from '@ifloom/plugin-unlocks'
7
+ import { smallTown } from './game.ts'
8
+ import { Layout } from './layout.tsx'
9
+ import { townUi } from './ui.ts'
10
+ import './styles.css'
11
+
12
+ const driver = localStorageDriver(window.localStorage)
13
+ // The profile keeps what outlives a save: the player's settings, and the supporter code once it has worked.
14
+ // It's opened before the game is built, to find the supporter content the player's code opens.
15
+ const stored = profile({ id: 'small-town' }, driver)
16
+ const unlocked = await unlockedPacks('small-town', stored)
17
+
18
+ // The player's mods live in IndexedDB; they're loaded over the town at start-up. Without the storage, the town starts without them.
19
+ const modStore = mods('small-town', indexedDbDriver({ database: 'small-town-mods' }))
20
+ const modPacks = await modStore.packs()
21
+ if (!modPacks.ok) console.warn(modPacks.reason, modPacks.cause)
22
+ const built = smallTown({ withDebug: import.meta.env.DEV, unlocked: unlocked.packs, mods: modPacks.ok ? modPacks.value : [] })
23
+ const { game } = built
24
+ const problems = built.problems.map(describeProblem)
25
+ if (problems.length) console.warn(problems.join('\n'))
26
+
27
+ // The title screen's New game starts afresh with a random seed; this state is
28
+ // only what's in play until the player picks something there.
29
+ const runner = createRunner(game, startingState(game, { seed: Math.floor(Math.random() * 2 ** 31) }), {
30
+ history: { depth: 50 },
31
+ backlog: { limit: 200 },
32
+ saves: saves(game, driver),
33
+ profile: stored,
34
+ autosave: { every: 'turn' },
35
+ })
36
+
37
+ const pages: PagesOptions = {
38
+ subtitle: 'A new flat, a new town, and a cat with no name.',
39
+ credits: ['Small Town is the IFLoom showcase.', { label: 'Made with IFLoom', href: 'https://ifloom.dev/' }],
40
+ }
41
+
42
+ createRoot(document.getElementById('root')!).render(
43
+ <StrictMode>
44
+ {/* `keys`: 1 to 9 pick the choices on screen, each showing its number, and Escape opens the menu. */}
45
+ {/* `plugins`: the plugins' own UIs. The unlocks UI puts a code box on the settings page; a code that opens new content reloads the page to add it, as a mod does. */}
46
+ <GameShell
47
+ runner={runner}
48
+ pages={pages}
49
+ layout={Layout}
50
+ keys
51
+ mods={{ store: modStore, problems, onChange: () => location.reload() }}
52
+ plugins={townUi({ problems: unlocked.problems, onChange: () => location.reload() })}
53
+ />
54
+ </StrictMode>,
55
+ )
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A location with the town's default: the line under its name is Small
3
+ * Town. Each place's file in `story/` writes its place with it, in its
4
+ * `entities`, with the words the room shows in its `body`.
5
+ */
6
+ import { places, type PlaceDef } from '@ifloom/plugin-places'
7
+
8
+ export const place = (def: PlaceDef) => places.location({ description: 'Small Town', ...def })
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Small Town's own code: its rules, the hooks and the functions its content
3
+ * calls by name, as `game/…`. Everything else in the game is data, in
4
+ * `world/` and `story/`.
5
+ */
6
+ import { entityImage, heldBy, parseRef, PLAYER, type GameRules } from '@ifloom/engine'
7
+ import { feed } from '@ifloom/plugin-feed'
8
+
9
+ /**
10
+ * The game's own calls, declared as a plugin declares its own, so content
11
+ * written in code is checked: `{ 'game/postLatest': true }` compiles, and a
12
+ * call with arguments it doesn't take doesn't.
13
+ */
14
+ declare module '@ifloom/engine' {
15
+ interface EffectRegistry {
16
+ 'game/postLatest': true
17
+ }
18
+ }
19
+
20
+ /**
21
+ * How the town runs: energy back overnight, the cat's name, and one effect
22
+ * worked out from the state, a macro. What's locked when, and what each day resets,
23
+ * are content, in the story.
24
+ */
25
+ export const rules: GameRules = {
26
+ // Energy back to full overnight.
27
+ onTurn: (_state, { apply }) => apply([{ stat: 'energy', to: 100 }]),
28
+ values: {
29
+ // The cat's name as the player typed it, or a cat with no name yet.
30
+ catName: (state) => (typeof state.kv.catName === 'string' ? state.kv.catName : 'The cat'),
31
+ },
32
+ // Content calls these as `game/…`: `{{catName}}`, `{ 'game/postLatest': true }`.
33
+ // A macro is an effect that stands for others: it returns plain effects, so a button's price sees them.
34
+ macros: {
35
+ // Post the newest photo, and roll how it does. It returns plain effects, a plugin's
36
+ // included, and draws its dice from the save's seed, so the same save gets the same likes.
37
+ postLatest: (state, _args, { game, roll }) => {
38
+ const photos = heldBy(state, game, PLAYER).filter(({ ref }) => parseRef(ref)?.kind === 'photo')
39
+ const latest = photos.at(-1)?.ref
40
+ if (!latest) return []
41
+ const image = entityImage(state, game, latest)
42
+ const id = `post.photo.${parseRef(latest)!.id}`
43
+ const likes = 2 + roll(10, 'likes') + (state.stats.charm ?? 0)
44
+ return [
45
+ feed.post('social', id, { text: 'New town, new faces.', ...(image ? { image } : {}) }),
46
+ { stat: 'charm', by: 1 },
47
+ feed.react(id, { likes, from: 'ava', text: 'Lovely!' }),
48
+ ]
49
+ },
50
+ },
51
+ }
@@ -0,0 +1,12 @@
1
+ /** Ava's lines read by key: her small talk at the café, drawn as variants, and the pool of texts she sends. */
2
+ export const prose: Record<string, string> = {
3
+ // Named lines: they follow another of Ava's, and a bare quote there would read as the player's.
4
+ 'ava.smalltalk.rain': '@ava: "Rain later. The ducks know before the forecast does."',
5
+ 'ava.smalltalk.beans': '@ava: "New beans this week. Tell me if they’re awful. Nobody else will."',
6
+ 'ava.smalltalk.river': '@ava: "Walk the river at dusk sometime. It’s the only quiet in town."',
7
+ // Ava's small talk by text: a pool of messages, one drawn each day.
8
+ 'ava.chat.rain': 'Rain later. The ducks know before the forecast does.',
9
+ 'ava.chat.beans': 'New beans this week. Tell me if they’re *awful*. Nobody else will.',
10
+ 'ava.chat.river': 'Walk the river at dusk sometime. It’s the only quiet in town.',
11
+ 'ava.chat.ducks': 'A duck walked into the café this morning. **Walked in.** Then out again.',
12
+ }
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Ava's arc: meeting her at the café, her calls and texts, the evening by the
3
+ * river, and the friendship quest. Her words are written where they are
4
+ * read; the lines drawn at random, her small talk, are by key in `ava.prose.ts`.
5
+ */
6
+ import { choice, decide, give, holding, jump, move, point, say, text, type Content } from '@ifloom/engine'
7
+ import { quests } from '@ifloom/plugin-quests'
8
+ import { calendar } from '@ifloom/plugin-calendar'
9
+ import { cast } from '@ifloom/plugin-cast'
10
+ import { jobs } from '@ifloom/plugin-jobs'
11
+ import { messages, type MessageDef } from '@ifloom/plugin-messages'
12
+ import { prose } from './ava.prose.ts'
13
+
14
+ /**
15
+ * Ava's small talk by text: a pool the `ava.chat` trigger draws one line from
16
+ * each day, once you've answered her first text. A line rests for three days
17
+ * after it comes, so the same one never comes twice within three days.
18
+ */
19
+ const smallTalk: MessageDef[] = ['rain', 'beans', 'river', 'ducks'].map((topic) => ({
20
+ id: `ava.chat.${topic}`,
21
+ channel: 'texts',
22
+ from: 'ava',
23
+ drawnFrom: ['ava.chat'],
24
+ when: { not: messages.since(`ava.chat.${topic}`, { lt: 3 }) },
25
+ body: [{ prose: `ava.chat.${topic}` }],
26
+ // The beans want an answer, every time she asks.
27
+ ...(topic === 'beans'
28
+ ? { replies: [{ id: 'taste', label: 'I’ll come and taste them', effects: [{ stat: 'friendship', by: 2, of: cast.character('ava') }] }] }
29
+ : {}),
30
+ }))
31
+
32
+ export const ava: Content = {
33
+ // A keepsake is one particular thing, so whoever has it has the only one. Not listed: what you hold is in `view.held`.
34
+ kinds: [{ id: 'keepsake', label: 'Keepsake', unique: true, listed: false }],
35
+ entities: [{ id: 'shell', of: 'keepsake', name: 'A river shell', description: 'Smooth and grey, from the bank by Ava’s bench.' }],
36
+ scenes: [
37
+ {
38
+ id: 'ava.hi',
39
+ title: 'Ava',
40
+ speaker: 'ava',
41
+ body: [
42
+ // A paragraph in quotes is a spoken line, so narration goes in a paragraph of its own.
43
+ // `[[ui:image|…]]` is the React UI's: her name opens her photo in the viewer.
44
+ text(`
45
+ [[ui:image|Ava|photo/ava.svg|Ava at the café counter]] looks up from the till and grins.
46
+
47
+ "You’re the one above the launderette. Welcome to the worst-kept secret in town: me."
48
+ `),
49
+ // Drawn from the variants by key, a different line each visit.
50
+ { variants: 'ava.smalltalk' },
51
+ { text: 'She has your cup out before you ask.', when: { seen: 'ava.hi', gte: 3 } },
52
+ // Things are held: once the shell is Ava's, it sits by her till.
53
+ { text: 'The river shell sits by the till, holding down the receipts.', when: { entity: 'keepsake:shell', at: cast.character('ava') } },
54
+ ],
55
+ choices: [
56
+ // Shown while you hold the shell from the river: giving it moves it to her.
57
+ {
58
+ id: 'shell',
59
+ label: 'Give her the shell from the river',
60
+ when: holding('keepsake:shell'),
61
+ effects: [move('keepsake:shell', cast.character('ava')), { stat: 'friendship', by: 5, of: cast.character('ava') }],
62
+ },
63
+ {
64
+ id: 'chat',
65
+ label: 'Chat for a minute',
66
+ once: { per: 'turn', reason: 'She has a queue.' },
67
+ effects: [{ stat: 'friendship', by: 5, of: cast.character('ava') }],
68
+ },
69
+ {
70
+ id: 'compliment',
71
+ label: 'Tell her the café is the best thing in town',
72
+ when: { stat: 'charm', gte: 3 },
73
+ effects: [{ stat: 'friendship', by: 10, of: cast.character('ava') }, { scene: null }],
74
+ },
75
+ // She points you at the job board by the till: the scene closes and the board opens over the room.
76
+ { id: 'work', label: 'Ask about weekend work', effects: [{ scene: null }, jobs.open()] },
77
+ { id: 'bye', label: 'Leave her to it', effects: [{ scene: null }] },
78
+ ],
79
+ },
80
+ {
81
+ id: 'ava.call',
82
+ title: 'Ava, on the phone',
83
+ speaker: 'ava',
84
+ body: [{ text: '"Oh, hello! I’m on the bench by the river. Come and find me some evening."' }],
85
+ choices: [
86
+ {
87
+ id: 'bye',
88
+ label: 'Say goodnight',
89
+ effects: [{ stat: 'friendship', by: 3, of: cast.character('ava') }, { scene: null }],
90
+ },
91
+ ],
92
+ },
93
+ // A flowing scene: the evening reads on as you choose, and a question comes back round until you settle.
94
+ {
95
+ id: 'ava.river',
96
+ title: 'By the river',
97
+ ui: { transition: { in: 'fade', out: 'fade', ms: 600 } },
98
+ speaker: 'ava',
99
+ body: [
100
+ { text: 'Ava is on the bench with her shoes off, feeding the ducks the crusts of the day.' },
101
+ // Her line comes a moment after the ducks: a block of its own, revealed by the React UI.
102
+ { text: '"I told you it was the only quiet in town." She shuffles up to make room.', ui: { reveal: { delay: 1500, as: 'slide-up' } } },
103
+ // Each pick but the last jumps back here, so you can do both before you sit.
104
+ point('bench'),
105
+ decide('evening', [
106
+ // A thing to keep: the shell is an entity, and picking it up gives it to you.
107
+ choice('shell', 'Pocket a smooth shell from the bank', {
108
+ when: { not: { entity: 'keepsake:shell', gte: 1 } },
109
+ effects: [give('keepsake:shell'), jump('bench')],
110
+ then: [text(`It's cold, and fits your palm exactly.`)],
111
+ }),
112
+ choice('ducks', 'Ask about the ducks', {
113
+ blocked: [{ when: { chose: 'ava.river#ducks' }, reason: 'You asked.', hide: true }],
114
+ effects: [jump('bench')],
115
+ then: [say('ava', 'They know my name. I never asked theirs.')],
116
+ }),
117
+ choice('stay', 'Sit with her until the light goes', {
118
+ effects: [{ stat: 'friendship', by: 5, of: cast.character('ava') }],
119
+ then: [text(`The water goes orange, then grey. Neither of you says much.`)],
120
+ }),
121
+ ]),
122
+ text(`You walk back along the river together, as far as the bridge.`),
123
+ ],
124
+ choices: [{ id: 'home', label: 'Say goodnight', effects: [{ scene: null }] }],
125
+ },
126
+ ],
127
+ triggers: [
128
+ // Once a day after you've answered Ava's first text, a line of her small talk from the pool.
129
+ { id: 'ava.chat', once: { per: 'turn' }, when: messages.replied('ava.text'), effects: [messages.draw('ava.chat')] },
130
+ ],
131
+ variants: {
132
+ 'ava.smalltalk': ['ava.smalltalk.rain', 'ava.smalltalk.beans', 'ava.smalltalk.river'],
133
+ },
134
+ data: {
135
+ quests: {
136
+ quests: [
137
+ {
138
+ id: 'friend',
139
+ name: 'A friend in town',
140
+ storyline: 'ava',
141
+ starts: quests.active('settle'),
142
+ stages: [
143
+ { id: 'close', hint: 'Spend time with Ava.', done: { stat: 'friendship', of: cast.character('ava'), gte: 25 } },
144
+ // A friendship takes days as well as visits: three since you met, however often you chat.
145
+ {
146
+ id: 'river',
147
+ hint: 'Find Ava by the river some evening.',
148
+ done: { all: [{ since: 'ava.hi', gte: 3 }, { seen: 'ava.river' }] },
149
+ },
150
+ ],
151
+ },
152
+ ],
153
+ },
154
+ achievements: {
155
+ achievements: [
156
+ // Hidden until it happens.
157
+ { id: 'river', name: 'Dusk by the river', description: 'Spend an evening by the river with Ava.', secret: true, when: { seen: 'ava.river' } },
158
+ ],
159
+ },
160
+ messages: {
161
+ messages: [
162
+ {
163
+ id: 'ava.text',
164
+ channel: 'texts',
165
+ from: 'ava',
166
+ when: { all: [{ seen: 'ava.hi' }, { since: 'ava.hi', gte: 1 }] },
167
+ body: [{ text: 'Good to meet you yesterday! Coffee’s on me next time 🙂' }],
168
+ replies: [
169
+ { id: 'yes', label: 'Deal!', effects: [{ stat: 'friendship', by: 5, of: cast.character('ava') }] },
170
+ { id: 'later', label: 'Maybe later in the week' },
171
+ ],
172
+ },
173
+ // A second text a moment after the first, with her typing in between: `after` waits on the engine's timers.
174
+ {
175
+ id: 'ava.text.ps',
176
+ channel: 'texts',
177
+ from: 'ava',
178
+ when: messages.arrived('ava.text'),
179
+ after: { ms: 2000 },
180
+ body: [{ text: 'The café, not the one by the bus stop. Theirs is terrible.' }],
181
+ },
182
+ ...smallTalk,
183
+ ],
184
+ },
185
+ feed: {
186
+ posts: [
187
+ {
188
+ id: 'ava.cake',
189
+ feed: 'social',
190
+ from: 'ava',
191
+ when: calendar.day({ gte: 1 }),
192
+ body: [{ text: 'Lemon drizzle today. It will not last until noon.' }],
193
+ likes: 14,
194
+ },
195
+ ],
196
+ },
197
+ },
198
+ prose,
199
+ }