@adatechnology/game-vehicles-driving 0.3.13 → 0.4.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.d.ts CHANGED
@@ -496,7 +496,7 @@ declare const DEFAULT_CRUISE: CruiseOptions;
496
496
  /** Gas cruise control asks for to hold `target` at `speed` (m/s); none above the target, the car coasts down to it. */
497
497
  declare function cruiseThrottle(target: number, speed: number, options?: CruiseOptions): number;
498
498
 
499
- type ControlCommand = 'ignition' | 'gearbox' | 'gear_up' | 'gear_down' | 'parking_brake' | 'drive_mode' | 'lights' | 'high_beam' | 'fog_lights' | 'interior_light' | 'alarm' | 'radio' | 'radio_source' | 'radio_track' | 'exit' | 'indicator_left' | 'indicator_right' | 'hazard' | 'wipers' | 'seatbelt' | 'drive_profile' | 'traction_control' | 'abs' | 'cruise' | 'climate' | 'demist' | 'siren' | 'beacon' | 'glovebox';
499
+ type ControlCommand = 'ignition' | 'gearbox' | 'gear_up' | 'gear_down' | 'parking_brake' | 'drive_mode' | 'lights' | 'high_beam' | 'fog_lights' | 'interior_light' | 'alarm' | 'radio' | 'radio_source' | 'radio_track' | 'exit' | 'indicator_left' | 'indicator_right' | 'hazard' | 'wipers' | 'seatbelt' | 'drive_profile' | 'traction_control' | 'abs' | 'cruise' | 'climate' | 'demist' | 'siren' | 'beacon' | 'comm' | 'glovebox';
500
500
  type ControlKeyMap = {
501
501
  readonly throttle: readonly string[];
502
502
  readonly brake: readonly string[];
@@ -508,6 +508,8 @@ type ControlKeyMap = {
508
508
  /** Flashes the high beam while held. */
509
509
  readonly flash: readonly string[];
510
510
  readonly washer: readonly string[];
511
+ /** The two-way radio's button on the microphone: it transmits while held (the set must be on). */
512
+ readonly talk: readonly string[];
511
513
  /** Held without the key (`hasKey: false`): strips and joins the wires under the column until the engine turns over. */
512
514
  readonly hotwire: readonly string[];
513
515
  } & {
@@ -587,6 +589,11 @@ interface ControlState {
587
589
  beaconSide: 0 | 1;
588
590
  /** The glovebox lid is open. */
589
591
  glovebox: boolean;
592
+ /** The two-way radio of an emergency vehicle: the set is on (it hisses and takes the calls of the net), and the driver transmits (the button held: the set is silent meanwhile). */
593
+ comm: {
594
+ on: boolean;
595
+ talking: boolean;
596
+ };
590
597
  }
591
598
  type ControlEvent = {
592
599
  type: 'command';
@@ -595,10 +602,15 @@ type ControlEvent = {
595
602
  } | {
596
603
  type: 'refused';
597
604
  command: ControlCommand;
598
- reason: 'no_four_wheel_drive' | 'no_fog_lamps' | 'ignition_off' | 'battery_flat' | 'too_slow' | 'no_key' | 'no_siren';
605
+ reason: 'no_four_wheel_drive' | 'no_fog_lamps' | 'ignition_off' | 'battery_flat' | 'too_slow' | 'no_key' | 'no_siren' | 'no_comm_radio';
599
606
  } | {
600
607
  type: 'cruise_cancelled';
601
608
  }
609
+ /** The two-way radio's button: down (the driver transmits) and let go of (the set listens again). */
610
+ | {
611
+ type: 'transmit';
612
+ on: boolean;
613
+ }
602
614
  /** The wires under the column: stripped (first touch), joined (the ignition is live and the starter turns). */
603
615
  | {
604
616
  type: 'hotwire';
@@ -640,6 +652,8 @@ interface VehicleControlOptions {
640
652
  hotwireSeconds?: number;
641
653
  /** The vehicle has a siren and a beacon (an emergency vehicle). Default false: both refuse. */
642
654
  emergency?: boolean;
655
+ /** The vehicle has a two-way radio (police, ambulance, fire). Default: as `emergency`. Without one `comm` refuses. */
656
+ commRadio?: boolean;
643
657
  /** The beacon's sides swap this many times a second. Default 2.5. */
644
658
  beaconHz?: number;
645
659
  onEvent?: (event: ControlEvent) => void;
@@ -845,9 +845,11 @@ var GameVehiclesDriving = (() => {
845
845
  demist: ["Equal"],
846
846
  siren: ["Semicolon"],
847
847
  beacon: ["Quote"],
848
- glovebox: ["Slash"]
848
+ glovebox: ["Slash"],
849
+ comm: ["BracketLeft"],
850
+ talk: ["Backslash"]
849
851
  };
850
- var HELD_KEYS = ["throttle", "brake", "left", "right", "handbrake", "horn", "clutch", "flash", "washer", "hotwire"];
852
+ var HELD_KEYS = ["throttle", "brake", "left", "right", "handbrake", "horn", "clutch", "flash", "washer", "hotwire", "talk"];
851
853
  function createVehicleControls(options) {
852
854
  const keys = { ...DEFAULT_CONTROL_KEYS, ...options.keys };
853
855
  const auto4 = options.autoFourWheel ?? { slip: 0.18, releaseSeconds: 2 };
@@ -887,9 +889,11 @@ var GameVehiclesDriving = (() => {
887
889
  siren: "off",
888
890
  beacon: false,
889
891
  beaconSide: 0,
890
- glovebox: false
892
+ glovebox: false,
893
+ comm: { on: false, talking: false }
891
894
  };
892
895
  const hasKey = options.hasKey !== false;
896
+ const hasComm = options.commRadio ?? !!options.emergency;
893
897
  const hotwireSeconds = Math.max(0.1, options.hotwireSeconds ?? 8);
894
898
  const beaconHz = options.beaconHz ?? 2.5;
895
899
  let beaconClock = 0;
@@ -1021,6 +1025,14 @@ var GameVehiclesDriving = (() => {
1021
1025
  case "glovebox":
1022
1026
  state.glovebox = !state.glovebox;
1023
1027
  break;
1028
+ case "comm":
1029
+ if (!hasComm) return emit({ type: "refused", command: c, reason: "no_comm_radio" });
1030
+ state.comm.on = !state.comm.on;
1031
+ if (!state.comm.on && state.comm.talking) {
1032
+ state.comm.talking = false;
1033
+ emit({ type: "transmit", on: false });
1034
+ }
1035
+ break;
1024
1036
  }
1025
1037
  emit({ type: "command", command: c, state });
1026
1038
  };
@@ -1080,6 +1092,11 @@ var GameVehiclesDriving = (() => {
1080
1092
  state.horn = any(keys.horn);
1081
1093
  state.lamps.flash = any(keys.flash);
1082
1094
  state.washer = any(keys.washer);
1095
+ const talking = state.comm.on && any(keys.talk);
1096
+ if (talking !== state.comm.talking) {
1097
+ state.comm.talking = talking;
1098
+ emit({ type: "transmit", on: talking });
1099
+ }
1083
1100
  state.clutch = ease(state.clutch, any(keys.clutch) ? 1 : 0, any(keys.clutch) ? 8 : 2.5, dt);
1084
1101
  const speed = driver?.state.u ?? 0;
1085
1102
  lastSpeed = speed;
@@ -1132,6 +1149,7 @@ var GameVehiclesDriving = (() => {
1132
1149
  release() {
1133
1150
  held.clear();
1134
1151
  throttle = brake = steer = 0;
1152
+ state.comm.talking = false;
1135
1153
  state.horn = false;
1136
1154
  state.lamps.flash = false;
1137
1155
  state.washer = false;