create-threenative 0.2.18 → 0.2.20

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 (183) hide show
  1. package/agent-docs/references/capability-reference.md +212 -4
  2. package/agent-docs/references/kit-racing.md +4 -2
  3. package/agent-docs/references/performance-basics.md +2 -1
  4. package/agent-docs/references/terrain-authoring.md +21 -7
  5. package/agent-files/.agents/skills/prd-creator/SKILL.md +24 -0
  6. package/dist/index.js +255 -236
  7. package/dist/quality.d.ts +5 -1
  8. package/dist/quality.js +75 -6
  9. package/dist/terrain-kit.js +1 -1
  10. package/dist/threenative.js +6 -4
  11. package/dist/web-engine-post-effects.js +6 -0
  12. package/dist/web-engine-runtime.js +211 -36
  13. package/package.json +6 -6
  14. package/template-assets/assets/floor-fern-0.glb +0 -0
  15. package/template-assets/assets/floor-litter-0.glb +0 -0
  16. package/template-assets/assets/floor-log-0.glb +0 -0
  17. package/template-assets/assets/floor-log-1.glb +0 -0
  18. package/template-assets/assets/floor-stump-0.glb +0 -0
  19. package/template-assets/assets/floor-twig-0.glb +0 -0
  20. package/template-assets/quality/eslint.config.js +1 -1
  21. package/templates/action-rpg/package.json +7 -7
  22. package/templates/action-rpg/src/loot/drops.ts +3 -7
  23. package/templates/action-rpg/src/render/camera.ts +2 -2
  24. package/templates/action-rpg/src/render/clouds.ts +3 -1
  25. package/templates/action-rpg/src/render/materials.ts +3 -2
  26. package/templates/action-rpg/src/render/touch-controls.ts +7 -6
  27. package/templates/action-rpg/src/scenes/Play.ts +1 -15
  28. package/templates/adventure/AGENTS.md +3 -3
  29. package/templates/adventure/CLAUDE.md +3 -3
  30. package/templates/adventure/native-playtests/survives.playtest.json +12 -0
  31. package/templates/adventure/native-playtests/woodland-floor.playtest.json +61 -0
  32. package/templates/adventure/package.json +7 -7
  33. package/templates/adventure/playtests/grass.playtest.json +61 -0
  34. package/templates/adventure/playtests/performance.playtest.json +1 -1
  35. package/templates/adventure/playtests/survives.playtest.json +2 -2
  36. package/templates/adventure/playtests/woodland-floor.playtest.json +61 -0
  37. package/templates/adventure/src/entities/LockOn.ts +42 -4
  38. package/templates/adventure/src/entities/Warden.ts +4 -1
  39. package/templates/adventure/src/level/Vale.ts +241 -16
  40. package/templates/adventure/src/render/camera.ts +2 -2
  41. package/templates/adventure/src/render/foliage.ts +64 -20
  42. package/templates/adventure/src/render/grass.ts +325 -0
  43. package/templates/adventure/src/render/materials.ts +3 -2
  44. package/templates/adventure/src/render/palette.ts +3 -0
  45. package/templates/adventure/src/render/touch-controls.ts +4 -1
  46. package/templates/adventure/src/scenes/Play.ts +96 -1
  47. package/templates/collectathon/package.json +7 -7
  48. package/templates/collectathon/src/level/Course.ts +2 -7
  49. package/templates/collectathon/src/level/terrain.ts +2 -1
  50. package/templates/collectathon/src/render/camera.ts +2 -2
  51. package/templates/collectathon/src/render/ground.ts +4 -4
  52. package/templates/collectathon/src/render/hero.ts +1 -1
  53. package/templates/collectathon/src/render/materials.ts +0 -1
  54. package/templates/collectathon/src/render/sky.ts +4 -3
  55. package/templates/kart/package.json +6 -6
  56. package/templates/kart/src/entities/Kart.ts +2 -1
  57. package/templates/kart/src/render/course.ts +2 -1
  58. package/templates/kart/src/track/Course.ts +3 -1
  59. package/templates/minimal/package.json +6 -6
  60. package/templates/minimal/src/render/camera.ts +2 -2
  61. package/templates/minimal/src/render/clouds.ts +3 -1
  62. package/templates/minimal/src/render/materials.ts +3 -2
  63. package/templates/minimal/src/render/touch-controls.ts +7 -6
  64. package/templates/platformer/package.json +7 -7
  65. package/templates/platformer/playtests/collect.playtest.json +4 -1
  66. package/templates/platformer/src/level/Stage.ts +2 -6
  67. package/templates/platformer/src/scenes/Play.ts +2 -1
  68. package/templates/puzzle/package.json +7 -7
  69. package/templates/puzzle/src/entities/Warden.ts +3 -3
  70. package/templates/puzzle/src/render/camera.ts +2 -2
  71. package/templates/puzzle/src/render/touch-controls.ts +7 -6
  72. package/templates/racing/AGENTS.md +2 -2
  73. package/templates/racing/CLAUDE.md +2 -2
  74. package/templates/racing/CREDITS.md +29 -0
  75. package/templates/racing/assets/engine-loop.wav +0 -0
  76. package/templates/racing/assets/grass/Grass004_color.jpg +0 -0
  77. package/templates/racing/assets/grass/Grass004_normal.jpg +0 -0
  78. package/templates/racing/assets/grass/Grass004_roughness.jpg +0 -0
  79. package/templates/racing/assets/nitro-burst.wav +0 -0
  80. package/templates/racing/assets/tyre-squeal.wav +0 -0
  81. package/templates/racing/package.json +7 -7
  82. package/templates/racing/playtests/drift-natural.playtest.json +68 -0
  83. package/templates/racing/playtests/drift.playtest.json +100 -0
  84. package/templates/racing/playtests/hud.playtest.json +117 -0
  85. package/templates/racing/playtests/launch-pose.playtest.json +34 -0
  86. package/templates/racing/playtests/nitro.playtest.json +158 -0
  87. package/templates/racing/playtests/outcome.playtest.json +4 -4
  88. package/templates/racing/playtests/performance.playtest.json +1 -1
  89. package/templates/racing/playtests/steady-camera.playtest.json +88 -0
  90. package/templates/racing/src/audio/engine.ts +138 -0
  91. package/templates/racing/src/entities/CarBody.ts +83 -10
  92. package/templates/racing/src/entities/Drift.ts +243 -0
  93. package/templates/racing/src/entities/LineDriver.ts +2 -2
  94. package/templates/racing/src/entities/Nitro.ts +72 -0
  95. package/templates/racing/src/entities/RacingCar.ts +86 -21
  96. package/templates/racing/src/entities/Rival.ts +35 -21
  97. package/templates/racing/src/game.ts +6 -0
  98. package/templates/racing/src/gauges.ts +74 -0
  99. package/templates/racing/src/render/camera.ts +29 -4
  100. package/templates/racing/src/render/clouds.ts +3 -1
  101. package/templates/racing/src/render/effects.ts +244 -0
  102. package/templates/racing/src/render/materials.ts +43 -8
  103. package/templates/racing/src/render/shapes.ts +37 -0
  104. package/templates/racing/src/render/skids.ts +84 -0
  105. package/templates/racing/src/render/touch-controls.ts +10 -10
  106. package/templates/racing/src/scenes/Race.ts +277 -25
  107. package/templates/racing/src/state.ts +35 -0
  108. package/templates/racing/src/style.css +3 -0
  109. package/templates/racing/src/track/Track.ts +132 -58
  110. package/templates/racing/src/track/TrackSector.ts +19 -1
  111. package/templates/racing/src/track/circuit.ts +21 -15
  112. package/templates/racing/src/ui/GameUi.tsx +0 -2
  113. package/templates/racing/src/ui/Hud.tsx +417 -50
  114. package/templates/racing/threenative.config.ts +15 -0
  115. package/templates/racing/tools/make-racing-audio.mjs +388 -0
  116. package/templates/rain/package.json +6 -6
  117. package/templates/rain/src/render/noise-volume.ts +2 -1
  118. package/templates/rain/src/state.ts +3 -1
  119. package/templates/rain/src/ui/GameUi.tsx +1 -1
  120. package/templates/rain/src/ui/automation.ts +10 -8
  121. package/templates/rain/src/ui/tempest.ts +3 -4
  122. package/templates/rts/package.json +6 -6
  123. package/templates/rts/src/sim/terrain.ts +1 -0
  124. package/templates/rts/src/sim/types.ts +1 -0
  125. package/templates/runner/package.json +7 -7
  126. package/templates/runner/src/render/clouds.ts +3 -1
  127. package/templates/runner/src/render/materials.ts +3 -2
  128. package/templates/runner/src/render/touch-controls.ts +7 -6
  129. package/templates/runner/src/scenes/Run.ts +4 -9
  130. package/templates/sailing/package.json +7 -7
  131. package/templates/sailing/src/render/touch-controls.ts +7 -6
  132. package/templates/shooter/package.json +7 -7
  133. package/templates/shooter/src/render/clouds.ts +3 -1
  134. package/templates/snow/package.json +7 -7
  135. package/templates/snow/src/entities/Explorer.ts +6 -12
  136. package/templates/snow/src/render/bootPrint.ts +3 -1
  137. package/templates/snow/src/render/camera.ts +3 -2
  138. package/templates/snow/src/render/scenery.ts +3 -3
  139. package/templates/snow/src/render/touch-controls.ts +7 -6
  140. package/templates/snow/src/render/weather.ts +3 -5
  141. package/templates/snow/src/terrain.ts +2 -1
  142. package/templates/starter/native-playtests/render-chain.playtest.json +9 -9
  143. package/templates/starter/package.json +7 -7
  144. package/templates/starter/src/entities/Player.ts +10 -2
  145. package/templates/starter/src/render/camera.ts +2 -2
  146. package/templates/starter/src/render/clouds.ts +3 -1
  147. package/templates/starter/src/render/materials.ts +3 -2
  148. package/templates/starter/src/render/touch-controls.ts +7 -6
  149. package/templates/starter/src/scenes/Play.ts +1 -14
  150. package/templates/tower-defense/package.json +7 -7
  151. package/templates/tower-defense/src/render/shapes.ts +1 -2
  152. package/templates/tower-defense/src/scenes/Battle.ts +3 -8
  153. package/template-assets/terrain/alpine/assets.json +0 -12
  154. package/template-assets/terrain/alpine/bake.mjs +0 -6
  155. package/template-assets/terrain/alpine/credits.json +0 -164
  156. package/template-assets/terrain/alpine/heightmap.r16 +0 -0
  157. package/template-assets/terrain/alpine/recipe.json +0 -119
  158. package/template-assets/terrain/alpine/surface.json +0 -53
  159. package/template-assets/terrain/coastal/assets.json +0 -11
  160. package/template-assets/terrain/coastal/bake.mjs +0 -6
  161. package/template-assets/terrain/coastal/credits.json +0 -117
  162. package/template-assets/terrain/coastal/heightmap.r16 +0 -0
  163. package/template-assets/terrain/coastal/recipe.json +0 -113
  164. package/template-assets/terrain/coastal/surface.json +0 -41
  165. package/template-assets/terrain/desert/assets.json +0 -12
  166. package/template-assets/terrain/desert/bake.mjs +0 -6
  167. package/template-assets/terrain/desert/credits.json +0 -164
  168. package/template-assets/terrain/desert/heightmap.r16 +0 -0
  169. package/template-assets/terrain/desert/recipe.json +0 -108
  170. package/template-assets/terrain/desert/surface.json +0 -54
  171. package/template-assets/terrain/forest/assets.json +0 -65
  172. package/template-assets/terrain/forest/bake.mjs +0 -8
  173. package/template-assets/terrain/forest/credits.json +0 -225
  174. package/template-assets/terrain/forest/heightmap.r16 +0 -0
  175. package/template-assets/terrain/forest/recipe.json +0 -350
  176. package/template-assets/terrain/forest/surface.json +0 -79
  177. package/template-assets/terrain/tundra/assets.json +0 -12
  178. package/template-assets/terrain/tundra/bake.mjs +0 -6
  179. package/template-assets/terrain/tundra/credits.json +0 -164
  180. package/template-assets/terrain/tundra/heightmap.r16 +0 -0
  181. package/template-assets/terrain/tundra/recipe.json +0 -277
  182. package/template-assets/terrain/tundra/surface.json +0 -54
  183. package/templates/racing/src/ui/Menu.tsx +0 -7
@@ -1,15 +1,381 @@
1
1
  import { useUiState } from "@threenative/ui";
2
2
  import type { GameState } from "../state.js";
3
+ import { CIRCUIT } from "../track/circuit.js";
3
4
 
4
- function clock(seconds: number): string {
5
- return `${String(Math.floor(seconds / 60)).padStart(2, "0")}:${String(Math.floor(seconds % 60)).padStart(2, "0")}.${String(Math.floor((seconds % 1) * 10))}`;
5
+ /**
6
+ * The race HUD, authored from the owner's reference frame: position and the live field down the
7
+ * top left, the lap/timer/best panel top right, the circuit minimap bottom left, and the tach with
8
+ * speed, gear and the segmented nitro bar bottom right.
9
+ *
10
+ * Everything is a reading of `GameState`: the standings come from the scene's own ranking (the same
11
+ * order the race is decided on), the minimap from the one circuit every other system reads, and the
12
+ * dial from the gauges the engine sound is pitched from. No second source of truth.
13
+ */
14
+
15
+ const RIVAL_NAMES = ["Carter", "Vega", "Ruiz", "Monroe", "Blake"] as const;
16
+
17
+ function racerName(id: string): string {
18
+ if (id === "player") return "Player";
19
+ if (id === "rival") return RIVAL_NAMES[0];
20
+ const index = Number.parseInt(id.slice("rival-".length), 10) - 1;
21
+ return RIVAL_NAMES[index] ?? id;
22
+ }
23
+
24
+ /** The race clock and the lap readouts, three decimals as the reference's timer. */
25
+ function raceClock(seconds: number): string {
26
+ const minutes = Math.floor(seconds / 60);
27
+ const whole = Math.floor(seconds % 60);
28
+ const millis = Math.floor((seconds % 1) * 1000);
29
+ return `${String(minutes).padStart(2, "0")}:${String(whole).padStart(2, "0")}.${String(millis).padStart(3, "0")}`;
30
+ }
31
+
32
+ function lapClock(seconds: number): string {
33
+ return seconds > 0 ? raceClock(seconds) : "--:--.---";
34
+ }
35
+
36
+ /** A field row's gap to the player: + ahead, − behind, in the reference's m:ss.t form. */
37
+ function gapClock(seconds: number): string {
38
+ const sign = seconds < 0 ? "-" : "+";
39
+ const abs = Math.abs(seconds);
40
+ return `${sign}${Math.floor(abs / 60)}:${String(Math.floor(abs % 60)).padStart(2, "0")}.${Math.floor((abs % 1) * 10)}`;
41
+ }
42
+
43
+ function StandingBoard({ state }: { state: GameState }) {
44
+ const player = state.rankings.find((row) => row.id === "player");
45
+ const playerProgress = player?.routeProgress ?? state.trackProgress;
46
+ const referenceSpeed = Math.max(state.speed, 1);
47
+ return (
48
+ <ol className="mt-2 w-[196px] text-[13px] leading-[19px]">
49
+ {state.rankings.map((row) => {
50
+ const isPlayer = row.id === "player";
51
+ const gap = (row.routeProgress - playerProgress) / referenceSpeed;
52
+ return (
53
+ <li
54
+ key={row.id}
55
+ className={`flex items-center gap-2 px-2 py-[1px] normal-case ${
56
+ isPlayer
57
+ ? "border-l-2 border-cyan bg-cyan/15 font-bold text-cyan"
58
+ : "border-l-2 border-transparent bg-black/45 text-white/90"
59
+ }`}
60
+ >
61
+ <span className="w-4 text-right tabular-nums text-white/55">{row.place}</span>
62
+ <span className="flex-1">{racerName(row.id)}</span>
63
+ <span
64
+ className={`tabular-nums ${isPlayer ? "text-cyan" : gap > 0 ? "text-white/80" : "text-white/55"}`}
65
+ >
66
+ {isPlayer ? "—" : gapClock(gap)}
67
+ </span>
68
+ </li>
69
+ );
70
+ })}
71
+ </ol>
72
+ );
73
+ }
74
+
75
+ /* The minimap is the circuit itself, fitted to the dial once: one polyline for the route, the
76
+ player and the field projected onto the same geometry the car is ranked on. */
77
+ const MINIMAP_SIZE = 200;
78
+ const MINIMAP_ORIGIN = MINIMAP_SIZE / 2;
79
+ const MINIMAP_RADIUS = 92;
80
+ const MINIMAP = (() => {
81
+ const sample = CIRCUIT.createSample();
82
+ let minX = Number.POSITIVE_INFINITY;
83
+ let maxX = Number.NEGATIVE_INFINITY;
84
+ let minZ = Number.POSITIVE_INFINITY;
85
+ let maxZ = Number.NEGATIVE_INFINITY;
86
+ const points: Array<[number, number]> = [];
87
+ const steps = 120;
88
+ for (let index = 0; index < steps; index += 1) {
89
+ CIRCUIT.at((index / steps) * CIRCUIT.totalLength, sample);
90
+ const { x, z } = sample.point;
91
+ points.push([x, z]);
92
+ minX = Math.min(minX, x);
93
+ maxX = Math.max(maxX, x);
94
+ minZ = Math.min(minZ, z);
95
+ maxZ = Math.max(maxZ, z);
96
+ }
97
+ const centreX = (minX + maxX) / 2;
98
+ const centreZ = (minZ + maxZ) / 2;
99
+ const scale = Math.min(
100
+ (MINIMAP_RADIUS * 2) / (maxX - minX),
101
+ (MINIMAP_RADIUS * 2) / (maxZ - minZ),
102
+ );
103
+ const path = points
104
+ .map(([x, z], index) => {
105
+ const px = MINIMAP_ORIGIN + (x - centreX) * scale;
106
+ const pz = MINIMAP_ORIGIN + (z - centreZ) * scale;
107
+ return `${index === 0 ? "M" : "L"}${px.toFixed(1)} ${pz.toFixed(1)}`;
108
+ })
109
+ .join(" ");
110
+ return { centreX, centreZ, path: `${path} Z`, scale };
111
+ })();
112
+ const minimapSample = CIRCUIT.createSample();
113
+
114
+ function mapAt(progress: number): { x: number; y: number; heading: number } {
115
+ CIRCUIT.at(progress, minimapSample);
116
+ return {
117
+ x: MINIMAP_ORIGIN + (minimapSample.point.x - MINIMAP.centreX) * MINIMAP.scale,
118
+ y: MINIMAP_ORIGIN + (minimapSample.point.z - MINIMAP.centreZ) * MINIMAP.scale,
119
+ heading: (Math.atan2(minimapSample.tangent.x, -minimapSample.tangent.z) * 180) / Math.PI,
120
+ };
121
+ }
122
+
123
+ function Minimap({ state }: { state: GameState }) {
124
+ const player = state.rankings.find((row) => row.id === "player");
125
+ const playerAt = mapAt(player?.routeProgress ?? state.trackProgress);
126
+ return (
127
+ <svg
128
+ aria-label="circuit map"
129
+ viewBox="0 0 200 200"
130
+ className="h-[168px] w-[168px] drop-shadow-[0_2px_10px_rgb(0_0_0/0.65)]"
131
+ role="img"
132
+ >
133
+ <circle
134
+ cx="100"
135
+ cy="100"
136
+ r="96"
137
+ fill="rgb(3 9 14 / 0.78)"
138
+ stroke="rgb(56 215 231 / 0.45)"
139
+ strokeWidth="1.5"
140
+ />
141
+ <path
142
+ d={MINIMAP.path}
143
+ fill="none"
144
+ stroke="#f4c524"
145
+ strokeWidth="3.4"
146
+ strokeLinecap="round"
147
+ strokeLinejoin="round"
148
+ />
149
+ {state.rankings
150
+ .filter((row) => row.id !== "player")
151
+ .map((row) => {
152
+ const at = mapAt(row.routeProgress);
153
+ return (
154
+ <circle
155
+ key={row.id}
156
+ cx={at.x}
157
+ cy={at.y}
158
+ r="3.2"
159
+ fill="#f6e7b0"
160
+ stroke="#0a1117"
161
+ strokeWidth="1"
162
+ />
163
+ );
164
+ })}
165
+ <g
166
+ transform={`translate(${playerAt.x.toFixed(1)} ${playerAt.y.toFixed(1)}) rotate(${playerAt.heading.toFixed(1)})`}
167
+ >
168
+ <path
169
+ d="M0 -7.5 L5.2 6.2 L0 3.2 L-5.2 6.2 Z"
170
+ fill="#38d7e7"
171
+ stroke="#04222a"
172
+ strokeWidth="1"
173
+ />
174
+ </g>
175
+ <text
176
+ x="100"
177
+ y="17"
178
+ textAnchor="middle"
179
+ fill="rgb(255 255 255 / 0.92)"
180
+ fontSize="12"
181
+ fontWeight="700"
182
+ >
183
+ N
184
+ </text>
185
+ </svg>
186
+ );
187
+ }
188
+
189
+ function LapPanel({ state }: { state: GameState }) {
190
+ const lap = Math.min(state.totalLaps, state.completedLaps + 1);
191
+ return (
192
+ <div className="min-w-[196px] bg-black/45 px-4 py-3 text-right">
193
+ <div className="flex items-baseline justify-end gap-2">
194
+ <span className="text-[12px] font-bold tracking-[0.22em] text-white/80">lap</span>
195
+ <span id="lap" className="text-[34px] font-black leading-none text-white">
196
+ {lap}
197
+ </span>
198
+ <span className="text-[17px] font-bold text-white/55">/ {state.totalLaps}</span>
199
+ </div>
200
+ <div id="time" className="mt-1 text-[30px] font-black leading-none tabular-nums text-white">
201
+ {raceClock(state.elapsed)}
202
+ </div>
203
+ <div className="mt-2 grid grid-cols-[auto_1fr] gap-x-4 gap-y-[1px] border-t border-cyan/30 pt-2 text-[13px] leading-[17px]">
204
+ <span className="font-bold tracking-[0.16em] text-cyan">best</span>
205
+ <span className="tabular-nums text-white/85">{lapClock(state.bestLap)}</span>
206
+ <span className="font-bold tracking-[0.16em] text-white">lap</span>
207
+ <span className="tabular-nums text-white/85">{lapClock(state.lastLap)}</span>
208
+ </div>
209
+ </div>
210
+ );
211
+ }
212
+
213
+ /* The dial: 0..9 around 270°, a red 7–9 band, and the needle from the gauges' needle. */
214
+ const DIAL_START = 135;
215
+ const DIAL_SWEEP = 270;
216
+ const DIAL_VALUES = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] as const;
217
+
218
+ function dialAngle(value: number): number {
219
+ return DIAL_START + (Math.min(9, Math.max(0, value)) / 9) * DIAL_SWEEP;
220
+ }
221
+
222
+ function polar(angle: number, radius: number): [number, number] {
223
+ const radians = (angle * Math.PI) / 180;
224
+ return [100 + Math.cos(radians) * radius, 100 + Math.sin(radians) * radius];
225
+ }
226
+
227
+ function dialArc(from: number, to: number, radius: number): string {
228
+ const [startX, startY] = polar(dialAngle(from), radius);
229
+ const [endX, endY] = polar(dialAngle(to), radius);
230
+ const large = dialAngle(to) - dialAngle(from) > 180 ? 1 : 0;
231
+ return `M ${startX.toFixed(2)} ${startY.toFixed(2)} A ${radius} ${radius} 0 ${large} 1 ${endX.toFixed(2)} ${endY.toFixed(2)}`;
232
+ }
233
+
234
+ function Tach({ state }: { state: GameState }) {
235
+ const needle = dialAngle(state.rpm * 9);
236
+ const [needleX, needleY] = polar(needle, 66);
237
+ const redline = state.rpm >= 7 / 9;
238
+ return (
239
+ <div className="relative h-[204px] w-[204px]">
240
+ <svg
241
+ aria-hidden="true"
242
+ viewBox="0 0 200 200"
243
+ className="absolute inset-0 drop-shadow-[0_2px_12px_rgb(0_0_0/0.7)]"
244
+ >
245
+ <circle
246
+ cx="100"
247
+ cy="100"
248
+ r="96"
249
+ fill="rgb(3 9 14 / 0.72)"
250
+ stroke="rgb(255 255 255 / 0.14)"
251
+ strokeWidth="1.5"
252
+ />
253
+ <path
254
+ d={dialArc(0, 9, 88)}
255
+ fill="none"
256
+ stroke="#38d7e7"
257
+ strokeWidth="3.2"
258
+ strokeLinecap="round"
259
+ />
260
+ <path
261
+ d={dialArc(7, 9, 88)}
262
+ fill="none"
263
+ stroke="#ff4d4d"
264
+ strokeWidth="4.4"
265
+ strokeLinecap="round"
266
+ />
267
+ {DIAL_VALUES.map((value) => {
268
+ const angle = dialAngle(value);
269
+ const [outerX, outerY] = polar(angle, 82);
270
+ const [innerX, innerY] = polar(angle, 74);
271
+ const [labelX, labelY] = polar(angle, 64);
272
+ return (
273
+ <g key={value}>
274
+ <line
275
+ x1={outerX}
276
+ y1={outerY}
277
+ x2={innerX}
278
+ y2={innerY}
279
+ stroke={value >= 7 ? "#ff4d4d" : "rgb(255 255 255 / 0.7)"}
280
+ strokeWidth={value >= 7 ? 2 : 1.4}
281
+ />
282
+ <text
283
+ x={labelX}
284
+ y={labelY + 3.5}
285
+ textAnchor="middle"
286
+ fill={value >= 7 ? "#ff6a6a" : "rgb(255 255 255 / 0.8)"}
287
+ fontSize="11"
288
+ fontWeight="700"
289
+ >
290
+ {value}
291
+ </text>
292
+ </g>
293
+ );
294
+ })}
295
+ <line
296
+ x1="100"
297
+ y1="100"
298
+ x2={needleX}
299
+ y2={needleY}
300
+ stroke={redline ? "#ff5252" : "#f4f7f8"}
301
+ strokeWidth="3.4"
302
+ strokeLinecap="round"
303
+ />
304
+ <circle
305
+ cx="100"
306
+ cy="100"
307
+ r="5"
308
+ fill="#0a1117"
309
+ stroke="rgb(255 255 255 / 0.8)"
310
+ strokeWidth="1.4"
311
+ />
312
+ </svg>
313
+ <div className="absolute inset-0 flex flex-col items-center justify-center pt-3">
314
+ <div id="speed" className="text-[52px] font-black leading-none tabular-nums text-white">
315
+ {Math.round(state.speed * 3.6)}
316
+ </div>
317
+ <div className="text-[10px] font-bold tracking-[0.2em] text-white/55">km/h</div>
318
+ <div className="mt-2 min-w-[42px] border border-white/35 px-2 py-[1px] text-center">
319
+ <span id="gear" className="text-[24px] font-black leading-none text-white">
320
+ {state.gear}
321
+ </span>
322
+ </div>
323
+ </div>
324
+ </div>
325
+ );
326
+ }
327
+
328
+ const NITRO_SEGMENTS = 12;
329
+
330
+ function Nitro({ state }: { state: GameState }) {
331
+ const active = state.nitroActive || state.boostActive;
332
+ const filled = Math.round(Math.min(1, Math.max(0, state.nitro)) * NITRO_SEGMENTS);
333
+ const label = state.nitroActive ? "BURNING" : state.boostActive ? "ACTIVE" : "READY";
334
+ return (
335
+ <div className="flex w-[224px] flex-col gap-1.5">
336
+ <div className="flex items-center justify-between">
337
+ <div className="flex items-center gap-2">
338
+ <svg viewBox="0 0 12 20" className="h-[18px] w-[11px]" aria-hidden="true">
339
+ <path
340
+ d="M4 1h4v4l2 3v10a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V8l2-3V1Z"
341
+ fill="none"
342
+ stroke="#38d7e7"
343
+ strokeWidth="1.4"
344
+ />
345
+ <path d="M2 12h8" stroke="#38d7e7" strokeWidth="1.4" />
346
+ </svg>
347
+ <span className="text-[12px] font-bold tracking-[0.22em] text-cyan">nitro</span>
348
+ </div>
349
+ <span
350
+ id="boost"
351
+ className={`text-[9px] font-bold tracking-[0.2em] ${active ? "text-cyan" : "text-white/45"}`}
352
+ >
353
+ {label}
354
+ </span>
355
+ </div>
356
+ <div className="flex h-[10px] gap-[3px]">
357
+ {Array.from({ length: NITRO_SEGMENTS }, (_, index) => index + 1).map((segment) => (
358
+ <span
359
+ key={segment}
360
+ className={`h-full flex-1 -skew-x-12 ${
361
+ segment <= filled ? (active ? "bg-cyan" : "bg-cyan/80") : "bg-white/12"
362
+ }`}
363
+ />
364
+ ))}
365
+ </div>
366
+ </div>
367
+ );
368
+ }
369
+
370
+ function driftPopup(state: GameState | undefined): number | undefined {
371
+ if (state === undefined || state.driftPopup <= 0) return undefined;
372
+ return state.driftLast;
6
373
  }
7
374
 
8
375
  export function Hud() {
9
376
  const state = useUiState<GameState>();
10
- // Nothing to draw until the game publishes its first snapshot, a few milliseconds in.
11
- // Rendering zeroes instead would put wrong numbers on screen and then correct them.
12
377
  if (state === undefined) return null;
378
+ const drift = driftPopup(state);
13
379
  const statusClass =
14
380
  state.raceStatus === "WON"
15
381
  ? "text-win"
@@ -17,59 +383,60 @@ export function Hud() {
17
383
  ? "text-danger"
18
384
  : "text-accent";
19
385
  return (
20
- <div className="pointer-events-none absolute inset-0 p-6 text-[11px] uppercase tracking-[0.16em] text-text">
21
- <div className="flex items-start justify-between">
22
- <div className="-m-3 bg-panel p-3">
23
- <div className="text-[10px] text-muted">circuit / northern loop</div>
24
- <div className="mt-2 flex items-baseline gap-5 text-[18px] text-white">
25
- <span>
26
- lap <b id="lap">{Math.min(state.totalLaps, state.completedLaps + 1)}</b>/
27
- <b>{state.totalLaps}</b>
28
- </span>
29
- <span className={statusClass} id="race-status">
30
- {state.raceStatus}
31
- </span>
32
- </div>
386
+ <div className="pointer-events-none absolute inset-0 select-none overflow-hidden font-racing uppercase italic">
387
+ <div className="absolute left-5 top-4">
388
+ <div className="text-[10px] font-bold tracking-[0.3em] text-white/45">northern loop</div>
389
+ <div id="position" className="mt-1 flex items-baseline text-accent">
390
+ <span className="text-[58px] font-black leading-none">{state.place}</span>
391
+ <span className="ml-1 text-[26px] font-bold leading-none text-white/55">
392
+ /{state.racers}
393
+ </span>
33
394
  </div>
34
- <div className="-m-3 bg-panel p-3 text-right">
35
- <div className="text-[10px] text-muted">position</div>
36
- <div className="mt-2 text-[22px] text-white" id="position">
37
- P{state.place}
38
- </div>
395
+ <div
396
+ className={`mt-1 text-[11px] font-bold tracking-[0.28em] ${statusClass}`}
397
+ id="race-status"
398
+ >
399
+ {state.raceStatus}
39
400
  </div>
401
+ <StandingBoard state={state} />
40
402
  </div>
41
- <div className="absolute bottom-6 left-6 -m-3 flex items-end gap-8 bg-panel p-3">
42
- <div>
43
- <div className="text-[10px] text-muted">speed</div>
44
- <div className="mt-1 text-[26px] leading-none text-white">
45
- <span id="speed">{Math.round(state.speed * 3.6)}</span>
46
- <span className="text-[11px] text-muted"> km/h</span>
47
- </div>
48
- </div>
49
- <div>
50
- <div className="text-[10px] text-muted">time</div>
51
- <div className="mt-1 text-[18px] leading-none text-white" id="time">
52
- {clock(state.elapsed)}
53
- </div>
54
- </div>
55
- <div className={state.boostActive ? "text-accent" : "text-muted"}>
56
- <div className="text-[10px]">boost</div>
57
- <div className="mt-1 text-[18px] leading-none" id="boost">
58
- {state.boostActive ? "ACTIVE" : "READY"}
59
- </div>
60
- </div>
403
+ <div className="absolute right-5 top-4">
404
+ <LapPanel state={state} />
61
405
  </div>
62
- {state.raceStatus !== "RACING" && (
406
+ <div className="absolute bottom-5 left-5">
407
+ <Minimap state={state} />
408
+ </div>
409
+ <div className="absolute bottom-5 right-5 flex items-end gap-4">
410
+ <Nitro state={state} />
411
+ <Tach state={state} />
412
+ </div>
413
+ {drift !== undefined && state.raceStatus === "RACING" && (
63
414
  <div
64
- className={`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 border px-8 py-5 text-center ${state.raceStatus === "WON" ? "border-win/70 bg-panel" : "border-danger/70 bg-panel"}`}
415
+ className="absolute left-1/2 top-6 -translate-x-1/2 border-l-2 border-cyan bg-black/55 px-5 py-1.5 text-center"
416
+ id="drift-popup"
65
417
  >
66
- <div className={`text-[28px] tracking-[0.28em] ${statusClass}`} id="outcome">
67
- {/* Every lap done behind the rival is a loss, but not a "did not finish": name the place. */}
68
- {state.raceStatus === "DNF" && state.completedLaps >= state.totalLaps
69
- ? `P${state.place}`
70
- : state.raceStatus}
418
+ <div className="text-[10px] font-bold tracking-[0.3em] text-cyan">drift</div>
419
+ <div className="text-[26px] font-black leading-none text-accent">
420
+ +{Math.round(drift)}
421
+ </div>
422
+ </div>
423
+ )}
424
+ {state.raceStatus !== "RACING" && (
425
+ <div className="absolute inset-0 grid place-items-center">
426
+ <div
427
+ className={`border bg-black/70 px-10 py-6 text-center ${
428
+ state.raceStatus === "WON" ? "border-win/60" : "border-danger/60"
429
+ }`}
430
+ >
431
+ <div className={`text-[42px] font-black tracking-[0.14em] ${statusClass}`} id="outcome">
432
+ {state.raceStatus === "DNF" && state.completedLaps >= state.totalLaps
433
+ ? `P${state.place}`
434
+ : state.raceStatus}
435
+ </div>
436
+ <div className="mt-2 text-[11px] font-bold tracking-[0.26em] text-white/60">
437
+ press r to restart
438
+ </div>
71
439
  </div>
72
- <div className="mt-2 text-[10px] text-muted">press R to restart</div>
73
440
  </div>
74
441
  )}
75
442
  </div>
@@ -46,6 +46,21 @@ const config: IThreeNativeConfig = {
46
46
  // Switch to "native" for a UI drawn as part of the rendered frame, with no web view and no
47
47
  // extra process — and own the appearance difference that comes with it.
48
48
  ui: { renderer: "web" },
49
+ assets: {
50
+ audio: {
51
+ // The engine bed and the tyre squeal are loops this kit pitches and opens live, so the two
52
+ // claims that matter are their joins: declaring `loop` makes the audio pass measure the seam
53
+ // and fail the build on a click. `crossFadeMs: 0` because the bake already makes the join
54
+ // exact — every frequency in the bed is a whole number of cycles per loop — and a 250 ms
55
+ // cross-fade over a clean seam would smear a quarter of a second of the engine into itself
56
+ // on every lap. The nitro burst is a one-shot and is declared not to loop.
57
+ overrides: [
58
+ { glob: "engine-loop.wav", loop: { crossFadeMs: 0 } },
59
+ { glob: "tyre-squeal.wav", loop: { crossFadeMs: 0 } },
60
+ { glob: "nitro-burst.wav", loop: false },
61
+ ],
62
+ },
63
+ },
49
64
  // One asset tree, one compiler, one representation per artifact. Uncomment, then cook:
50
65
  // threenative build --target android # cooks defaults.android; --profile <name> beats it
51
66
  // buildProfiles: {