@adatechnology/game-player 0.14.0 → 0.15.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.
package/dist/index.js CHANGED
@@ -701,6 +701,242 @@ function createStepPose(start, options = {}) {
701
701
  };
702
702
  }
703
703
 
704
+ // src/vehicle-boarding.ts
705
+ var VEHICLE_BOARDING_DEFAULTS = { rattleSeconds: 0.75, endTolerance: 0.02 };
706
+ function createVehicleBoarding(ports, rules = {}) {
707
+ const r = { ...VEHICLE_BOARDING_DEFAULTS, ...rules };
708
+ let phase = "out";
709
+ let clock = 0;
710
+ const isOpen = () => ports.doorOpenness() >= 1 - r.endTolerance;
711
+ const isShut = () => ports.doorOpenness() <= r.endTolerance;
712
+ const sitDown = (events) => {
713
+ if (ports.sit()) phase = "sit";
714
+ else {
715
+ phase = "out";
716
+ events.push({ type: "refused", reason: "no_seat" });
717
+ }
718
+ };
719
+ const pending = [];
720
+ return {
721
+ get phase() {
722
+ return phase;
723
+ },
724
+ get driving() {
725
+ return phase === "in";
726
+ },
727
+ get handOnDoor() {
728
+ return phase === "shut" || phase === "unlatch";
729
+ },
730
+ enter() {
731
+ if (phase !== "out") return false;
732
+ if (!ports.hasDoor) {
733
+ if (!ports.sit()) return false;
734
+ phase = "sit";
735
+ return true;
736
+ }
737
+ if (isOpen()) {
738
+ phase = "open";
739
+ return true;
740
+ }
741
+ phase = "reach";
742
+ const locked = ports.doorLocked();
743
+ ports.reachHandle({
744
+ pull: true,
745
+ locked,
746
+ onGrip: () => {
747
+ if (phase !== "reach") return;
748
+ if (locked) {
749
+ phase = "refused";
750
+ clock = 0;
751
+ return;
752
+ }
753
+ ports.swingDoor(true);
754
+ phase = "open";
755
+ },
756
+ onMiss: () => {
757
+ if (phase !== "reach") return;
758
+ phase = "out";
759
+ pending.push({ type: "refused", reason: "blocked" });
760
+ }
761
+ });
762
+ return true;
763
+ },
764
+ takeSeat() {
765
+ if (phase !== "out" || !ports.sit()) return false;
766
+ phase = "sit";
767
+ return true;
768
+ },
769
+ leave() {
770
+ if (phase !== "in") return false;
771
+ if (!ports.hasDoor) {
772
+ if (!ports.stand()) {
773
+ pending.push({ type: "refused", reason: "blocked" });
774
+ return false;
775
+ }
776
+ phase = "stand";
777
+ return true;
778
+ }
779
+ ports.swingDoor(true);
780
+ phase = "unlatch";
781
+ return true;
782
+ },
783
+ dropped() {
784
+ if (phase === "out") return;
785
+ phase = "out";
786
+ pending.push({ type: "out" });
787
+ },
788
+ update(dt) {
789
+ const events = pending.splice(0);
790
+ switch (phase) {
791
+ case "refused":
792
+ clock += dt;
793
+ if (clock >= r.rattleSeconds) {
794
+ phase = "out";
795
+ events.push({ type: "refused", reason: "locked" });
796
+ }
797
+ break;
798
+ case "open":
799
+ if (isOpen()) sitDown(events);
800
+ break;
801
+ case "sit":
802
+ if (ports.seated() >= 1) {
803
+ if (ports.hasDoor && !isShut()) {
804
+ ports.swingDoor(false);
805
+ phase = "shut";
806
+ } else {
807
+ phase = "in";
808
+ events.push({ type: "in" });
809
+ }
810
+ }
811
+ break;
812
+ case "shut":
813
+ if (isShut()) {
814
+ phase = "in";
815
+ events.push({ type: "in" });
816
+ }
817
+ break;
818
+ case "unlatch":
819
+ if (!isOpen()) break;
820
+ if (ports.stand()) phase = "stand";
821
+ else {
822
+ ports.swingDoor(false);
823
+ phase = "shut";
824
+ events.push({ type: "refused", reason: "blocked" });
825
+ }
826
+ break;
827
+ case "stand":
828
+ if (ports.seated() > 0) break;
829
+ if (!ports.hasDoor) {
830
+ phase = "out";
831
+ events.push({ type: "out" });
832
+ break;
833
+ }
834
+ phase = "close";
835
+ ports.reachHandle({
836
+ pull: false,
837
+ locked: false,
838
+ onGrip: () => {
839
+ if (phase === "close") ports.swingDoor(false);
840
+ },
841
+ // the door out of reach stays open: the driver is out all the same
842
+ onMiss: () => {
843
+ if (phase !== "close") return;
844
+ phase = "out";
845
+ pending.push({ type: "out" });
846
+ }
847
+ });
848
+ break;
849
+ case "close":
850
+ if (isShut()) {
851
+ phase = "out";
852
+ events.push({ type: "out" });
853
+ }
854
+ break;
855
+ default:
856
+ break;
857
+ }
858
+ return events;
859
+ }
860
+ };
861
+ }
862
+
863
+ // src/driving-hands.ts
864
+ 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 };
865
+ var smooth = (k) => k * k * (3 - 2 * k);
866
+ function createDrivingHands(rules = {}) {
867
+ const r = { ...DRIVING_HANDS_DEFAULTS, ...rules };
868
+ 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 } };
869
+ let last = 0;
870
+ let shifting = null;
871
+ const busy = (h) => h.regrip >= 0 || h.toLever > 0;
872
+ const total = r.leverReachSeconds * 2 + r.leverHoldSeconds;
873
+ return {
874
+ left: hands.left,
875
+ right: hands.right,
876
+ get leverThrow() {
877
+ if (!shifting) return 1;
878
+ return smooth(Math.max(0, Math.min(1, (shifting.clock - r.leverReachSeconds) / r.leverHoldSeconds)));
879
+ },
880
+ shift(hand) {
881
+ if (shifting) return;
882
+ shifting = { hand, clock: 0 };
883
+ hands[hand].regrip = -1;
884
+ },
885
+ reset(wheel) {
886
+ last = wheel;
887
+ shifting = null;
888
+ for (const h of [hands.left, hands.right]) Object.assign(h, { at: 0, hold: 1, toLever: 0, regrip: -1, from: 0, to: 0 });
889
+ },
890
+ update(dt, wheel) {
891
+ const turned = wheel - last;
892
+ last = wheel;
893
+ if (shifting) {
894
+ shifting.clock += dt;
895
+ const h = hands[shifting.hand];
896
+ const c = shifting.clock;
897
+ const out = smooth(Math.min(1, c / r.leverReachSeconds));
898
+ const back = smooth(Math.max(0, Math.min(1, (c - r.leverReachSeconds - r.leverHoldSeconds) / r.leverReachSeconds)));
899
+ h.toLever = out * (1 - back);
900
+ h.hold = 1 - h.toLever;
901
+ h.at = 0;
902
+ if (c >= total) {
903
+ h.toLever = 0;
904
+ h.hold = 1;
905
+ shifting = null;
906
+ }
907
+ }
908
+ for (const side of ["left", "right"]) {
909
+ const h = hands[side];
910
+ const other = hands[side === "left" ? "right" : "left"];
911
+ if (h.toLever > 0) continue;
912
+ if (h.regrip >= 0) {
913
+ h.regrip += dt;
914
+ const k = Math.min(1, h.regrip / r.regripSeconds);
915
+ h.at = h.from + (h.to - h.from) * smooth(k);
916
+ h.hold = Math.abs(2 * k - 1);
917
+ if (k >= 1) {
918
+ h.regrip = -1;
919
+ h.at = h.to;
920
+ h.hold = 1;
921
+ }
922
+ continue;
923
+ }
924
+ h.at += turned;
925
+ const far = Math.abs(h.at);
926
+ const rate = dt > 0 ? turned / dt : 0;
927
+ const turning = Math.abs(rate) > r.stillRate;
928
+ const goesDown = turning && side === "left" === rate > 0 && Math.sign(h.at) === Math.sign(rate);
929
+ const wants = far > (goesDown ? r.firstAt : r.regripAt) || !turning && far > r.settleAt;
930
+ if (wants && !busy(other) || far > r.reachLimit) {
931
+ h.regrip = 0;
932
+ h.from = h.at;
933
+ h.to = turning ? -Math.sign(rate) * r.lead : 0;
934
+ }
935
+ }
936
+ }
937
+ };
938
+ }
939
+
704
940
  // src/gesture.ts
705
941
  var GESTURE_TIMING = {
706
942
  reach: 0.32,
@@ -887,6 +1123,7 @@ export {
887
1123
  DOOR_ARM_REACH,
888
1124
  DOOR_SHOULDER_HEIGHT,
889
1125
  DOOR_USE_DEFAULTS,
1126
+ DRIVING_HANDS_DEFAULTS,
890
1127
  FURNITURE_PUSH_DEFAULTS,
891
1128
  GESTURE_ARM_REACH,
892
1129
  GESTURE_TIMING,
@@ -904,6 +1141,7 @@ export {
904
1141
  SLING_SLOT,
905
1142
  SLOT_FALLBACKS,
906
1143
  STEP_POSE_DEFAULTS,
1144
+ VEHICLE_BOARDING_DEFAULTS,
907
1145
  WALKER_JUMP_SPEED,
908
1146
  advanceNeeds,
909
1147
  applyItemEffect,
@@ -913,6 +1151,7 @@ export {
913
1151
  conjugateQuaternion,
914
1152
  createBodyVitals,
915
1153
  createDoorUse,
1154
+ createDrivingHands,
916
1155
  createFurniturePush,
917
1156
  createGestureHands,
918
1157
  createGestureTimeline,
@@ -923,6 +1162,7 @@ export {
923
1162
  createRng,
924
1163
  createStepPose,
925
1164
  createTakeTimeline,
1165
+ createVehicleBoarding,
926
1166
  createWalker,
927
1167
  deriveVitals,
928
1168
  dragMarkFor,