Kacey Coley 7 vuotta sitten
vanhempi
commit
67383d3913
2 muutettua tiedostoa jossa 112 lisäystä ja 2 poistoa
  1. 88 2
      src/Gamepad/babylon.gamepad.ts
  2. 24 0
      src/Gamepad/babylon.gamepadManager.ts

+ 88 - 2
src/Gamepad/babylon.gamepad.ts

@@ -1,18 +1,56 @@
 module BABYLON {
+    /**
+     * Represents a gamepad control stick position
+     */
     export class StickValues {
-        constructor(public x: number, public y: number) {
+        /**
+         * Initializes the gamepad x and y control stick values
+         * @param x The x component of the gamepad control stick value
+         * @param y The y component of the gamepad control stick value
+         */
+        constructor(
+            /**
+             * The x component of the control stick
+             */
+            public x: number, 
+            /**
+             * The y component of the control stick
+             */
+            public y: number
+        ) {
         }
     }
 
+    /**
+     * An interface which manages callbacks for gamepad button changes
+     */
     export interface GamepadButtonChanges {
+        /**
+         * Called when a gamepad has been changed
+         */
         changed: boolean;
+        /**
+         * Called when a gamepad press event has been triggered
+         */
         pressChanged: boolean;
+        /**
+         * Called when a touch event has been triggered
+         */
         touchChanged: boolean;
+        /**
+         * Called when a value has changed
+         */
         valueChanged: boolean;
     }
 
+    /**
+     * Represents a gamepad
+     */
     export class Gamepad {
 
+        /**
+         * Specifies what type of gamepad this represents
+         */
         public type: number;
 
         private _leftStick: StickValues = { x: 0, y: 0 };
@@ -26,21 +64,69 @@
         private _rightStickAxisX: number;
         private _rightStickAxisY: number;
 
+        /**
+         * Triggered when the left control stick has been changed
+         */
         private _onleftstickchanged: (values: StickValues) => void;
+
+        /**
+         * Triggered when the right control stick has been changed
+         */
         private _onrightstickchanged: (values: StickValues) => void;
 
+        /**
+         * Represents a gamepad controller
+         */
         public static GAMEPAD = 0;
+        /**
+         * Represents a generic controller
+         */
         public static GENERIC = 1;
+        /**
+         * Represents an XBox controller
+         */
         public static XBOX = 2;
+        /**
+         * Represents a pose-enabled controller
+         */
         public static POSE_ENABLED = 3;
 
+        /**
+         * Specifies whether the left control stick should be Y-inverted
+         */
         protected _invertLeftStickY: boolean = false;
 
+        /**
+         * Specifies if the gamepad has been connected
+         */
         public get isConnected(): boolean {
             return this._isConnected;
         }
 
-        constructor(public id: string, public index: number, public browserGamepad: any, leftStickX: number = 0, leftStickY: number = 1, rightStickX: number = 2, rightStickY: number = 3) {
+        /**
+         * Initializes the gamepad
+         * @param id The id of the gamepad
+         * @param index The index of the gamepad
+         * @param browserGamepad The browser gamepad
+         * @param leftStickX The x component of the left joystick
+         * @param leftStickY The y component of the left joystick
+         * @param rightStickX The x component of the right joystick
+         * @param rightStickY The y component of the right joystick
+         */
+        constructor(
+            /**
+             * The id of the gamepad
+             */
+            public id: string, 
+            /**
+             * The index of the gamepad
+             */
+            public index: number, 
+            /**
+             * The browser gamepad
+             */
+            public browserGamepad: any, 
+            leftStickX: number = 0, leftStickY: number = 1, rightStickX: number = 2, rightStickY: number = 3) {
             this.type = Gamepad.GAMEPAD;
             this._leftStickAxisX = leftStickX;
             this._leftStickAxisY = leftStickY;

+ 24 - 0
src/Gamepad/babylon.gamepadManager.ts

@@ -1,4 +1,7 @@
 module BABYLON {
+    /**
+     * Manager for handling gamepads
+     */
     export class GamepadManager {
         private _babylonGamepads: Array<Gamepad> = [];
         private _oneGamepadConnected: boolean = false;
@@ -8,12 +11,23 @@
         private _gamepadEventSupported: boolean;
         private _gamepadSupport: () => Array<any>;
 
+        /**
+         * observable to be triggered when the gamepad controller has been connected
+         */
         public onGamepadConnectedObservable: Observable<Gamepad>;
+
+        /**
+         * observable to be triggered when the gamepad controller has been disconnected
+         */
         public onGamepadDisconnectedObservable = new Observable<Gamepad>();
 
         private _onGamepadConnectedEvent: Nullable<(evt: any) => void>;
         private _onGamepadDisconnectedEvent: Nullable<(evt: any) => void>;
 
+        /**
+         * Initializes the gamepad manager
+         * @param _scene BabylonJS scene
+         */
         constructor(private _scene?: Scene) {
             if (!Tools.IsWindowObjectExist()) {
                 this._gamepadEventSupported = false;
@@ -87,10 +101,17 @@
             }
         }
 
+        /**
+         * The gamepads in the game pad manager
+         */
         public get gamepads(): Gamepad[] {
             return this._babylonGamepads;
         }
 
+        /**
+         * Get the gamepad controllers based on type
+         * @param type The type of gamepad controller
+         */
         public getGamepadByType(type: number = Gamepad.XBOX): Nullable<Gamepad> {
             for (var gamepad of this._babylonGamepads) {
                 if (gamepad && gamepad.type === type) {
@@ -101,6 +122,9 @@
             return null;
         }
 
+        /**
+         * Disposes the gamepad manager
+         */
         public dispose() {
             if (this._gamepadEventSupported) {
                 if (this._onGamepadConnectedEvent) {