Преглед на файлове

detachControl Backcompat

Raanan Weber преди 4 години
родител
ревизия
1201e612af

+ 7 - 1
src/Cameras/Inputs/BaseCameraMouseWheelInput.ts

@@ -99,7 +99,13 @@ export abstract class BaseCameraMouseWheelInput implements ICameraInput<Camera>
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._observer) {
             this.camera.getScene().onPointerObservable.remove(this._observer);
             this._observer = null;

+ 7 - 1
src/Cameras/Inputs/BaseCameraPointersInput.ts

@@ -242,7 +242,13 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._onLostFocus) {
             let hostWindow = this.camera.getScene().getEngine().getHostWindow();
             if (hostWindow) {

+ 7 - 2
src/Cameras/Inputs/arcRotateCameraGamepadInput.ts

@@ -74,9 +74,14 @@ export class ArcRotateCameraGamepadInput implements ICameraInput<ArcRotateCamera
 
     /**
      * Detach the current controls from the specified dom element.
-     * @param element Defines the element to stop listening the inputs from
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);
         this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);
         this.gamepad = null;

+ 7 - 1
src/Cameras/Inputs/arcRotateCameraKeyboardMoveInput.ts

@@ -145,7 +145,13 @@ export class ArcRotateCameraKeyboardMoveInput implements ICameraInput<ArcRotateC
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl() {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._scene) {
             if (this._onKeyboardObserver) {
                 this._scene.onKeyboardObservable.remove(this._onKeyboardObserver);

+ 7 - 1
src/Cameras/Inputs/arcRotateCameraMouseWheelInput.ts

@@ -101,7 +101,13 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._observer) {
             this.camera.getScene().onPointerObservable.remove(this._observer);
             this._observer = null;

+ 7 - 1
src/Cameras/Inputs/arcRotateCameraVRDeviceOrientationInput.ts

@@ -119,7 +119,13 @@ export class ArcRotateCameraVRDeviceOrientationInput implements ICameraInput<Arc
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
     }
 

+ 7 - 1
src/Cameras/Inputs/flyCameraKeyboardInput.ts

@@ -120,7 +120,13 @@ export class FlyCameraKeyboardInput implements ICameraInput<FlyCamera> {
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._scene) {
             if (this._onKeyboardObserver) {
                 this._scene.onKeyboardObservable.remove(this._onKeyboardObserver);

+ 7 - 1
src/Cameras/Inputs/flyCameraMouseInput.ts

@@ -102,7 +102,13 @@ export class FlyCameraMouseInput implements ICameraInput<FlyCamera> {
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._observer) {
             this.camera.getScene().onPointerObservable.remove(this._observer);
 

+ 7 - 1
src/Cameras/Inputs/followCameraKeyboardMoveInput.ts

@@ -205,7 +205,13 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl() {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._scene) {
             if (this._onKeyboardObserver) {
                 this._scene.onKeyboardObservable.remove(this._onKeyboardObserver);

+ 7 - 1
src/Cameras/Inputs/followCameraMouseWheelInput.ts

@@ -119,7 +119,13 @@ export class FollowCameraMouseWheelInput implements ICameraInput<FollowCamera> {
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._observer) {
             this.camera.getScene().onPointerObservable.remove(this._observer);
             this._observer = null;

+ 24 - 16
src/Cameras/Inputs/freeCameraDeviceOrientationInput.ts

@@ -4,7 +4,7 @@ import { FreeCamera } from "../../Cameras/freeCamera";
 import { Quaternion } from "../../Maths/math.vector";
 import { Tools } from "../../Misc/tools";
 import { FreeCameraInputsManager } from "../../Cameras/freeCameraInputsManager";
-import { Observable } from '../../Misc/observable';
+import { Observable } from "../../Misc/observable";
 
 // Module augmentation to abstract orientation inputs from camera.
 declare module "../../Cameras/freeCameraInputsManager" {
@@ -25,7 +25,7 @@ declare module "../../Cameras/freeCameraInputsManager" {
  * Add orientation input support to the input manager.
  * @returns the current input manager
  */
-FreeCameraInputsManager.prototype.addDeviceOrientation = function(): FreeCameraInputsManager {
+FreeCameraInputsManager.prototype.addDeviceOrientation = function (): FreeCameraInputsManager {
     if (!this._deviceOrientationInput) {
         this._deviceOrientationInput = new FreeCameraDeviceOrientationInput();
         this.add(this._deviceOrientationInput);
@@ -75,10 +75,11 @@ export class FreeCameraDeviceOrientationInput implements ICameraInput<FreeCamera
                 }, timeout);
             }
 
-            if (typeof(DeviceOrientationEvent) !== "undefined" && typeof (<any>DeviceOrientationEvent).requestPermission === 'function') {
-                (<any>DeviceOrientationEvent).requestPermission()
+            if (typeof DeviceOrientationEvent !== "undefined" && typeof (<any>DeviceOrientationEvent).requestPermission === "function") {
+                (<any>DeviceOrientationEvent)
+                    .requestPermission()
                     .then((response: string) => {
-                        if (response == 'granted') {
+                        if (response == "granted") {
                             window.addEventListener("deviceorientation", eventHandler);
                         } else {
                             Tools.Warn("Permission not granted.");
@@ -102,7 +103,7 @@ export class FreeCameraDeviceOrientationInput implements ICameraInput<FreeCamera
      * @see https://doc.babylonjs.com/how_to/customizing_camera_inputs
      */
     constructor() {
-        this._constantTranform = new Quaternion(- Math.sqrt(0.5), 0, 0, Math.sqrt(0.5));
+        this._constantTranform = new Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5));
         this._orientationChanged();
     }
 
@@ -129,11 +130,9 @@ export class FreeCameraDeviceOrientationInput implements ICameraInput<FreeCamera
      * Attach the input controls to a specific dom element to get the input from.
      */
     public attachControl(): void {
-
         let hostWindow = this.camera.getScene().getEngine().getHostWindow();
 
         if (hostWindow) {
-
             const eventHandler = () => {
                 hostWindow!.addEventListener("orientationchange", this._orientationChanged);
                 hostWindow!.addEventListener("deviceorientation", this._deviceOrientation);
@@ -141,10 +140,11 @@ export class FreeCameraDeviceOrientationInput implements ICameraInput<FreeCamera
                 //So this is needed.
                 this._orientationChanged();
             };
-            if (typeof(DeviceOrientationEvent) !== "undefined" && typeof (<any>DeviceOrientationEvent).requestPermission === 'function') {
-                (<any>DeviceOrientationEvent).requestPermission()
+            if (typeof DeviceOrientationEvent !== "undefined" && typeof (<any>DeviceOrientationEvent).requestPermission === "function") {
+                (<any>DeviceOrientationEvent)
+                    .requestPermission()
                     .then((response: string) => {
-                        if (response === 'granted') {
+                        if (response === "granted") {
                             eventHandler();
                         } else {
                             Tools.Warn("Permission not granted.");
@@ -160,10 +160,10 @@ export class FreeCameraDeviceOrientationInput implements ICameraInput<FreeCamera
     }
 
     private _orientationChanged = () => {
-        this._screenOrientationAngle = (<any>window.orientation !== undefined ? +<any>window.orientation : ((<any>window.screen).orientation && ((<any>window.screen).orientation)['angle'] ? ((<any>window.screen).orientation).angle : 0));
+        this._screenOrientationAngle = <any>window.orientation !== undefined ? +(<any>window.orientation) : (<any>window.screen).orientation && (<any>window.screen).orientation["angle"] ? (<any>window.screen).orientation.angle : 0;
         this._screenOrientationAngle = -Tools.ToRadians(this._screenOrientationAngle / 2);
         this._screenQuaternion.copyFromFloats(0, Math.sin(this._screenOrientationAngle), 0, Math.cos(this._screenOrientationAngle));
-    }
+    };
 
     private _deviceOrientation = (evt: DeviceOrientationEvent) => {
         this._alpha = evt.alpha !== null ? evt.alpha : 0;
@@ -172,12 +172,18 @@ export class FreeCameraDeviceOrientationInput implements ICameraInput<FreeCamera
         if (evt.alpha !== null) {
             this._onDeviceOrientationChangedObservable.notifyObservers();
         }
-    }
+    };
 
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         window.removeEventListener("orientationchange", this._orientationChanged);
         window.removeEventListener("deviceorientation", this._deviceOrientation);
         this._alpha = 0;
@@ -190,7 +196,9 @@ export class FreeCameraDeviceOrientationInput implements ICameraInput<FreeCamera
     public checkInputs(): void {
         //if no device orientation provided, don't update the rotation.
         //Only testing against alpha under the assumption thatnorientation will never be so exact when set.
-        if (!this._alpha) { return; }
+        if (!this._alpha) {
+            return;
+        }
         Quaternion.RotationYawPitchRollToRef(Tools.ToRadians(this._alpha), Tools.ToRadians(this._beta), -Tools.ToRadians(this._gamma), this.camera.rotationQuaternion);
         this._camera.rotationQuaternion.multiplyInPlace(this._screenQuaternion);
         this._camera.rotationQuaternion.multiplyInPlace(this._constantTranform);

+ 7 - 1
src/Cameras/Inputs/freeCameraGamepadInput.ts

@@ -87,7 +87,13 @@ export class FreeCameraGamepadInput implements ICameraInput<FreeCamera> {
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);
         this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);
         this.gamepad = null;

+ 10 - 14
src/Cameras/Inputs/freeCameraKeyboardMoveInput.ts

@@ -7,7 +7,7 @@ import { KeyboardInfo, KeyboardEventTypes } from "../../Events/keyboardEvents";
 import { Scene } from "../../scene";
 import { Vector3 } from "../../Maths/math.vector";
 import { Engine } from "../../Engines/engine";
-import { Tools } from '../../Misc/tools';
+import { Tools } from "../../Misc/tools";
 /**
  * Manage the keyboard inputs to control the movement of a free camera.
  * @see https://doc.babylonjs.com/how_to/customizing_camera_inputs
@@ -81,12 +81,7 @@ export class FreeCameraKeyboardMoveInput implements ICameraInput<FreeCamera> {
             let evt = info.event;
             if (!evt.metaKey) {
                 if (info.type === KeyboardEventTypes.KEYDOWN) {
-                    if (this.keysUp.indexOf(evt.keyCode) !== -1 ||
-                        this.keysDown.indexOf(evt.keyCode) !== -1 ||
-                        this.keysLeft.indexOf(evt.keyCode) !== -1 ||
-                        this.keysRight.indexOf(evt.keyCode) !== -1 ||
-                        this.keysUpward.indexOf(evt.keyCode) !== -1 ||
-                        this.keysDownward.indexOf(evt.keyCode) !== -1) {
+                    if (this.keysUp.indexOf(evt.keyCode) !== -1 || this.keysDown.indexOf(evt.keyCode) !== -1 || this.keysLeft.indexOf(evt.keyCode) !== -1 || this.keysRight.indexOf(evt.keyCode) !== -1 || this.keysUpward.indexOf(evt.keyCode) !== -1 || this.keysDownward.indexOf(evt.keyCode) !== -1) {
                         var index = this._keys.indexOf(evt.keyCode);
 
                         if (index === -1) {
@@ -97,12 +92,7 @@ export class FreeCameraKeyboardMoveInput implements ICameraInput<FreeCamera> {
                         }
                     }
                 } else {
-                    if (this.keysUp.indexOf(evt.keyCode) !== -1 ||
-                        this.keysDown.indexOf(evt.keyCode) !== -1 ||
-                        this.keysLeft.indexOf(evt.keyCode) !== -1 ||
-                        this.keysRight.indexOf(evt.keyCode) !== -1 ||
-                        this.keysUpward.indexOf(evt.keyCode) !== -1 ||
-                        this.keysDownward.indexOf(evt.keyCode) !== -1) {
+                    if (this.keysUp.indexOf(evt.keyCode) !== -1 || this.keysDown.indexOf(evt.keyCode) !== -1 || this.keysLeft.indexOf(evt.keyCode) !== -1 || this.keysRight.indexOf(evt.keyCode) !== -1 || this.keysUpward.indexOf(evt.keyCode) !== -1 || this.keysDownward.indexOf(evt.keyCode) !== -1) {
                         var index = this._keys.indexOf(evt.keyCode);
 
                         if (index >= 0) {
@@ -120,7 +110,13 @@ export class FreeCameraKeyboardMoveInput implements ICameraInput<FreeCamera> {
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._scene) {
             if (this._onKeyboardObserver) {
                 this._scene.onKeyboardObservable.remove(this._onKeyboardObserver);

+ 7 - 1
src/Cameras/Inputs/freeCameraMouseInput.ts

@@ -192,7 +192,13 @@ export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._observer) {
             this.camera.getScene().onPointerObservable.remove(this._observer);
 

+ 7 - 2
src/Cameras/Inputs/freeCameraTouchInput.ts

@@ -137,9 +137,14 @@ export class FreeCameraTouchInput implements ICameraInput<FreeCamera> {
 
     /**
      * Detach the current controls from the specified dom element.
-     * @param element Defines the element to stop listening the inputs from
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         if (this._pointerInput) {
             if (this._observer) {
                 this.camera.getScene().onPointerObservable.remove(this._observer);

+ 7 - 1
src/Cameras/Inputs/freeCameraVirtualJoystickInput.ts

@@ -94,7 +94,13 @@ export class FreeCameraVirtualJoystickInput implements ICameraInput<FreeCamera>
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         this._leftjoystick.releaseCanvas();
         this._rightjoystick.releaseCanvas();
     }

+ 8 - 2
src/Cameras/VR/webVRCamera.ts

@@ -516,9 +516,15 @@ export class WebVRFreeCamera extends FreeCamera implements PoseControlled {
     }
 
     /**
-     * Detaches the camera from the html element and disables VR
+     * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         this.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);
         this.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);
 

+ 7 - 1
src/Cameras/camera.ts

@@ -537,7 +537,13 @@ export class Camera extends Node {
     /**
      * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
     }
 
     /**

+ 8 - 3
src/Cameras/followCamera.ts

@@ -179,10 +179,15 @@ export class FollowCamera extends TargetCamera {
     }
 
     /**
-     * Detach the current controls from the camera.
-     * The camera will stop reacting to inputs.
+     * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         this.inputs.detachElement();
 
         if (this._reset) {

+ 8 - 3
src/Cameras/freeCamera.ts

@@ -231,10 +231,15 @@ export class FreeCamera extends TargetCamera {
     }
 
     /**
-     * Detach the current controls from the camera.
-     * The camera will stop reacting to inputs.
+     * Detach the current controls from the specified dom element.
      */
-    public detachControl(): void {
+    public detachControl(): void;
+
+    /**
+     * Detach the current controls from the specified dom element.
+     * @param ignored defines an ignored parameter kept for backward compatibility. If you want to define the source input element, you can set engine.inputElement before calling camera.attachControl
+     */
+    public detachControl(ignored?: any): void {
         this.inputs.detachElement();
 
         this.cameraDirection = new Vector3(0, 0, 0);