@pinkaphant/create-kolmo 0.4.2 → 0.5.2

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 (78) hide show
  1. package/README.md +56 -17
  2. package/bin/create-kolmo.mjs +20 -12
  3. package/package.json +1 -1
  4. package/templates/demolition/README.md +17 -0
  5. package/templates/demolition/index.html +29 -0
  6. package/templates/demolition/package.json +39 -0
  7. package/templates/demolition/src/App.tsx +599 -0
  8. package/templates/{lonedrive → demolition}/tsconfig.json +4 -2
  9. package/templates/{lonedrive → demolition}/vite.config.ts +3 -1
  10. package/templates/dust/README.md +9 -1
  11. package/templates/dust/index.html +15 -1
  12. package/templates/dust/package.json +10 -8
  13. package/templates/dust/src/App.tsx +106 -122
  14. package/templates/dust/tsconfig.json +4 -2
  15. package/templates/evolution/README.md +15 -0
  16. package/templates/evolution/index.html +29 -0
  17. package/templates/{lonedrive → evolution}/package.json +10 -9
  18. package/templates/evolution/src/App.tsx +619 -0
  19. package/templates/evolution/src/main.tsx +10 -0
  20. package/templates/evolution/src/styles.css +237 -0
  21. package/templates/evolution/tsconfig.json +16 -0
  22. package/templates/evolution/vite.config.ts +10 -0
  23. package/templates/longline/README.md +16 -9
  24. package/templates/longline/index.html +26 -12
  25. package/templates/longline/package.json +13 -11
  26. package/templates/longline/src/App.tsx +191 -42
  27. package/templates/longline/src/highway.ts +222 -0
  28. package/templates/longline/src/main.tsx +7 -6
  29. package/templates/longline/tsconfig.json +14 -16
  30. package/templates/longline/vite.config.ts +5 -23
  31. package/templates/road/README.md +8 -4
  32. package/templates/road/index.html +15 -1
  33. package/templates/road/package.json +7 -7
  34. package/templates/road/src/App.tsx +21 -6
  35. package/templates/road/tsconfig.json +1 -0
  36. package/templates/tugline/README.md +16 -0
  37. package/templates/tugline/index.html +31 -0
  38. package/templates/tugline/package.json +41 -0
  39. package/templates/tugline/src/App.tsx +48 -0
  40. package/templates/{longline → tugline}/src/components/Boat.tsx +1 -2
  41. package/templates/{longline → tugline}/src/components/Crates.tsx +2 -2
  42. package/templates/tugline/src/components/Hud.tsx +281 -0
  43. package/templates/{longline → tugline}/src/components/Longline.tsx +2 -2
  44. package/templates/{longline → tugline}/src/components/Ocean.tsx +14 -3
  45. package/templates/{longline → tugline}/src/components/Radar.tsx +15 -14
  46. package/templates/{longline → tugline}/src/components/Referee.tsx +6 -4
  47. package/templates/{longline → tugline}/src/components/Scene.tsx +10 -9
  48. package/templates/{longline → tugline}/src/components/Sky.tsx +14 -8
  49. package/templates/{longline → tugline}/src/game/store.test.ts +2 -2
  50. package/templates/{longline → tugline}/src/game/store.ts +38 -19
  51. package/templates/tugline/src/main.tsx +13 -0
  52. package/templates/tugline/src/styles.css +495 -0
  53. package/templates/tugline/tsconfig.json +18 -0
  54. package/templates/tugline/vite.config.ts +16 -0
  55. package/templates/lonedrive/README.md +0 -11
  56. package/templates/lonedrive/index.html +0 -15
  57. package/templates/lonedrive/src/App.tsx +0 -149
  58. package/templates/longline/src/components/Hud.tsx +0 -197
  59. package/templates/longline/src/styles.css +0 -367
  60. /package/templates/{lonedrive → demolition}/src/main.tsx +0 -0
  61. /package/templates/{longline → tugline}/src/components/CameraRig.tsx +0 -0
  62. /package/templates/{longline → tugline}/src/components/ocean-material.ts +0 -0
  63. /package/templates/{longline → tugline}/src/components/round-context.ts +0 -0
  64. /package/templates/{longline → tugline}/src/game/boat-control.ts +0 -0
  65. /package/templates/{longline → tugline}/src/game/constants.ts +0 -0
  66. /package/templates/{longline → tugline}/src/game/input.test.ts +0 -0
  67. /package/templates/{longline → tugline}/src/game/input.ts +0 -0
  68. /package/templates/{longline → tugline}/src/game/logic.test.ts +0 -0
  69. /package/templates/{longline → tugline}/src/game/logic.ts +0 -0
  70. /package/templates/{longline → tugline}/src/game/physics.test.ts +0 -0
  71. /package/templates/{longline → tugline}/src/game/radar.ts +0 -0
  72. /package/templates/{longline → tugline}/src/game/registry.ts +0 -0
  73. /package/templates/{longline → tugline}/src/game/sea.ts +0 -0
  74. /package/templates/{longline → tugline}/src/game/session.ts +0 -0
  75. /package/templates/{longline → tugline}/src/game/simulation.test.ts +0 -0
  76. /package/templates/{longline → tugline}/src/game/simulation.ts +0 -0
  77. /package/templates/{longline → tugline}/src/game/test-world.ts +0 -0
  78. /package/templates/{longline → tugline}/src/sfx.ts +0 -0
@@ -1,197 +0,0 @@
1
- import { useEffect, useRef, useState, useSyncExternalStore } from "react";
2
- import { SEA_STATES, SEA_STATE_IDS, type SeaStateId } from "../game/constants.js";
3
- import type { Helm } from "../game/input.js";
4
- import type { Game, Snapshot } from "../game/store.js";
5
- import { isMuted, playEnd, playHaul, setMuted, unlockAudio } from "../sfx.js";
6
- import { Radar } from "./Radar.js";
7
-
8
- export function formatClock(seconds: number): string {
9
- const s = Math.max(0, Math.ceil(seconds));
10
- return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
11
- }
12
-
13
- function useSnapshot(game: Game): Snapshot {
14
- return useSyncExternalStore(game.subscribe, game.getSnapshot);
15
- }
16
-
17
- /** Sounds for the round's events: a chime on each haul, a tone when time runs out. */
18
- function useSounds(snap: Snapshot): void {
19
- const haul = useRef(snap.lastHaul?.id ?? 0);
20
- const phase = useRef(snap.phase);
21
- useEffect(() => {
22
- const id = snap.lastHaul?.id ?? 0;
23
- if (snap.lastHaul !== null && id !== haul.current) playHaul(snap.lastHaul.combo);
24
- haul.current = id;
25
- if (phase.current === "playing" && snap.phase === "over") playEnd();
26
- phase.current = snap.phase;
27
- }, [snap]);
28
- }
29
-
30
- function TouchControls({ helm }: { helm: Helm }) {
31
- const axes = useRef({ throttle: 0, steer: 0 });
32
- const set = (axis: "throttle" | "steer", value: number) => ({
33
- onPointerDown: (e: React.PointerEvent) => {
34
- e.currentTarget.setPointerCapture(e.pointerId);
35
- axes.current[axis] = value;
36
- helm.setTouch(axes.current.throttle, axes.current.steer);
37
- },
38
- onPointerUp: () => {
39
- axes.current[axis] = 0;
40
- helm.setTouch(axes.current.throttle, axes.current.steer);
41
- },
42
- onPointerCancel: () => {
43
- axes.current[axis] = 0;
44
- helm.setTouch(axes.current.throttle, axes.current.steer);
45
- },
46
- });
47
- return (
48
- <div className="touch">
49
- <div className="touch-side">
50
- <button aria-label="Steer to port" {...set("steer", -1)}>
51
- ◀
52
- </button>
53
- <button aria-label="Steer to starboard" {...set("steer", 1)}>
54
- ▶
55
- </button>
56
- </div>
57
- <div className="touch-side">
58
- <button aria-label="Astern" {...set("throttle", -1)}>
59
- ▼
60
- </button>
61
- <button aria-label="Ahead" {...set("throttle", 1)}>
62
- ▲
63
- </button>
64
- </div>
65
- </div>
66
- );
67
- }
68
-
69
- function SeaPicker({ game, snap }: { game: Game; snap: Snapshot }) {
70
- return (
71
- <div className="seas" role="radiogroup" aria-label="Sea state">
72
- {SEA_STATE_IDS.map((id: SeaStateId) => (
73
- <button
74
- key={id}
75
- role="radio"
76
- aria-checked={snap.sea === id}
77
- className={snap.sea === id ? "sea selected" : "sea"}
78
- onClick={() => game.selectSea(id)}
79
- >
80
- <strong>{SEA_STATES[id].label}</strong>
81
- <span>Current {SEA_STATES[id].current.toFixed(1)} m/s</span>
82
- </button>
83
- ))}
84
- </div>
85
- );
86
- }
87
-
88
- function Title({ game, snap }: { game: Game; snap: Snapshot }) {
89
- const start = (): void => {
90
- unlockAudio();
91
- game.start(snap.sea);
92
- };
93
- useEffect(() => {
94
- const onKey = (e: KeyboardEvent): void => {
95
- if (e.code === "Enter" || e.code === "Space") {
96
- e.preventDefault();
97
- start();
98
- }
99
- };
100
- window.addEventListener("keydown", onKey);
101
- return () => window.removeEventListener("keydown", onKey);
102
- });
103
- return (
104
- <div className="panel title">
105
- <h1>Longline</h1>
106
- <p className="tag">Tow the line through the crates before time runs out.</p>
107
- <SeaPicker game={game} snap={snap} />
108
- <p className="best">{snap.best > 0 ? `Best at ${SEA_STATES[snap.sea].label.toLowerCase()} sea: ${snap.best}` : "No score at this sea yet"}</p>
109
- <button className="go" onClick={start}>
110
- Start
111
- </button>
112
- <p className="keys">
113
- <kbd>W</kbd> <kbd>S</kbd> throttle · <kbd>A</kbd> <kbd>D</kbd> steer · arrow keys work too · <kbd>Enter</kbd> starts
114
- </p>
115
- <p className="credit">Floated by the water module of @pinkaphant/kolmo</p>
116
- </div>
117
- );
118
- }
119
-
120
- function Result({ game, snap }: { game: Game; snap: Snapshot }) {
121
- const again = (): void => {
122
- unlockAudio();
123
- game.start(snap.sea);
124
- };
125
- useEffect(() => {
126
- const onKey = (e: KeyboardEvent): void => {
127
- if (e.code === "Enter") again();
128
- };
129
- window.addEventListener("keydown", onKey);
130
- return () => window.removeEventListener("keydown", onKey);
131
- });
132
- return (
133
- <div className="panel result">
134
- <h2>Time's up</h2>
135
- <div className="big">{snap.score}</div>
136
- {snap.newBest ? <p className="newbest">New best!</p> : <p className="best">Best: {snap.best}</p>}
137
- <p className="stats">
138
- {snap.hauled} hauled · {snap.lost} lost to the current
139
- </p>
140
- <div className="row">
141
- <button className="go" onClick={again}>
142
- Sail again
143
- </button>
144
- <button onClick={() => game.toMenu()}>Change sea</button>
145
- </div>
146
- </div>
147
- );
148
- }
149
-
150
- /** The heads-up display: score, clock, combo, radar and, on the title and result screens, the panels. */
151
- export function Hud({ game, helm }: { game: Game; helm: Helm }) {
152
- const snap = useSnapshot(game);
153
- useSounds(snap);
154
- const [muted, setMutedState] = useState(isMuted());
155
- const [coarse] = useState(() => typeof window !== "undefined" && window.matchMedia?.("(pointer: coarse)").matches === true);
156
- const playing = snap.phase === "playing";
157
- return (
158
- <div className="hud">
159
- {playing ? (
160
- <>
161
- <div className="top">
162
- <div className="score">
163
- <span className="label">Score</span>
164
- <span className="value">{snap.score}</span>
165
- {snap.combo > 1 ? <span className="combo">×{snap.combo}</span> : null}
166
- </div>
167
- <div className={snap.secondsLeft <= 10 ? "clock low" : "clock"}>{formatClock(snap.secondsLeft)}</div>
168
- <div className="tally">
169
- <span>{snap.hauled} hauled</span>
170
- <span>{snap.lost} lost</span>
171
- </div>
172
- </div>
173
- {snap.lastHaul !== null ? (
174
- <div className="toast" key={snap.lastHaul.id}>
175
- +{snap.lastHaul.points}
176
- {snap.lastHaul.combo > 1 ? ` ×${snap.lastHaul.combo}` : ""}
177
- </div>
178
- ) : null}
179
- {coarse ? <TouchControls helm={helm} /> : null}
180
- </>
181
- ) : null}
182
- <Radar />
183
- <button
184
- className="mute"
185
- aria-label={muted ? "Unmute" : "Mute"}
186
- onClick={() => {
187
- setMuted(!muted);
188
- setMutedState(!muted);
189
- }}
190
- >
191
- {muted ? "🔇" : "🔊"}
192
- </button>
193
- {snap.phase === "menu" ? <Title game={game} snap={snap} /> : null}
194
- {snap.phase === "over" ? <Result game={game} snap={snap} /> : null}
195
- </div>
196
- );
197
- }
@@ -1,367 +0,0 @@
1
- :root {
2
- --ink: #06243a;
3
- --sea: #0a3a5c;
4
- --foam: #f2f8fb;
5
- --sun: #ffd23d;
6
- --pink: #ff3d6e;
7
- color-scheme: dark;
8
- }
9
-
10
- * {
11
- box-sizing: border-box;
12
- }
13
-
14
- html,
15
- body,
16
- #root {
17
- height: 100%;
18
- margin: 0;
19
- overflow: hidden;
20
- background: #b9dbea;
21
- font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
22
- -webkit-tap-highlight-color: transparent;
23
- overscroll-behavior: none;
24
- }
25
-
26
- .loading {
27
- margin: 0;
28
- padding: 2rem;
29
- color: var(--ink);
30
- font-weight: 700;
31
- }
32
-
33
- .stage {
34
- position: fixed;
35
- inset: 0;
36
- touch-action: none;
37
- }
38
-
39
- .hud {
40
- position: fixed;
41
- inset: 0;
42
- pointer-events: none;
43
- color: var(--foam);
44
- text-shadow: 0 1px 3px rgba(6, 36, 58, 0.7);
45
- user-select: none;
46
- -webkit-user-select: none;
47
- }
48
-
49
- .hud button {
50
- pointer-events: auto;
51
- font: inherit;
52
- cursor: pointer;
53
- }
54
-
55
- .top {
56
- position: absolute;
57
- top: max(12px, env(safe-area-inset-top));
58
- left: 16px;
59
- right: 16px;
60
- display: flex;
61
- justify-content: space-between;
62
- align-items: flex-start;
63
- gap: 12px;
64
- }
65
-
66
- .score,
67
- .tally {
68
- min-width: 7rem;
69
- display: flex;
70
- flex-direction: column;
71
- gap: 2px;
72
- font-weight: 700;
73
- }
74
-
75
- .tally {
76
- align-items: flex-end;
77
- font-size: 0.95rem;
78
- padding-right: 3.2rem;
79
- }
80
-
81
- .score .label {
82
- font-size: 0.75rem;
83
- letter-spacing: 0.12em;
84
- text-transform: uppercase;
85
- opacity: 0.85;
86
- }
87
-
88
- .score .value {
89
- font-size: 2.2rem;
90
- line-height: 1;
91
- font-variant-numeric: tabular-nums;
92
- }
93
-
94
- .score .combo {
95
- align-self: flex-start;
96
- margin-top: 4px;
97
- padding: 1px 8px;
98
- border-radius: 999px;
99
- background: var(--sun);
100
- color: var(--ink);
101
- text-shadow: none;
102
- font-weight: 800;
103
- }
104
-
105
- .clock {
106
- font-size: 2.6rem;
107
- font-weight: 800;
108
- font-variant-numeric: tabular-nums;
109
- line-height: 1;
110
- }
111
-
112
- .clock.low {
113
- color: var(--pink);
114
- animation: pulse 1s ease-in-out infinite;
115
- }
116
-
117
- @keyframes pulse {
118
- 50% {
119
- transform: scale(1.12);
120
- }
121
- }
122
-
123
- .toast {
124
- position: absolute;
125
- top: 26%;
126
- left: 50%;
127
- translate: -50% 0;
128
- font-size: 2.4rem;
129
- font-weight: 800;
130
- color: var(--sun);
131
- animation: toast 1.1s ease-out forwards;
132
- }
133
-
134
- @keyframes toast {
135
- from {
136
- opacity: 1;
137
- transform: translateY(0) scale(0.8);
138
- }
139
- 20% {
140
- transform: translateY(-6px) scale(1.15);
141
- }
142
- to {
143
- opacity: 0;
144
- transform: translateY(-46px) scale(1);
145
- }
146
- }
147
-
148
- .radar {
149
- position: absolute;
150
- right: max(14px, env(safe-area-inset-right));
151
- bottom: max(14px, env(safe-area-inset-bottom));
152
- }
153
-
154
- .warning {
155
- position: absolute;
156
- left: 50%;
157
- bottom: 18%;
158
- translate: -50% 0;
159
- padding: 6px 16px;
160
- border-radius: 999px;
161
- background: var(--pink);
162
- font-weight: 800;
163
- opacity: 0;
164
- transition: opacity 0.2s;
165
- }
166
-
167
- .mute {
168
- position: absolute;
169
- top: max(12px, env(safe-area-inset-top));
170
- right: 14px;
171
- width: 38px;
172
- height: 38px;
173
- border: 0;
174
- border-radius: 50%;
175
- background: rgba(6, 36, 58, 0.45);
176
- font-size: 1.1rem;
177
- line-height: 1;
178
- color: var(--foam);
179
- }
180
-
181
- .touch {
182
- position: absolute;
183
- left: 0;
184
- right: 0;
185
- bottom: max(14px, env(safe-area-inset-bottom));
186
- display: flex;
187
- justify-content: space-between;
188
- padding: 0 14px;
189
- pointer-events: none;
190
- }
191
-
192
- .touch-side {
193
- display: flex;
194
- gap: 14px;
195
- }
196
-
197
- .touch button {
198
- width: 76px;
199
- height: 76px;
200
- border: 2px solid rgba(255, 255, 255, 0.6);
201
- border-radius: 50%;
202
- background: rgba(6, 36, 58, 0.4);
203
- color: var(--foam);
204
- font-size: 1.6rem;
205
- touch-action: none;
206
- }
207
-
208
- .touch button:active {
209
- background: rgba(255, 210, 61, 0.55);
210
- }
211
-
212
- .panel {
213
- position: absolute;
214
- left: 50%;
215
- top: 50%;
216
- translate: -50% -50%;
217
- width: min(92vw, 30rem);
218
- padding: 1.6rem 1.6rem 1.3rem;
219
- border-radius: 1.2rem;
220
- background: rgba(6, 36, 58, 0.62);
221
- backdrop-filter: blur(10px);
222
- -webkit-backdrop-filter: blur(10px);
223
- text-align: center;
224
- pointer-events: auto;
225
- box-shadow: 0 18px 50px rgba(6, 36, 58, 0.35);
226
- }
227
-
228
- .panel h1 {
229
- margin: 0;
230
- font-size: clamp(2.4rem, 9vw, 3.6rem);
231
- letter-spacing: 0.04em;
232
- text-transform: uppercase;
233
- }
234
-
235
- .panel h2 {
236
- margin: 0;
237
- font-size: 1.6rem;
238
- }
239
-
240
- .tag {
241
- margin: 0.4rem 0 1.1rem;
242
- font-size: 1.05rem;
243
- }
244
-
245
- .seas {
246
- display: grid;
247
- grid-template-columns: repeat(3, 1fr);
248
- gap: 0.6rem;
249
- }
250
-
251
- .sea {
252
- display: flex;
253
- flex-direction: column;
254
- gap: 2px;
255
- padding: 0.6rem 0.4rem;
256
- border: 2px solid rgba(255, 255, 255, 0.35);
257
- border-radius: 0.8rem;
258
- background: transparent;
259
- color: var(--foam);
260
- }
261
-
262
- .sea span {
263
- font-size: 0.72rem;
264
- opacity: 0.85;
265
- }
266
-
267
- .sea.selected {
268
- border-color: var(--sun);
269
- background: rgba(255, 210, 61, 0.2);
270
- }
271
-
272
- .best {
273
- margin: 0.9rem 0 0.2rem;
274
- font-size: 0.95rem;
275
- opacity: 0.9;
276
- }
277
-
278
- .newbest {
279
- margin: 0.4rem 0;
280
- font-size: 1.2rem;
281
- font-weight: 800;
282
- color: var(--sun);
283
- }
284
-
285
- .go,
286
- .row button {
287
- padding: 0.7rem 1.8rem;
288
- border: 0;
289
- border-radius: 999px;
290
- background: var(--sun);
291
- color: var(--ink);
292
- font-size: 1.15rem;
293
- font-weight: 800;
294
- text-shadow: none;
295
- }
296
-
297
- .row {
298
- display: flex;
299
- justify-content: center;
300
- gap: 0.8rem;
301
- margin-top: 1rem;
302
- }
303
-
304
- .row button:not(.go) {
305
- background: rgba(255, 255, 255, 0.85);
306
- }
307
-
308
- .go {
309
- margin-top: 0.8rem;
310
- }
311
-
312
- .big {
313
- font-size: 4rem;
314
- font-weight: 800;
315
- line-height: 1.1;
316
- font-variant-numeric: tabular-nums;
317
- }
318
-
319
- .stats {
320
- margin: 0.4rem 0 0;
321
- }
322
-
323
- .keys {
324
- margin: 1.1rem 0 0;
325
- font-size: 0.85rem;
326
- opacity: 0.9;
327
- }
328
-
329
- .credit {
330
- margin: 0.5rem 0 0;
331
- font-size: 0.72rem;
332
- opacity: 0.65;
333
- }
334
-
335
- kbd {
336
- padding: 1px 6px;
337
- border-radius: 5px;
338
- background: rgba(255, 255, 255, 0.85);
339
- color: var(--ink);
340
- font: inherit;
341
- font-weight: 800;
342
- text-shadow: none;
343
- }
344
-
345
- .fatal {
346
- position: fixed;
347
- inset: 0;
348
- display: grid;
349
- place-content: center;
350
- gap: 0.5rem;
351
- padding: 2rem;
352
- text-align: center;
353
- color: var(--ink);
354
- }
355
-
356
- @media (max-width: 560px) {
357
- .score .value {
358
- font-size: 1.8rem;
359
- }
360
- .clock {
361
- font-size: 2rem;
362
- }
363
- .tally {
364
- padding-right: 2.8rem;
365
- font-size: 0.8rem;
366
- }
367
- }
File without changes
File without changes