@rydr/game-sdk 8.14.0 → 8.16.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 (63) hide show
  1. package/dist/protocol/identity.d.ts +39 -0
  2. package/dist/protocol/identity.d.ts.map +1 -1
  3. package/dist/protocol/version.d.ts +1 -1
  4. package/dist/protocol/version.js +1 -1
  5. package/dist/protocol/worlds.d.ts +19 -0
  6. package/dist/protocol/worlds.d.ts.map +1 -1
  7. package/dist/protocol/worlds.js.map +1 -1
  8. package/dist/three/README.md +132 -4
  9. package/dist/three/controller/index.d.ts +2 -0
  10. package/dist/three/controller/index.d.ts.map +1 -1
  11. package/dist/three/controller/index.js +2 -0
  12. package/dist/three/controller/index.js.map +1 -1
  13. package/dist/three/controller/joycon-designs.d.ts +15 -1
  14. package/dist/three/controller/joycon-designs.d.ts.map +1 -1
  15. package/dist/three/controller/joycon-designs.js +301 -17
  16. package/dist/three/controller/joycon-designs.js.map +1 -1
  17. package/dist/three/controller/joycon-object.d.ts +216 -0
  18. package/dist/three/controller/joycon-object.d.ts.map +1 -0
  19. package/dist/three/controller/joycon-object.js +578 -0
  20. package/dist/three/controller/joycon-object.js.map +1 -0
  21. package/dist/three/controller/joycon-spec.d.ts +116 -4
  22. package/dist/three/controller/joycon-spec.d.ts.map +1 -1
  23. package/dist/three/controller/joycon-spec.js +128 -22
  24. package/dist/three/controller/joycon-spec.js.map +1 -1
  25. package/dist/three/controller/press-pulse.d.ts +89 -0
  26. package/dist/three/controller/press-pulse.d.ts.map +1 -0
  27. package/dist/three/controller/press-pulse.js +309 -0
  28. package/dist/three/controller/press-pulse.js.map +1 -0
  29. package/dist/three/controller/three-pad-renderer.d.ts +11 -22
  30. package/dist/three/controller/three-pad-renderer.d.ts.map +1 -1
  31. package/dist/three/controller/three-pad-renderer.js +49 -247
  32. package/dist/three/controller/three-pad-renderer.js.map +1 -1
  33. package/dist/three/rider/three-rider-rig.d.ts +12 -0
  34. package/dist/three/rider/three-rider-rig.d.ts.map +1 -1
  35. package/dist/three/rider/three-rider-rig.js +101 -6
  36. package/dist/three/rider/three-rider-rig.js.map +1 -1
  37. package/dist/ui/README.md +133 -7
  38. package/dist/ui/controller/controller-pad.d.ts +105 -2
  39. package/dist/ui/controller/controller-pad.d.ts.map +1 -1
  40. package/dist/ui/controller/controller-pad.js +347 -16
  41. package/dist/ui/controller/controller-pad.js.map +1 -1
  42. package/dist/ui/controller/renderer.d.ts +13 -0
  43. package/dist/ui/controller/renderer.d.ts.map +1 -1
  44. package/dist/ui/controller/renderer.js.map +1 -1
  45. package/dist/ui/controller/styles.js +50 -1
  46. package/dist/ui/controller/styles.js.map +1 -1
  47. package/dist/ui/hud-placement.d.ts +81 -0
  48. package/dist/ui/hud-placement.d.ts.map +1 -0
  49. package/dist/ui/hud-placement.js +74 -0
  50. package/dist/ui/hud-placement.js.map +1 -0
  51. package/dist/ui/index.d.ts +1 -0
  52. package/dist/ui/index.d.ts.map +1 -1
  53. package/dist/ui/index.js +1 -0
  54. package/dist/ui/index.js.map +1 -1
  55. package/dist/ui/rider-rig.d.ts +108 -10
  56. package/dist/ui/rider-rig.d.ts.map +1 -1
  57. package/dist/ui/rider-rig.js +299 -48
  58. package/dist/ui/rider-rig.js.map +1 -1
  59. package/dist/world-runtime.d.ts +11 -1
  60. package/dist/world-runtime.d.ts.map +1 -1
  61. package/dist/world-runtime.js +20 -3
  62. package/dist/world-runtime.js.map +1 -1
  63. package/package.json +4 -2
@@ -0,0 +1,216 @@
1
+ /**
2
+ * THE JOY-CON AS AN OBJECT — the pad's model *and everything that makes it react*, with no camera,
3
+ * no canvas and no renderer attached (PLAT-1582).
4
+ *
5
+ * ```ts
6
+ * import { createJoyconObject } from "@rydr/game-sdk/three";
7
+ *
8
+ * const pad = createJoyconObject({ view: "triggers" });
9
+ * pad.addLights(scene); // the art direction brings its own rig
10
+ * pad.group.position.set(2, 1.4, -3);
11
+ * scene.add(pad.group);
12
+ *
13
+ * pad.driver.setPartState("rt", "hint"); // "press this"
14
+ *
15
+ * // in your own loop:
16
+ * pad.step(performance.now());
17
+ * ```
18
+ *
19
+ * ## Why this exists
20
+ *
21
+ * `JOYCON_DESIGNS[i].build()` has always handed back the geometry, and that was never enough: a raw
22
+ * `THREE.Group` is a MUTE pad. Everything that makes it say something — a key lighting, sinking,
23
+ * pulsing, a stick leaning, a letter re-inking so it stays readable on a lit face, the roll that brings
24
+ * a trigger into view — lived inside `createThreePadRenderer`'s closure, welded to a canvas the game
25
+ * doesn't want. So a game placing the pad in its OWN scene (on a table, on a wall, floating beside the
26
+ * rider) got a prop it could not drive.
27
+ *
28
+ * This module is that logic, lifted out and given a door. `createThreePadRenderer` is now a thin shell
29
+ * around it: canvas, camera, framing, the render loop and `partRect`. Both paths therefore animate
30
+ * through the SAME code, which is the point — a press could not look one way in the HUD and another way
31
+ * in the world.
32
+ *
33
+ * ## What you own when you use it directly
34
+ *
35
+ * The loop. This object has no `requestAnimationFrame` of its own, because a game already has one and a
36
+ * second one would render behind it. Call {@link JoyconObject.step} once per frame with the same
37
+ * timestamp you pass everything else; it returns `true` while anything is still moving, which is all a
38
+ * dirty-guarded renderer needs. Miss the call and the pad still *paints* (colour is immediate) but
39
+ * nothing *animates* — keys teleport and pulses never fade.
40
+ *
41
+ * You also own the yaw. The object's `group` is yours to rotate, scale and place; the tilt and the
42
+ * trigger roll live on an inner pivot so they can't fight you for `rotation.x`.
43
+ */
44
+ import * as THREE from "three";
45
+ import type { PadDriver, PadPartState } from "../../ui/controller/pad-svg.js";
46
+ import type { PadDriverOptions } from "../../ui/controller/pad-svg.js";
47
+ import type { PadLayout, PadPart } from "../../ui/controller/types.js";
48
+ import { type JoyconBuild, type JoyconDesignId } from "./joycon-designs.js";
49
+ import { type PadViewName } from "./joycon-spec.js";
50
+ import { type PressHoldStyle, type PressPulseStyle } from "./press-pulse.js";
51
+ /**
52
+ * The four things a part can say, as colours. Same grammar and same hues as the flat pad's CSS.
53
+ *
54
+ * `off` is the FALLBACK only. A resting key is painted the colour its design built it in — see
55
+ * `restColor` — because a single hard-coded rest colour repainted every design into the same blue-grey
56
+ * pad the moment a driver touched it: the art direction survived in the showcase, which builds a model
57
+ * and never paints it, and was thrown away everywhere a view actually used one. That is also why a
58
+ * black pad with white keys came out with blue-grey keys.
59
+ */
60
+ export declare const PAD_STATE_COLOR: Readonly<Record<PadPartState, number>>;
61
+ /**
62
+ * How the pad is posed and how it reacts — everything both the in-scene object and the HUD renderer
63
+ * need, and nothing about a canvas.
64
+ *
65
+ * `createThreePadRenderer` extends this, so an option documented here means exactly the same thing
66
+ * there. That is deliberate: the two paths draw the same pad and must be tuned with the same words.
67
+ */
68
+ export interface JoyconObjectOptions extends PadDriverOptions {
69
+ /** Which art direction to draw. Default `"toy"` — the one built for reading at a distance. */
70
+ design?: JoyconDesignId;
71
+ /**
72
+ * A named orientation — `"front"`, `"angled"` (the default) or `"triggers"`. See {@link PAD_VIEWS}.
73
+ *
74
+ * This is the plain-words version of {@link tilt} + {@link yaw}: "show me the triggers" rather than
75
+ * "pitch 0.95 rad". Either of those, passed explicitly, still wins over the preset — so a view can be
76
+ * a starting point that you then nudge.
77
+ */
78
+ view?: PadViewName;
79
+ /** Forward tilt in radians. Default: the tilt of {@link view}, else {@link VIEW.pitch}. */
80
+ tilt?: number;
81
+ /** Turn about the vertical axis, radians. Default: the yaw of {@link view}, else 0 — head-on. */
82
+ yaw?: number;
83
+ /** Accent colour for pressed parts, as anything `THREE.Color` accepts. */
84
+ accent?: string;
85
+ /**
86
+ * Colour of the `hint` state — "press this". Default: the kit's near-white.
87
+ *
88
+ * ⚠️ Setting it to {@link accent} collapses *do this* and *you are doing it* into one picture — see
89
+ * `PadRendererOptions.hintColor`, where that trade-off is spelt out.
90
+ */
91
+ hintColor?: string;
92
+ /**
93
+ * Extra forward tilt applied while a TRIGGER is being shown, radians. Default 0.38 (~22°).
94
+ *
95
+ * This is the reason the pad is modelled in 3D at all. `ZL`/`ZR` sit on the back of the crown: from
96
+ * the reading angle they are edge-on, and a view teaching one would be pointing at a sliver. When a
97
+ * trigger lights, the pad rolls forward so the top face — and the key — come into view, then rolls
98
+ * back when it is released. The flat pad had to draw the triggers floating above the shell instead,
99
+ * which is a picture of a controller that does not exist.
100
+ *
101
+ * Set to 0 to pin the pad still — which is what you want under `view: "triggers"`, where the crown is
102
+ * already facing the viewer and a roll on top of it would tip the pad past flat.
103
+ */
104
+ triggerTilt?: number;
105
+ /** Milliseconds the roll takes, each way. Default 420. */
106
+ triggerTiltMs?: number;
107
+ /**
108
+ * The white circle that marks the INSTANT a key goes down. Default `"wave"`; `"none"` turns it off.
109
+ *
110
+ * Without it a press says nothing an eye can catch: the key's travel is along the viewing axis, so
111
+ * the tilt projects it to almost nothing, and what is left is a colour change — a state, not an
112
+ * event. See `press-pulse.ts` for the three animations and what each is good for.
113
+ */
114
+ pressPulse?: PressPulseStyle;
115
+ /**
116
+ * What a key does while it is HELD, once its press has been marked. Default `"echo"`.
117
+ *
118
+ * A separate axis from {@link pressPulse}, because "a key went down" and "a key is still down" are
119
+ * two different things to say. `"echo"` repeats the pulse quietly, `"collar"` parks a breathing ring
120
+ * at the key's edge, `"none"` says nothing.
121
+ *
122
+ * Note the cost: anything but `"none"` means the pad is animating for as long as a key is held, so it
123
+ * cannot go fully idle during a hold. That is a frame of work while the rider is holding a button,
124
+ * not while they are doing nothing — but it is the one case where the dirty-guard yields.
125
+ */
126
+ pressHold?: PressHoldStyle;
127
+ /**
128
+ * How deep a pressed key sinks, as a fraction of the shell's width. Default 0.07.
129
+ *
130
+ * The travel runs along the viewing axis, so the tilt eats most of it on screen — raise this if the
131
+ * pad is being read from far away or nearly head-on, where there is even less of it left.
132
+ */
133
+ pressTravel?: number;
134
+ /** Lifetime of one press pulse, ms. Default 500. */
135
+ pressPulseMs?: number;
136
+ /** Multiplier on the pulse's radius. Default 1.4 — the size judged on the showcase. */
137
+ pressPulseScale?: number;
138
+ /**
139
+ * The layout whose lettering is printed on the keys. Default: the Joy-Con layout.
140
+ *
141
+ * Only the glyphs are read from it — the geometry is always the modelled Joy-Con. Pass the layout a
142
+ * view is already using so the printed letters match the rest of the screen.
143
+ */
144
+ layout?: PadLayout;
145
+ }
146
+ /**
147
+ * A Joy-Con you can put in a scene and drive.
148
+ *
149
+ * Everything a renderer needs is here, which is exactly why `createThreePadRenderer` is now short: what
150
+ * it adds on top is a canvas, a camera, a framing rule and a projection — not behaviour.
151
+ */
152
+ export interface JoyconObject {
153
+ /**
154
+ * Put this in your scene. Yours to move, scale and YAW.
155
+ *
156
+ * The tilt and the trigger roll are applied to an inner pivot ({@link tiltGroup}), so setting
157
+ * `group.rotation.x` yourself doesn't fight them — and setting `group.rotation.y` is the supported
158
+ * way to turn the pad once it's in a world.
159
+ */
160
+ readonly group: THREE.Group;
161
+ /** The inner pivot carrying the reading tilt and the trigger roll. Read it; don't write to it. */
162
+ readonly tiltGroup: THREE.Group;
163
+ /** What the design built — geometry, control nodes, stick pivots, disposables. */
164
+ readonly model: JoyconBuild;
165
+ /** Light a key, sink it, lean a stick. The same `PadDriver` every controller view speaks. */
166
+ readonly driver: PadDriver;
167
+ /** Every part this model actually draws. */
168
+ readonly parts: readonly PadPart[];
169
+ /** The node behind a part, for hanging your own things off a key (a label, an arrow). */
170
+ nodeOf(part: PadPart): THREE.Object3D | undefined;
171
+ /**
172
+ * Add the design's OWN lighting rig to your scene.
173
+ *
174
+ * Lighting is part of the art direction — a separate rig makes the same pad look like a different
175
+ * pad. Skip it only if your scene's lighting is deliberately taking over; the materials are standard
176
+ * PBR, so with no lights at all the pad renders black.
177
+ */
178
+ addLights(target: THREE.Object3D): void;
179
+ /**
180
+ * Advance every animation. Call once per frame; returns `true` while anything is still moving.
181
+ *
182
+ * `now` should be a `performance.now()`-style millisecond timestamp — pass the one your loop already
183
+ * has rather than calling it again, so the pad is on the same clock as the rest of the frame.
184
+ */
185
+ step(now: number): boolean;
186
+ /**
187
+ * Fires whenever the pad's appearance changed and a dirty-guarded renderer should redraw.
188
+ *
189
+ * Irrelevant if you render every frame anyway — which a game does. Returns an unsubscribe.
190
+ */
191
+ onChange(cb: () => void): () => void;
192
+ /**
193
+ * Fires while the pad MOVES on its own — the roll a lit trigger provokes.
194
+ *
195
+ * Anything positioned from a projection of the pad (a caption, a leader line) has to re-place itself
196
+ * here or it is left behind. Returns an unsubscribe.
197
+ */
198
+ onPoseChange(cb: () => void): () => void;
199
+ /**
200
+ * Mark the parts a callout currently points at.
201
+ *
202
+ * Only meaningful for the parts drawn faint (the shell's View/Guide): a callout pointing at one makes
203
+ * it the subject of the screen, and leaving it at 40% then reads as "disabled".
204
+ */
205
+ setReferenced(parts: ReadonlySet<PadPart>): void;
206
+ /** Release geometry, materials and textures. The `group` is removed from its parent. */
207
+ dispose(): void;
208
+ }
209
+ /**
210
+ * Build a Joy-Con that lives in your scene and reacts like the one in the HUD.
211
+ *
212
+ * For a pad framed in its own canvas — a controls screen, a HUD corner — you want
213
+ * `createThreePadRenderer` (or `mountPadHud` from `@rydr/game-sdk/ui`) instead; both are built on this.
214
+ */
215
+ export declare function createJoyconObject(opts?: JoyconObjectOptions): JoyconObject;
216
+ //# sourceMappingURL=joycon-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joycon-object.d.ts","sourceRoot":"","sources":["../../../src/three/controller/joycon-object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAkB,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO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