@needle-tools/engine 4.4.2 → 4.4.3-beta

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.
@@ -671,15 +671,30 @@ export class Input implements IInput {
671
671
  }
672
672
 
673
673
 
674
-
675
- getKeyDown(): string | null {
674
+ /** Get a key (if any) that was just pressed this frame (this is only true for the frame it was pressed down) */
675
+ getKeyDown(): string | null;
676
+ /** Get true or false if the given key was pressed this frame */
677
+ getKeyDown(key: KeyCode | ({} & string)): boolean;
678
+ getKeyDown(key?: KeyCode | ({} & string)): boolean | string | null {
679
+ // If a key is provided check if it was pressed this frame
680
+ if (key !== undefined) {
681
+ return this.isKeyDown(key);
682
+ }
683
+ // If no key was provided get the first key that was pressed this frame
676
684
  for (const key in this.keysPressed) {
677
685
  const k = this.keysPressed[key];
678
686
  if (k.startFrame === this.context.time.frameCount) return k.key;
679
687
  }
680
688
  return null;
681
689
  }
682
- getKeyPressed(): string | null {
690
+ /** Get a key (if any) that is currently being pressed (held down) */
691
+ getKeyPressed(): string | null;
692
+ /** Get true or false if the given key is pressed */
693
+ getKeyPressed(key: KeyCode | ({} & string)): boolean
694
+ getKeyPressed(key?: KeyCode | ({} & string)): boolean | string | null {
695
+ if (key !== undefined) {
696
+ return this.isKeyPressed(key);
697
+ }
683
698
  for (const key in this.keysPressed) {
684
699
  const k = this.keysPressed[key];
685
700
  if (k.pressed)
@@ -687,6 +702,25 @@ export class Input implements IInput {
687
702
  }
688
703
  return null;
689
704
  }
705
+
706
+ /** Get a key (if any) that was released in this frame */
707
+ getKeyUp(): string | null;
708
+ /** Get true or false if the given key was released this frame */
709
+ getKeyUp(key: KeyCode | ({} & string)): boolean;
710
+ getKeyUp(key?: KeyCode | ({} & string)): boolean | string | null {
711
+
712
+ if (key !== undefined) {
713
+ return this.isKeyUp(key);
714
+ }
715
+ for (const key in this.keysPressed) {
716
+ const k = this.keysPressed[key];
717
+ if (k.pressed === false && k.frame === this.context.time.frameCount) return true;
718
+ return false;
719
+ }
720
+
721
+ return null;
722
+ }
723
+
690
724
  isKeyDown(keyCode: KeyCode | ({} & string)) {
691
725
  if (!this.context.application.isVisible || !this.context.application.hasFocus) return false;
692
726
  const codes = this.getCodeForCommonKeyName(keyCode);
@@ -694,7 +728,9 @@ export class Input implements IInput {
694
728
  for (const code of codes) if (this.isKeyDown(code)) return true;
695
729
  return false;
696
730
  }
697
- return this.keysPressed[keyCode]?.startFrame === this.context.time.frameCount && this.keysPressed[keyCode].pressed;
731
+ const k = this.keysPressed[keyCode];
732
+ if (!k) return false;
733
+ return k.startFrame === this.context.time.frameCount && k.pressed;
698
734
  }
699
735
  isKeyUp(keyCode: KeyCode | ({} & string)) {
700
736
  if (!this.context.application.isVisible || !this.context.application.hasFocus) return false;
@@ -703,16 +739,20 @@ export class Input implements IInput {
703
739
  for (const code of codes) if (this.isKeyUp(code)) return true;
704
740
  return false;
705
741
  }
706
- return this.keysPressed[keyCode]?.frame === this.context.time.frameCount && !this.keysPressed[keyCode].pressed;
742
+ const k = this.keysPressed[keyCode];
743
+ if (!k) return false;
744
+ return k.frame === this.context.time.frameCount && k.pressed === false;
707
745
  }
708
- isKeyPressed(keyCode: KeyCode | ({} & string)) {
746
+ isKeyPressed(keyCode: KeyCode | ({} & string)): boolean {
709
747
  if (!this.context.application.isVisible || !this.context.application.hasFocus) return false;
710
748
  const codes = this.getCodeForCommonKeyName(keyCode);
711
749
  if (codes !== null) {
712
750
  for (const code of codes) if (this.isKeyPressed(code)) return true;
713
751
  return false;
714
752
  }
715
- return this.keysPressed[keyCode]?.pressed;// && time.frameCount - this.keysPressed[keyCode].frame < 100;
753
+ const k = this.keysPressed[keyCode];
754
+ if (!k) return false;
755
+ return k.pressed || false;
716
756
  }
717
757
 
718
758
  // utility helper for mapping common names to actual codes; e.g. "Shift" -> "ShiftLeft" and "ShiftRight" or "a" -> "KeyA"
@@ -232,7 +232,7 @@ function insertNonCommercialUseHint(ctx: IContext) {
232
232
  padding-left: 30px;
233
233
  `;
234
234
  if (NEEDLE_ENGINE_LICENSE_TYPE === "edu") {
235
- console.log("%c " + "Supported by Needle for Education – https://needle.tools", style);
235
+ console.log("%c " + "This project is supported by Needle for Education – https://needle.tools", style);
236
236
  }
237
237
  else {
238
238
  // if the user has a basic license we already show the logo in the menu and log a license message
@@ -321,7 +321,7 @@ export class SyncedTransform extends Behaviour {
321
321
 
322
322
  if (this._model && !this._model.hasOwnership && this._model.isOwned) {
323
323
  if (this._receivedDataBefore) {
324
- const t = this._receivedFastUpdate || this.fastMode ? .05 : .3;
324
+ const t = this._receivedFastUpdate || this.fastMode ? .5 : .3;
325
325
  let requireMarkDirty = false;
326
326
  if (this.interpolatePosition && this._targetPosition) {
327
327
  const pos = this.worldPosition;