@adatechnology/game-player 0.14.0 → 0.15.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.
package/README.md CHANGED
@@ -109,6 +109,18 @@ The walk with the piece speeds up and brakes like a person's (`accel`: the force
109
109
 
110
110
  `createDoorUse(rules?)` is the logic of working a door, lid or drawer by hand: `begin({ opening, massKg, locked })` answers where the leaf goes (1 open, 0 closed; a second `begin` in the middle of a swing turns it round) or null for a locked leaf, which only rattles. `step(dt, isFree, hand?)` then goes through `reach` (the hand to the handle), `swing` (the leaf follows the hand, a little at a time so it stops at the first thing in its way, `block: 'obstacle'`) and `release`. The player does not follow the leaf: when `hand.reaches()` says the handle left the arm (`DOOR_ARM_REACH` from the shoulder), a leaf that goes away gets a shove (`push`, `hand.pull` false) and one that comes toward the body is let go (`release`), and the leaf finishes on its own to its goal. A heavier leaf swings slower (`swingSecondsFor`); every number is in `DoorUseRules` (`DOOR_USE_DEFAULTS`).
111
111
 
112
+ ## Getting into a vehicle and driving it
113
+
114
+ `createVehicleBoarding(ports)` is the body getting into a vehicle and out of it: the hand to the door's handle, the door open, the body seated, the door
115
+ pulled shut, and only then `driving`; `leave()` runs it backwards (the door opened from the seat, the body up at the sill, the door shut from outside). A
116
+ locked door is only shaken (`refused`), a hand that cannot get to the handle grips nothing, an exit with nowhere to stand brings the door back shut, and a
117
+ vehicle without a door is sat on and got off. `takeSeat()` puts the body at the seat without the door. The host owns the door, the seat and the hand
118
+ (`VehicleBoardingPorts`).
119
+
120
+ `createDrivingHands()` is the driver's hands: both on the rim, going round with the wheel; the hand that goes down the rim lets go first and takes it again
121
+ ahead of its place, the other after it, never both off the wheel; `shift(hand)` sends the hand on the lever's side to the knob, moves the lever
122
+ (`leverThrow`) and brings it back. Angles on the rim and shares of the way to the lever: the host turns them into places in its world.
123
+
112
124
  ## The hands and the weapon
113
125
 
114
126
  `planHands({ hands, weapons: { R, L }, slots })` is the owner's rule (2026-11-24): an interaction of one hand (a small thing picked up, a door, a switch) takes the free hand, not the
package/dist/index.d.ts CHANGED
@@ -560,6 +560,128 @@ declare const STEP_POSE_DEFAULTS: {
560
560
  };
561
561
  declare function createStepPose(start: StepPosition, options?: StepPoseOptions): StepPose;
562
562
 
563
+ /**
564
+ * Getting into a vehicle and out of it, as a body does it: the hand goes to the door's handle, the door opens, the body sits, the hand on the door's side
565
+ * pulls the door shut; out, the same backwards (the door opened from inside, the body up at the sill, the door pushed shut). A locked door is only shaken.
566
+ * A vehicle without a door (a motorcycle, an open tractor) is sat on and got off. Engine-agnostic: the host owns the door, the seat and the hand
567
+ * (`VehicleBoardingPorts`); this says what happens next and when the driver is in.
568
+ */
569
+ /**
570
+ * `out` on its feet; `reach` the hand going to the handle; `refused` shaking a locked door; `open` the door swinging open; `sit` the body going to the seat;
571
+ * `shut` seated, pulling the door shut; `in` seated with the door shut (the driver drives); `unlatch` seated, pushing the door open; `stand` getting up at the
572
+ * sill; `close` on its feet, the hand shutting the door.
573
+ */
574
+ type VehicleBoardingPhase = 'out' | 'reach' | 'refused' | 'open' | 'sit' | 'shut' | 'in' | 'unlatch' | 'stand' | 'close';
575
+ type VehicleBoardingEvent = {
576
+ readonly type: 'in';
577
+ } | {
578
+ readonly type: 'out';
579
+ } | {
580
+ readonly type: 'refused';
581
+ readonly reason: 'locked' | 'no_seat' | 'blocked';
582
+ };
583
+ /** What the hand asks of the host at a door's outer handle: `pull` the door comes to the body (opening) or goes away (shutting); `onGrip` once the hand is on it. */
584
+ interface VehicleHandleReach {
585
+ readonly pull: boolean;
586
+ readonly locked: boolean;
587
+ onGrip(): void;
588
+ /** The body could not get to the handle: nothing was gripped. */
589
+ onMiss(): void;
590
+ }
591
+ interface VehicleBoardingPorts {
592
+ /** The seat is entered by a door (false: sat on from outside, as a motorcycle). */
593
+ readonly hasDoor: boolean;
594
+ doorLocked(): boolean;
595
+ /** 0 shut to 1 open. */
596
+ doorOpenness(): number;
597
+ /** Starts the door swinging to open (true) or shut (false). */
598
+ swingDoor(open: boolean): void;
599
+ /** Sends the hand to the outer handle; a host without a hand calls `onGrip` at once. */
600
+ reachHandle(reach: VehicleHandleReach): void;
601
+ /** Starts the body sitting down on the seat; false when it cannot. */
602
+ sit(): boolean;
603
+ /** Starts the body getting up at the seat's exit; false when the exit is blocked. */
604
+ stand(): boolean;
605
+ /** How far into the seat the body is: 0 on its feet, 1 seated. */
606
+ seated(): number;
607
+ }
608
+ interface VehicleBoardingRules {
609
+ /** How long a locked door is shaken before the hand gives up, seconds. */
610
+ readonly rattleSeconds: number;
611
+ /** Within this of shut or open the door counts as there. */
612
+ readonly endTolerance: number;
613
+ }
614
+ declare const VEHICLE_BOARDING_DEFAULTS: VehicleBoardingRules;
615
+ interface VehicleBoarding {
616
+ readonly phase: VehicleBoardingPhase;
617
+ /** The driver is seated with the door shut: the controls are the driver's. */
618
+ readonly driving: boolean;
619
+ /** The hand on the door's side is on the door's inner pull (shutting it from the seat, or opening it to get out). */
620
+ readonly handOnDoor: boolean;
621
+ /** Starts getting in; false when not on its feet outside. */
622
+ enter(): boolean;
623
+ /**
624
+ * Sits without going to the door: the body is put at the seat (a bench's shortcut, a driver who starts inside, a door the body has no clear way to).
625
+ * False when not on its feet outside or the seat refuses.
626
+ */
627
+ takeSeat(): boolean;
628
+ /** Starts getting out; false when not driving. */
629
+ leave(): boolean;
630
+ /** The body left the seat by another way (the host got it up, the seat is gone): on its feet, the door as it is. */
631
+ dropped(): void;
632
+ update(dt: number): VehicleBoardingEvent[];
633
+ }
634
+ declare function createVehicleBoarding(ports: VehicleBoardingPorts, rules?: Partial<VehicleBoardingRules>): VehicleBoarding;
635
+
636
+ /**
637
+ * The hands of a driver: both on the rim of the steering wheel, turning with it; a hand carried too far round lets go, comes back to its own side and holds
638
+ * again (one hand at a time, the other keeps the wheel); to change gear the hand on the lever's side leaves the rim, takes the knob, moves it and comes back.
639
+ * Engine-agnostic: the host gives the wheel's turn and says when a gear changes; this says where each hand is, as angles on the rim and shares of the way to
640
+ * the lever, and the host turns that into places in its world.
641
+ */
642
+ interface DrivingHandsRules {
643
+ /** A hand carried this far round from its own place lets go to hold again, radians (a quarter turn and a little). */
644
+ readonly regripAt: number;
645
+ /** The hand on the side the wheel turns to goes down the rim and lets go sooner, radians: it is the one that reaches back up for more wheel. */
646
+ readonly firstAt: number;
647
+ /** While the wheel keeps turning, a hand takes the rim again this far before its own place, radians, so it has wheel to pull. */
648
+ readonly lead: number;
649
+ /** Under this the wheel is held still, radians a second: a hand left off its own place goes back to it. */
650
+ readonly stillRate: number;
651
+ /** A hand at rest this far from its own place goes back to it, radians. */
652
+ readonly settleAt: number;
653
+ /** Past this a hand cannot stay on the rim whatever the other one does, radians. */
654
+ readonly reachLimit: number;
655
+ /** Letting go, coming back and holding again, seconds. */
656
+ readonly regripSeconds: number;
657
+ /** The hand from the rim to the knob, and back, seconds each way. */
658
+ readonly leverReachSeconds: number;
659
+ /** The hand on the knob while the lever moves, seconds. */
660
+ readonly leverHoldSeconds: number;
661
+ }
662
+ declare const DRIVING_HANDS_DEFAULTS: DrivingHandsRules;
663
+ interface DrivingHand {
664
+ /** Where on the rim the hand is, radians from its own place at rest, the way the wheel turns (positive to the left). */
665
+ readonly at: number;
666
+ /** 1 holding the rim, down to 0 off it (coming back to hold again, or gone to the lever). */
667
+ readonly hold: number;
668
+ /** Share of the way from the rim to the gear lever's knob, 0 on the rim to 1 on the knob. */
669
+ readonly toLever: number;
670
+ }
671
+ interface DrivingHands {
672
+ readonly left: DrivingHand;
673
+ readonly right: DrivingHand;
674
+ /** Share of the lever's throw done in the gear change going on, 0 before the hand moves it to 1 moved; 1 when no change is going on. */
675
+ readonly leverThrow: number;
676
+ /** A gear change starts: `hand` the hand on the lever's side. Ignored while one is going on. */
677
+ shift(hand: 'left' | 'right'): void;
678
+ /** `wheel`: the steering wheel's turn now, radians, positive to the left. */
679
+ update(dt: number, wheel: number): void;
680
+ /** Both hands back on the rim at rest (the driver got in). */
681
+ reset(wheel: number): void;
682
+ }
683
+ declare function createDrivingHands(rules?: Partial<DrivingHandsRules>): DrivingHands;
684
+
563
685
  /**
564
686
  * The body works a control with one hand (CLAUDE.md §18, owner 2026-11-30: every action has a body animation): the free hand `reach`es the point, does the `act` of the gesture
565
687
  * (presses a button, turns a knob, flips a rocker, strikes a match, pours, lets go inside, tips over, closes on the thing to stow it, holds the paper up to read) and goes `back`.
@@ -702,4 +824,4 @@ interface GestureHands {
702
824
  }
703
825
  declare function createGestureHands(deps: GestureHandDeps): GestureHands;
704
826
 
705
- export { BELT_SLOT, type BodyHand, DOOR_ARM_REACH, DOOR_SHOULDER_HEIGHT, DOOR_USE_DEFAULTS, type DoorUse, type DoorUseBlock, type DoorUseHand, type DoorUsePhase, type DoorUseRules, type DoorUseStep, type DoorUseTarget, type DragMark, FURNITURE_PUSH_DEFAULTS, type FurniturePush, type FurniturePushBlock, type FurniturePushInput, type FurniturePushLoad, type FurniturePushPhase, type FurniturePushRules, type FurniturePushStep, type FurniturePushTarget, GESTURE_ARM_REACH, GESTURE_TIMING, type GestureBody, type GestureHand, type GestureHandChoice, type GestureHandDeps, type GestureHandParams, type GestureHands, type GesturePhase, type GestureProgress, type GestureRefusal, type GestureStart, type GestureStartResult, type GestureTimeline, type GestureTiming, HANDS_BY_HANDLE, HANDS_DEFAULTS, HANDS_TIMING, type HandWeapon, type HandsMove, type HandsMoveKind, type HandsPlan, type HandsRules, type HandsTiming, ITEM_GRIP, type ItemGrip, KnownDeathCause, LIFT_DEFAULTS, type LiftCheck, type LiftRules, type LiftVerdict, PLAYER_MASS_KG, PLAYER_PUSH_STRENGTH_NEWTONS, PLAYER_TEXT, PLAYER_WALK_PUSH_NEWTONS, type PhysicsControllerOptions, type PhysicsPlayerController, type PlanHandsParams, PlayerCollider, PlayerController, PlayerMessageId, type PlayerPhysicsWorld, type PlayerText, type Pose, type QuatTuple, SLING_SLOT, SLOT_FALLBACKS, STEP_POSE_DEFAULTS, type StepPose, type StepPoseOptions, type StepPosition, type TakeProgress, type TakeSequence, type TakeStep, type TakeStepKind, type TakeTimeline, type Vec3Tuple, WALKER_JUMP_SPEED, type Walker, type WalkerOptions, type WalkerServices, type WalkerStance, blendPoses, canPush, composePose, conjugateQuaternion, createDoorUse, createFurniturePush, createGestureHands, createGestureTimeline, createPhysicsController, createRng, createStepPose, createTakeTimeline, createWalker, dragMarkFor, drawBackOf, easeInOut, footRestHeight, freeHandOf, frictionFor, gestureHandOf, gestureHandPose, gripOfItem, gripOnHandle, gripSecondsFor, handPoseOnItem, interactionHandsFor, itemPoseInHand, liftCheckFor, multiplyQuaternions, planDrawSequence, planHands, planTakeSequence, playerTextOf, poseHolding, pushAccelerationFor, pushSpeedFor, quaternionOfBasis, rotateVector, slipsOnTop, swingSecondsFor };
827
+ export { BELT_SLOT, type BodyHand, DOOR_ARM_REACH, DOOR_SHOULDER_HEIGHT, DOOR_USE_DEFAULTS, DRIVING_HANDS_DEFAULTS, type DoorUse, type DoorUseBlock, type DoorUseHand, type DoorUsePhase, type DoorUseRules, type DoorUseStep, type DoorUseTarget, type DragMark, type DrivingHand, type DrivingHands, type DrivingHandsRules, FURNITURE_PUSH_DEFAULTS, type FurniturePush, type FurniturePushBlock, type FurniturePushInput, type FurniturePushLoad, type FurniturePushPhase, type FurniturePushRules, type FurniturePushStep, type FurniturePushTarget, GESTURE_ARM_REACH, GESTURE_TIMING, type GestureBody, type GestureHand, type GestureHandChoice, type GestureHandDeps, type GestureHandParams, type GestureHands, type GesturePhase, type GestureProgress, type GestureRefusal, type GestureStart, type GestureStartResult, type GestureTimeline, type GestureTiming, HANDS_BY_HANDLE, HANDS_DEFAULTS, HANDS_TIMING, type HandWeapon, type HandsMove, type HandsMoveKind, type HandsPlan, type HandsRules, type HandsTiming, ITEM_GRIP, type ItemGrip, KnownDeathCause, LIFT_DEFAULTS, type LiftCheck, type LiftRules, type LiftVerdict, PLAYER_MASS_KG, PLAYER_PUSH_STRENGTH_NEWTONS, PLAYER_TEXT, PLAYER_WALK_PUSH_NEWTONS, type PhysicsControllerOptions, type PhysicsPlayerController, type PlanHandsParams, PlayerCollider, PlayerController, PlayerMessageId, type PlayerPhysicsWorld, type PlayerText, type Pose, type QuatTuple, SLING_SLOT, SLOT_FALLBACKS, STEP_POSE_DEFAULTS, type StepPose, type StepPoseOptions, type StepPosition, type TakeProgress, type TakeSequence, type TakeStep, type TakeStepKind, type TakeTimeline, VEHICLE_BOARDING_DEFAULTS, type Vec3Tuple, type VehicleBoarding, type VehicleBoardingEvent, type VehicleBoardingPhase, type VehicleBoardingPorts, type VehicleBoardingRules, type VehicleHandleReach, WALKER_JUMP_SPEED, type Walker, type WalkerOptions, type WalkerServices, type WalkerStance, blendPoses, canPush, composePose, conjugateQuaternion, createDoorUse, createDrivingHands, createFurniturePush, createGestureHands, createGestureTimeline, createPhysicsController, createRng, createStepPose, createTakeTimeline, createVehicleBoarding, createWalker, dragMarkFor, drawBackOf, easeInOut, footRestHeight, freeHandOf, frictionFor, gestureHandOf, gestureHandPose, gripOfItem, gripOnHandle, gripSecondsFor, handPoseOnItem, interactionHandsFor, itemPoseInHand, liftCheckFor, multiplyQuaternions, planDrawSequence, planHands, planTakeSequence, playerTextOf, poseHolding, pushAccelerationFor, pushSpeedFor, quaternionOfBasis, rotateVector, slipsOnTop, swingSecondsFor };
@@ -25,6 +25,7 @@ var GamePlayer = (() => {
25
25
  DOOR_ARM_REACH: () => DOOR_ARM_REACH,
26
26
  DOOR_SHOULDER_HEIGHT: () => DOOR_SHOULDER_HEIGHT,
27
27
  DOOR_USE_DEFAULTS: () => DOOR_USE_DEFAULTS,
28
+ DRIVING_HANDS_DEFAULTS: () => DRIVING_HANDS_DEFAULTS,
28
29
  FURNITURE_PUSH_DEFAULTS: () => FURNITURE_PUSH_DEFAULTS,
29
30
  GESTURE_ARM_REACH: () => GESTURE_ARM_REACH,
30
31
  GESTURE_TIMING: () => GESTURE_TIMING,
@@ -42,6 +43,7 @@ var GamePlayer = (() => {
42
43
  SLING_SLOT: () => SLING_SLOT,
43
44
  SLOT_FALLBACKS: () => SLOT_FALLBACKS,
44
45
  STEP_POSE_DEFAULTS: () => STEP_POSE_DEFAULTS,
46
+ VEHICLE_BOARDING_DEFAULTS: () => VEHICLE_BOARDING_DEFAULTS,
45
47
  WALKER_JUMP_SPEED: () => WALKER_JUMP_SPEED,
46
48
  advanceNeeds: () => advanceNeeds,
47
49
  applyItemEffect: () => applyItemEffect,
@@ -51,6 +53,7 @@ var GamePlayer = (() => {
51
53
  conjugateQuaternion: () => conjugateQuaternion,
52
54
  createBodyVitals: () => createBodyVitals,
53
55
  createDoorUse: () => createDoorUse,
56
+ createDrivingHands: () => createDrivingHands,
54
57
  createFurniturePush: () => createFurniturePush,
55
58
  createGestureHands: () => createGestureHands,
56
59
  createGestureTimeline: () => createGestureTimeline,
@@ -61,6 +64,7 @@ var GamePlayer = (() => {
61
64
  createRng: () => createRng,
62
65
  createStepPose: () => createStepPose,
63
66
  createTakeTimeline: () => createTakeTimeline,
67
+ createVehicleBoarding: () => createVehicleBoarding,
64
68
  createWalker: () => createWalker,
65
69
  deriveVitals: () => deriveVitals,
66
70
  dragMarkFor: () => dragMarkFor,
@@ -133,6 +137,8 @@ var GamePlayer = (() => {
133
137
  [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
134
138
  };
135
139
  var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
140
+ var BODY_FOAM_SURFACES = ["hands", "arms", "torso", "hair", "mouth"];
141
+ var WASH_SURFACES = [...BODY_FOAM_SURFACES, "brush"];
136
142
  var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
137
143
  var DEFAULT_SURFACE = "concrete";
138
144
  var GAIT_IDS = ["walk", "run"];
@@ -2121,6 +2127,242 @@ var GamePlayer = (() => {
2121
2127
  };
2122
2128
  }
2123
2129
 
2130
+ // src/vehicle-boarding.ts
2131
+ var VEHICLE_BOARDING_DEFAULTS = { rattleSeconds: 0.75, endTolerance: 0.02 };
2132
+ function createVehicleBoarding(ports, rules = {}) {
2133
+ const r = { ...VEHICLE_BOARDING_DEFAULTS, ...rules };
2134
+ let phase = "out";
2135
+ let clock = 0;
2136
+ const isOpen = () => ports.doorOpenness() >= 1 - r.endTolerance;
2137
+ const isShut = () => ports.doorOpenness() <= r.endTolerance;
2138
+ const sitDown = (events) => {
2139
+ if (ports.sit()) phase = "sit";
2140
+ else {
2141
+ phase = "out";
2142
+ events.push({ type: "refused", reason: "no_seat" });
2143
+ }
2144
+ };
2145
+ const pending = [];
2146
+ return {
2147
+ get phase() {
2148
+ return phase;
2149
+ },
2150
+ get driving() {
2151
+ return phase === "in";
2152
+ },
2153
+ get handOnDoor() {
2154
+ return phase === "shut" || phase === "unlatch";
2155
+ },
2156
+ enter() {
2157
+ if (phase !== "out") return false;
2158
+ if (!ports.hasDoor) {
2159
+ if (!ports.sit()) return false;
2160
+ phase = "sit";
2161
+ return true;
2162
+ }
2163
+ if (isOpen()) {
2164
+ phase = "open";
2165
+ return true;
2166
+ }
2167
+ phase = "reach";
2168
+ const locked = ports.doorLocked();
2169
+ ports.reachHandle({
2170
+ pull: true,
2171
+ locked,
2172
+ onGrip: () => {
2173
+ if (phase !== "reach") return;
2174
+ if (locked) {
2175
+ phase = "refused";
2176
+ clock = 0;
2177
+ return;
2178
+ }
2179
+ ports.swingDoor(true);
2180
+ phase = "open";
2181
+ },
2182
+ onMiss: () => {
2183
+ if (phase !== "reach") return;
2184
+ phase = "out";
2185
+ pending.push({ type: "refused", reason: "blocked" });
2186
+ }
2187
+ });
2188
+ return true;
2189
+ },
2190
+ takeSeat() {
2191
+ if (phase !== "out" || !ports.sit()) return false;
2192
+ phase = "sit";
2193
+ return true;
2194
+ },
2195
+ leave() {
2196
+ if (phase !== "in") return false;
2197
+ if (!ports.hasDoor) {
2198
+ if (!ports.stand()) {
2199
+ pending.push({ type: "refused", reason: "blocked" });
2200
+ return false;
2201
+ }
2202
+ phase = "stand";
2203
+ return true;
2204
+ }
2205
+ ports.swingDoor(true);
2206
+ phase = "unlatch";
2207
+ return true;
2208
+ },
2209
+ dropped() {
2210
+ if (phase === "out") return;
2211
+ phase = "out";
2212
+ pending.push({ type: "out" });
2213
+ },
2214
+ update(dt) {
2215
+ const events = pending.splice(0);
2216
+ switch (phase) {
2217
+ case "refused":
2218
+ clock += dt;
2219
+ if (clock >= r.rattleSeconds) {
2220
+ phase = "out";
2221
+ events.push({ type: "refused", reason: "locked" });
2222
+ }
2223
+ break;
2224
+ case "open":
2225
+ if (isOpen()) sitDown(events);
2226
+ break;
2227
+ case "sit":
2228
+ if (ports.seated() >= 1) {
2229
+ if (ports.hasDoor && !isShut()) {
2230
+ ports.swingDoor(false);
2231
+ phase = "shut";
2232
+ } else {
2233
+ phase = "in";
2234
+ events.push({ type: "in" });
2235
+ }
2236
+ }
2237
+ break;
2238
+ case "shut":
2239
+ if (isShut()) {
2240
+ phase = "in";
2241
+ events.push({ type: "in" });
2242
+ }
2243
+ break;
2244
+ case "unlatch":
2245
+ if (!isOpen()) break;
2246
+ if (ports.stand()) phase = "stand";
2247
+ else {
2248
+ ports.swingDoor(false);
2249
+ phase = "shut";
2250
+ events.push({ type: "refused", reason: "blocked" });
2251
+ }
2252
+ break;
2253
+ case "stand":
2254
+ if (ports.seated() > 0) break;
2255
+ if (!ports.hasDoor) {
2256
+ phase = "out";
2257
+ events.push({ type: "out" });
2258
+ break;
2259
+ }
2260
+ phase = "close";
2261
+ ports.reachHandle({
2262
+ pull: false,
2263
+ locked: false,
2264
+ onGrip: () => {
2265
+ if (phase === "close") ports.swingDoor(false);
2266
+ },
2267
+ // the door out of reach stays open: the driver is out all the same
2268
+ onMiss: () => {
2269
+ if (phase !== "close") return;
2270
+ phase = "out";
2271
+ pending.push({ type: "out" });
2272
+ }
2273
+ });
2274
+ break;
2275
+ case "close":
2276
+ if (isShut()) {
2277
+ phase = "out";
2278
+ events.push({ type: "out" });
2279
+ }
2280
+ break;
2281
+ default:
2282
+ break;
2283
+ }
2284
+ return events;
2285
+ }
2286
+ };
2287
+ }
2288
+
2289
+ // src/driving-hands.ts
2290
+ var DRIVING_HANDS_DEFAULTS = { regripAt: 1.75, firstAt: 0.7, lead: 0.9, stillRate: 0.3, settleAt: 0.25, reachLimit: 2.3, regripSeconds: 0.24, leverReachSeconds: 0.22, leverHoldSeconds: 0.26 };
2291
+ var smooth = (k) => k * k * (3 - 2 * k);
2292
+ function createDrivingHands(rules = {}) {
2293
+ const r = { ...DRIVING_HANDS_DEFAULTS, ...rules };
2294
+ const hands = { left: { at: 0, hold: 1, toLever: 0, regrip: -1, from: 0, to: 0 }, right: { at: 0, hold: 1, toLever: 0, regrip: -1, from: 0, to: 0 } };
2295
+ let last = 0;
2296
+ let shifting = null;
2297
+ const busy = (h) => h.regrip >= 0 || h.toLever > 0;
2298
+ const total = r.leverReachSeconds * 2 + r.leverHoldSeconds;
2299
+ return {
2300
+ left: hands.left,
2301
+ right: hands.right,
2302
+ get leverThrow() {
2303
+ if (!shifting) return 1;
2304
+ return smooth(Math.max(0, Math.min(1, (shifting.clock - r.leverReachSeconds) / r.leverHoldSeconds)));
2305
+ },
2306
+ shift(hand) {
2307
+ if (shifting) return;
2308
+ shifting = { hand, clock: 0 };
2309
+ hands[hand].regrip = -1;
2310
+ },
2311
+ reset(wheel) {
2312
+ last = wheel;
2313
+ shifting = null;
2314
+ for (const h of [hands.left, hands.right]) Object.assign(h, { at: 0, hold: 1, toLever: 0, regrip: -1, from: 0, to: 0 });
2315
+ },
2316
+ update(dt, wheel) {
2317
+ const turned = wheel - last;
2318
+ last = wheel;
2319
+ if (shifting) {
2320
+ shifting.clock += dt;
2321
+ const h = hands[shifting.hand];
2322
+ const c = shifting.clock;
2323
+ const out = smooth(Math.min(1, c / r.leverReachSeconds));
2324
+ const back = smooth(Math.max(0, Math.min(1, (c - r.leverReachSeconds - r.leverHoldSeconds) / r.leverReachSeconds)));
2325
+ h.toLever = out * (1 - back);
2326
+ h.hold = 1 - h.toLever;
2327
+ h.at = 0;
2328
+ if (c >= total) {
2329
+ h.toLever = 0;
2330
+ h.hold = 1;
2331
+ shifting = null;
2332
+ }
2333
+ }
2334
+ for (const side of ["left", "right"]) {
2335
+ const h = hands[side];
2336
+ const other = hands[side === "left" ? "right" : "left"];
2337
+ if (h.toLever > 0) continue;
2338
+ if (h.regrip >= 0) {
2339
+ h.regrip += dt;
2340
+ const k = Math.min(1, h.regrip / r.regripSeconds);
2341
+ h.at = h.from + (h.to - h.from) * smooth(k);
2342
+ h.hold = Math.abs(2 * k - 1);
2343
+ if (k >= 1) {
2344
+ h.regrip = -1;
2345
+ h.at = h.to;
2346
+ h.hold = 1;
2347
+ }
2348
+ continue;
2349
+ }
2350
+ h.at += turned;
2351
+ const far = Math.abs(h.at);
2352
+ const rate = dt > 0 ? turned / dt : 0;
2353
+ const turning = Math.abs(rate) > r.stillRate;
2354
+ const goesDown = turning && side === "left" === rate > 0 && Math.sign(h.at) === Math.sign(rate);
2355
+ const wants = far > (goesDown ? r.firstAt : r.regripAt) || !turning && far > r.settleAt;
2356
+ if (wants && !busy(other) || far > r.reachLimit) {
2357
+ h.regrip = 0;
2358
+ h.from = h.at;
2359
+ h.to = turning ? -Math.sign(rate) * r.lead : 0;
2360
+ }
2361
+ }
2362
+ }
2363
+ };
2364
+ }
2365
+
2124
2366
  // src/gesture.ts
2125
2367
  var GESTURE_TIMING = {
2126
2368
  reach: 0.32,