create-ifloom 0.0.0-stage → 0.1.1

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 +26 -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 +26 -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 +44 -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 +33 -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 +66 -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 +30 -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,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2023",
4
+ "lib": ["ES2023", "DOM", "DOM.Iterable"],
5
+ "jsx": "react-jsx",
6
+ "module": "esnext",
7
+ "moduleResolution": "bundler",
8
+ "allowImportingTsExtensions": true,
9
+ "verbatimModuleSyntax": true,
10
+ "moduleDetection": "force",
11
+ "erasableSyntaxOnly": true,
12
+ "noEmit": true,
13
+ "strict": true,
14
+ "skipLibCheck": true,
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "types": []
19
+ },
20
+ "include": ["src", "tests"]
21
+ }
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from 'tsdown'
2
+
3
+ // The package as it's published: ES modules, their types and source maps in dist/.
4
+ // `npm run build` makes it, and `npm publish` runs that first. Two entries, the
5
+ // plugin and its React UI (the `/react` subpath), with dist/ mirroring src/.
6
+ export default defineConfig({
7
+ entry: ['src/index.ts', 'src/react/index.tsx'],
8
+ unbundle: true,
9
+ format: 'esm',
10
+ platform: 'neutral',
11
+ fixedExtension: false,
12
+ dts: true,
13
+ sourcemap: true,
14
+ })
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "ifloom dev",
8
+ "build": "ifloom build",
9
+ "check": "ifloom check",
10
+ "typecheck": "tsc --noEmit",
11
+ "playtest": "ifloom playtest --turns 5 --out playtest/run.txt"
12
+ },
13
+ "dependencies": {
14
+ "@ifloom/audio": "^0.1.1",
15
+ "@ifloom/browser": "^0.1.1",
16
+ "@ifloom/engine": "^0.1.1",
17
+ "@ifloom/react": "^0.1.1",
18
+ "react": "19.3.0",
19
+ "react-dom": "19.3.0"
20
+ },
21
+ "devDependencies": {
22
+ "@ifloom/cli": "^0.1.1",
23
+ "@tailwindcss/vite": "4.3.3",
24
+ "@types/react": "^19.3.0",
25
+ "@types/react-dom": "^19.3.0",
26
+ "@vitejs/plugin-react": "6.1.1",
27
+ "tailwindcss": "4.3.3",
28
+ "typescript": "6.0.3"
29
+ }
30
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The page: what goes in the side column, what goes in the story, and what
3
+ * floats over them. This is a copy of the React UI's own `DefaultLayout`, so
4
+ * change anything. Delete a part, move it, wrap it, or show it only in some
5
+ * rooms with `when`. Each section hides itself when the game has nothing for
6
+ * it.
7
+ *
8
+ * A plugin's own UI (`shopUi` from `@ifloom/plugin-shop/react`, say), listed
9
+ * in `plugins` in `main.ts`, goes where each `<Plugins at="…" />` is. Or draw
10
+ * a plugin's components yourself, wherever you like.
11
+ *
12
+ * On a phone the side column becomes a drawer behind a menu button.
13
+ */
14
+ import {
15
+ Clock,
16
+ Game,
17
+ GameMenu,
18
+ InputFields,
19
+ Inventory,
20
+ Notices,
21
+ Overlay,
22
+ PanelHost,
23
+ Plugins,
24
+ RoomActions,
25
+ Scene,
26
+ Section,
27
+ Sidebar,
28
+ StatList,
29
+ Story,
30
+ Title,
31
+ useWords,
32
+ } from '@ifloom/react'
33
+
34
+ export function Layout() {
35
+ // The section titles are UI words, so `ui.stats` in the game's strings renames one.
36
+ const words = useWords()
37
+ return (
38
+ <Game>
39
+ <Sidebar>
40
+ <Title />
41
+ <Clock />
42
+ <GameMenu />
43
+ {/* `collapsible` folds in place, and the player's choice is remembered. */}
44
+ <Section id="stats" title={words('stats')} collapsible open>
45
+ <StatList />
46
+ <Plugins at="stats" />
47
+ </Section>
48
+ <Section id="inventory" title={words('inventory')} collapsible>
49
+ <Inventory title={false} />
50
+ </Section>
51
+ {/* What the plugins' UIs bring to the side column: a Quests button, the People, ... */}
52
+ <Plugins at="sidebar" />
53
+ </Sidebar>
54
+ <Story>
55
+ <Scene />
56
+ <InputFields />
57
+ {/* The bottom of the story: where you are and the way out, what to do, then who's here. */}
58
+ <Plugins at="room" />
59
+ <RoomActions />
60
+ <Plugins at="story" />
61
+ </Story>
62
+ {/* A panel content opens, such as a shop's counter, in a dialog. */}
63
+ <PanelHost />
64
+ <Overlay>
65
+ <Notices />
66
+ </Overlay>
67
+ </Game>
68
+ )
69
+ }
@@ -0,0 +1,11 @@
1
+ import { mountGame } from '@ifloom/react'
2
+ import module from './game.ts'
3
+ import { Layout } from './layout.tsx'
4
+ import './styles.css'
5
+
6
+ // `layout` is the page, in `layout.tsx`. `pages` opens on a title screen
7
+ // with New game, Continue, Load and Settings. Leave it out to start straight
8
+ // in the story. `plugins` lists the UIs of the plugins in game.ts, such as
9
+ // `shopUi` from `@ifloom/plugin-shop/react`; leave one out to draw that
10
+ // plugin yourself.
11
+ mountGame(module.build(), { layout: Layout, pages: true, plugins: [] })
@@ -0,0 +1,16 @@
1
+ @import "@ifloom/react/styles.css";
2
+ @import "@ifloom/react/themes/paper.css";
3
+
4
+ /*
5
+ * Make it yours. Set any colour or token here, or style any part of the page
6
+ * by its data-part attribute, for example:
7
+ *
8
+ * :root { --font-body: Georgia, serif; --primary: oklch(0.5 0.15 30); }
9
+ * [data-part="choice"] { border-radius: 0; }
10
+ *
11
+ * See https://ifloom.dev/docs/how-to/react/theme-the-react-ui#style-parts-with-css
12
+ *
13
+ * These are Tailwind source, built with your own classes. A game without
14
+ * Tailwind imports @ifloom/react's prebuilt styles.min.css instead, and a
15
+ * preset's .min.css: see "Use the prebuilt stylesheet" on the same page.
16
+ */
@@ -0,0 +1,7 @@
1
+ import tailwindcss from '@tailwindcss/vite'
2
+ import react from '@vitejs/plugin-react'
3
+ import { ifloom } from '@ifloom/cli/vite'
4
+
5
+ // The React UI needs React's Vite plugin, and Tailwind for its stylesheet.
6
+ // `dedupe` keeps one React when @ifloom/react is linked from a checkout.
7
+ export default ifloom({ vite: { plugins: [react(), tailwindcss()], resolve: { dedupe: ['react', 'react-dom'] } } })
@@ -0,0 +1,58 @@
1
+ # {{title}}
2
+
3
+ An interactive fiction game built on IFLoom, a TypeScript engine. This file is
4
+ for coding agents working on the game.
5
+
6
+ ## Learn the engine
7
+
8
+ - The docs, in one file: https://ifloom.dev/llms-full.txt
9
+ - The docs' MCP server, to search them and fetch single pages: https://ifloom.dev/api/mcp
10
+ - Working games to copy patterns from: `examples/novel`, `examples/cafe` and
11
+ `examples/showcase` in the IFLoom repository, https://github.com/IFLoom/ifloom.
12
+
13
+ ## Where things go
14
+
15
+ - `src/game.ts` only assembles the game: its default export is `defineGame({ build })`, where
16
+ `build` returns `loadGame([...content], { id, title, plugins, rules })`.
17
+ Content doesn't go here, and neither does anything a mod could change: the
18
+ actions, locks, where the game starts (`introScene`) and its starting kv are
19
+ content too.
20
+ - `src/world/` holds what the whole game shares, one file per kind:
21
+ `stats.ts`, `things.ts`, `cast.ts` for the people, `settings.ts` for what the
22
+ player can change. Each file exports a `Content` object.
23
+ - `src/story/` holds the story, one file per area: a place, a chapter or a
24
+ character's arc. Each exports a `Content` object with that area's scenes,
25
+ choices and its slice of plugin content (that place, its vendor, its jobs).
26
+ - The words a player reads are written in place: a choice's `label`, an
27
+ entity's `name`, a block of words in a scene, `text('…')` or
28
+ `{ text: '…' }`. Only lines read by key, `{ prose: 'key' }` blocks,
29
+ `variants` and pools, go in the `prose` table. A translation is one pack
30
+ with a `words` table: https://ifloom.dev/docs/how-to/translate-your-game
31
+ - `src/rules.ts` holds the game's own code once it has any: `rules`, with its
32
+ hooks (`onTurn`, `onStat`, ...) and the conditions, effects and values content
33
+ calls as `{ 'game/name': args }`.
34
+ - A new file's content goes in the list in `src/game.ts`. Files can be renamed
35
+ and split freely, but each scene, stat, prose key or other key is declared
36
+ once: `npm run check` reports one declared twice.
37
+ - A pack is different: content from outside the code, with an `id` and a
38
+ `schema`, such as a mod. Packs go in `loadGame`'s third argument and replace
39
+ what the content declares.
40
+ - Content is plain data: scenes, choices, conditions, effects, stats and words.
41
+ Prefer data over code.
42
+ - How to organise a game: https://ifloom.dev/docs/how-to/organise-your-files
43
+
44
+ ## How the game is put together
45
+
46
+ - The engine is deterministic and has no DOM. Randomness is seeded from the save.
47
+ - Plugins (a calendar, places, a cast of characters…) are added to `plugins: [...]`
48
+ when the game is loaded, and their content goes under `data.<plugin>`.
49
+ - `src/main.ts` draws the game in the browser. The page's layout, the side
50
+ column, the story and its sections, is `src/layout.tsx` with React,
51
+ `src/Layout.vue` with Vue, `src/Layout.svelte` with Svelte and `src/layout.ts`
52
+ in plain JS.
53
+
54
+ ## After every change
55
+
56
+ - `npm run check` lists anything the game names that doesn't exist. It should print "No problems."
57
+ - `npm run playtest` plays the game with no one at the keyboard and writes what it saw.
58
+ - `npm run dev` serves the game in a browser; `npm run build` makes one HTML file.
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ dist
3
+ playtest/
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>{{title}}</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="./src/main.ts"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The game, put together from its content. This file only assembles: what the
3
+ * whole game shares is in `world/`, one file per kind (stats, things, people),
4
+ * and the story is in `story/`, one file per area (a place, a chapter or a
5
+ * character's arc). Add a new file's content to the list when you make one.
6
+ *
7
+ * The docs: https://ifloom.dev/docs/how-to/organise-your-files
8
+ */
9
+ import { loadGame } from '@ifloom/engine'
10
+ import { defineGame, probe } from '@ifloom/cli/game'
11
+ import { stats } from './world/stats.ts'
12
+ import { opening } from './story/opening.ts'
13
+
14
+ /**
15
+ * The game module. `build` makes the game, with anything the loader found
16
+ * wrong with it. The page calls it, and so do `ifloom check`, `playtest`,
17
+ * `snapshot` and `words`.
18
+ */
19
+ export default defineGame({
20
+ build: ({ unlocked }) => loadGame([stats, opening], { id: '{{name}}', title: '{{title}}' }, { packs: unlocked }),
21
+ // The states `ifloom snapshot` reads every scene in: the first screen, and after knocking, played as the player would.
22
+ probes: (game) => [probe('start', game, []), probe('knocked', game, [{ play: { type: 'choose', id: 'knock' } }])],
23
+ })
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The opening of the story: its scenes, the choices in them and their words,
3
+ * written where they are read. A block of words is `text(…)`, and a choice
4
+ * is `{ id, label, effects }`. To translate the game, a pack's `words` table
5
+ * gives these fields other words: https://ifloom.dev/docs/how-to/translate-your-game
6
+ */
7
+ import { text, type Content } from '@ifloom/engine'
8
+
9
+ export const opening: Content = {
10
+ // The story opens on this scene.
11
+ introScene: 'start',
12
+ scenes: [
13
+ {
14
+ id: 'start',
15
+ title: 'The door',
16
+ body: [text('A door you have never noticed before stands at the end of the hall.')],
17
+ choices: [
18
+ { id: 'knock', label: 'Knock', effects: [{ stat: 'courage', by: 1 }, { scene: 'inside' }] },
19
+ { id: 'wait', label: 'Wait for someone to open it', effects: [{ scene: 'inside' }] },
20
+ ],
21
+ },
22
+ {
23
+ id: 'inside',
24
+ title: 'Inside',
25
+ body: [
26
+ text('It opens onto a quiet room with a kettle just coming to the boil.'),
27
+ // The engine remembers every choice, so a later scene can ask about one.
28
+ text('Someone calls out that they will be with you in a minute.', { when: { chose: 'start#knock' } }),
29
+ ],
30
+ // An ending's way back: `newGame` starts the story over, keeping the player's settings.
31
+ choices: [{ id: 'again', label: 'Start again', command: { type: 'newGame' }, effects: [] }],
32
+ },
33
+ ],
34
+ }
@@ -0,0 +1,228 @@
1
+ body {
2
+ margin: 0;
3
+ font: 1.05rem/1.6 Georgia, serif;
4
+ }
5
+
6
+ /*
7
+ * The page: the side column and the story side by side on a wide screen,
8
+ * one above the other on a phone. The prose keeps to a readable measure.
9
+ */
10
+ .page {
11
+ display: grid;
12
+ gap: 1.5rem;
13
+ padding: 1rem;
14
+ }
15
+
16
+ @media (min-width: 48rem) {
17
+ .page {
18
+ grid-template-columns: 16rem minmax(0, 1fr);
19
+ padding: 1.5rem;
20
+ }
21
+ }
22
+
23
+ .sidebar h1 {
24
+ margin: 0;
25
+ font-size: 1.3rem;
26
+ }
27
+
28
+ .clock {
29
+ margin: 0.25rem 0 0;
30
+ color: #666;
31
+ }
32
+
33
+ /* A section that folds: a <details> with its title in the <summary>. */
34
+ .section {
35
+ margin-top: 1rem;
36
+ padding-top: 0.75rem;
37
+ border-top: 1px solid #ddd;
38
+ }
39
+
40
+ .section > summary {
41
+ font-weight: bold;
42
+ cursor: pointer;
43
+ }
44
+
45
+ /* The save slot's buttons, and what the last save or load said. */
46
+ .saves {
47
+ display: flex;
48
+ gap: 0.5rem;
49
+ margin-top: 0.5rem;
50
+ }
51
+
52
+ .said {
53
+ margin: 0.25rem 0 0;
54
+ color: #666;
55
+ }
56
+
57
+ .stats {
58
+ display: grid;
59
+ grid-template-columns: 1fr auto;
60
+ gap: 0.25rem 1rem;
61
+ margin: 0.5rem 0 0;
62
+ }
63
+
64
+ .stats dd {
65
+ margin: 0;
66
+ text-align: right;
67
+ }
68
+
69
+ .story {
70
+ display: flex;
71
+ flex-direction: column;
72
+ gap: 1rem;
73
+ min-width: 0;
74
+ }
75
+
76
+ .story h2 {
77
+ margin: 0;
78
+ }
79
+
80
+ .prose {
81
+ max-width: 70ch;
82
+ }
83
+
84
+ /* The bottom of the story: the buttons for where you are. */
85
+ .bottom {
86
+ padding-top: 1rem;
87
+ border-top: 1px solid #ddd;
88
+ }
89
+
90
+ /* A UI piece shows its words: a sign in a typewriter face, a letter or a note as a card. */
91
+ .ui[data-ui='mono'] {
92
+ font-family: ui-monospace, monospace;
93
+ }
94
+
95
+ .beat-say {
96
+ color: #4a3b8f;
97
+ }
98
+
99
+ .beat-say[data-who='player'] {
100
+ padding-left: 1.5rem;
101
+ color: #1f6f5c;
102
+ }
103
+
104
+ /* Who says a spoken line, over its words. Hide it with display: none. */
105
+ .speaker-name {
106
+ display: block;
107
+ font-size: 0.75rem;
108
+ font-weight: 600;
109
+ letter-spacing: 0.04em;
110
+ text-transform: uppercase;
111
+ opacity: 0.75;
112
+ }
113
+
114
+ .beat-chose {
115
+ padding-left: 1.5rem;
116
+ font-style: italic;
117
+ color: #666;
118
+ }
119
+
120
+ .beat-chose::before {
121
+ content: '› ';
122
+ }
123
+
124
+ .beat-image {
125
+ max-width: 100%;
126
+ }
127
+
128
+ .ui[data-ui='mail'],
129
+ .ui[data-ui='prop'] {
130
+ display: block;
131
+ padding: 1rem;
132
+ border: 2px dashed #bbb;
133
+ white-space: pre-wrap;
134
+ }
135
+
136
+ .choices,
137
+ .inputs {
138
+ display: flex;
139
+ flex-direction: column;
140
+ gap: 0.5rem;
141
+ }
142
+
143
+ .choices button,
144
+ .inputs button {
145
+ padding: 0.6rem 1rem;
146
+ font: inherit;
147
+ text-align: left;
148
+ cursor: pointer;
149
+ }
150
+
151
+ .choices button:disabled {
152
+ cursor: not-allowed;
153
+ }
154
+
155
+ .reason {
156
+ margin: -0.25rem 0 0.25rem 1rem;
157
+ font-size: 0.9rem;
158
+ color: #a33;
159
+ }
160
+
161
+ .inline-action,
162
+ .tip {
163
+ padding: 0;
164
+ border: 0;
165
+ background: none;
166
+ font: inherit;
167
+ color: #4a3b8f;
168
+ text-decoration: underline;
169
+ text-underline-offset: 0.2em;
170
+ cursor: pointer;
171
+ }
172
+
173
+ .tip {
174
+ color: inherit;
175
+ text-decoration-style: dotted;
176
+ }
177
+
178
+ .inline-action[aria-disabled='true'] {
179
+ color: #888;
180
+ cursor: not-allowed;
181
+ }
182
+
183
+ /* A tooltip's note, or a greyed-out action's reason: shown on hover, focus or a tap. */
184
+ .note {
185
+ display: none;
186
+ position: absolute;
187
+ max-width: 16rem;
188
+ margin: 1.8em 0 0 -4rem;
189
+ padding: 0.3rem 0.6rem;
190
+ border: 1px solid #ccc;
191
+ border-radius: 0.4rem;
192
+ background: #fff;
193
+ font-size: 0.9rem;
194
+ }
195
+
196
+ :is(.inline-action, .tip):is(:hover, :focus-visible, [aria-expanded='true']) + .note {
197
+ display: block;
198
+ }
199
+
200
+ .timer {
201
+ height: 0.5rem;
202
+ overflow: hidden;
203
+ border-radius: 1rem;
204
+ background: #eee;
205
+ }
206
+
207
+ .timer span {
208
+ display: block;
209
+ height: 100%;
210
+ background: #4a3b8f;
211
+ transform-origin: left;
212
+ transition: transform 100ms linear;
213
+ }
214
+
215
+ /* A panel content opened, over the page: a modal <dialog>, which the browser centres over a backdrop. */
216
+ .panel {
217
+ width: min(30rem, calc(100% - 2rem));
218
+ max-height: calc(100dvh - 2rem);
219
+ overflow-y: auto;
220
+ padding: 1rem 1.5rem;
221
+ border: 0;
222
+ border-radius: 0.5rem;
223
+ background: #fff;
224
+ }
225
+
226
+ .panel::backdrop {
227
+ background: rgb(0 0 0 / 40%);
228
+ }
@@ -0,0 +1,6 @@
1
+ /** The stats the whole game keeps. A scene in any area can read or change them. */
2
+ import type { Content } from '@ifloom/engine'
3
+
4
+ export const stats: Content = {
5
+ stats: [{ id: 'courage', label: 'Courage', start: 1, max: 5 }],
6
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "lib": ["ES2023", "DOM", "DOM.Iterable"],
5
+ "jsx": "react-jsx",
6
+ "types": ["@ifloom/cli/client"]
7
+ },
8
+ "include": ["src", "vite.config.ts"]
9
+ }
@@ -0,0 +1,5 @@
1
+ import { ifloom } from '@ifloom/cli/vite'
2
+
3
+ // No framework: the preset builds the game into one HTML file. A framework's
4
+ // Vite plugin goes in `vite.plugins`: ifloom({ vite: { plugins: [vue()] } }).
5
+ export default ifloom()
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "ifloom dev",
8
+ "build": "ifloom build",
9
+ "check": "ifloom check",
10
+ "typecheck": "svelte-check",
11
+ "playtest": "ifloom playtest --turns 5 --out playtest/run.txt"
12
+ },
13
+ "dependencies": {
14
+ "@ifloom/audio": "^0.1.1",
15
+ "@ifloom/browser": "^0.1.1",
16
+ "@ifloom/engine": "^0.1.1",
17
+ "svelte": "5.57.2"
18
+ },
19
+ "devDependencies": {
20
+ "@ifloom/cli": "^0.1.1",
21
+ "@sveltejs/vite-plugin-svelte": "7.3.1",
22
+ "svelte-check": "4.7.7",
23
+ "typescript": "6.0.3"
24
+ }
25
+ }
@@ -0,0 +1,11 @@
1
+ <script lang="ts">
2
+ import { view } from './runner.ts'
3
+ import Layout from './Layout.svelte'
4
+ import Panel from './Panel.svelte'
5
+ </script>
6
+
7
+ <!-- The page: the side column, the story and its bottom. See Layout.svelte. -->
8
+ <Layout />
9
+
10
+ <!-- A panel content opened, such as a shop's counter, over everything else. -->
11
+ {#if $view.panel}<Panel panel={$view.panel} />{/if}
@@ -0,0 +1,31 @@
1
+ <script lang="ts">
2
+ import type { SceneBeat } from '@ifloom/engine'
3
+ import Line from './Line.svelte'
4
+
5
+ // One paragraph of a scene: narration, a spoken line, a picture, a clip, a pick made earlier. A sound beat is heard, not drawn.
6
+ let { beat }: { beat: SceneBeat } = $props()
7
+ </script>
8
+
9
+ {#if beat.type === 'text'}
10
+ <p><Line text={beat.text} spans={beat.spans} /></p>
11
+ {:else if beat.type === 'say'}
12
+ <p class="beat-say" data-who={beat.who}>
13
+ {#if beat.name}<span class="speaker-name">{beat.name}</span>{/if}
14
+ <Line text={beat.text} spans={beat.spans} />
15
+ </p>
16
+ {:else if beat.type === 'chose'}
17
+ <p class="beat-chose">{beat.label}</p>
18
+ {:else if beat.type === 'image'}
19
+ <img class="beat-image" src={beat.src} alt={beat.alt ?? ''} />
20
+ {:else if beat.type === 'video'}
21
+ <video
22
+ class="beat-image"
23
+ src={beat.src}
24
+ poster={beat.poster}
25
+ autoplay={beat.autoplay}
26
+ loop={beat.loop}
27
+ muted={beat.muted}
28
+ controls={beat.controls}
29
+ playsinline
30
+ ></video>
31
+ {/if}
@@ -0,0 +1,36 @@
1
+ <script lang="ts">
2
+ import type { InputView } from '@ifloom/engine'
3
+ import { runner } from './runner.ts'
4
+
5
+ // A value the game asks for, such as the player's name. What they enter goes back as an `input` command.
6
+ let { input }: { input: InputView } = $props()
7
+ // svelte-ignore state_referenced_locally
8
+ let value = $state(input.value === null ? '' : String(input.value))
9
+
10
+ function submit(event: SubmitEvent) {
11
+ event.preventDefault()
12
+ runner.apply({ type: 'input', id: input.id, to: input.type === 'number' ? Number(value) : value })
13
+ }
14
+ </script>
15
+
16
+ {#if input.type === 'choice'}
17
+ <div class="inputs" role="group" aria-label={input.label}>
18
+ {#each input.options as option (option.value)}
19
+ <button onclick={() => runner.apply({ type: 'input', id: input.id, to: option.value })}>{option.label}</button>
20
+ {/each}
21
+ </div>
22
+ {:else}
23
+ <form onsubmit={submit}>
24
+ <label>
25
+ {input.label}
26
+ <input
27
+ bind:value
28
+ type={input.type === 'number' ? 'number' : 'text'}
29
+ maxlength={input.maxLength ?? undefined}
30
+ min={input.min ?? undefined}
31
+ max={input.max ?? undefined}
32
+ />
33
+ </label>
34
+ <button type="submit">OK</button>
35
+ </form>
36
+ {/if}