浏览代码

All feedback but touch

Dave Solares 5 年之前
父节点
当前提交
0deaf4c5dd
共有 2 个文件被更改,包括 121 次插入162 次删除
  1. 27 88
      src/DeviceInput/InputDevices/deviceSourceManager.ts
  2. 94 74
      src/DeviceInput/deviceInputSystem.ts

+ 27 - 88
src/DeviceInput/InputDevices/deviceSourceManager.ts

@@ -1,4 +1,4 @@
-import { DeviceInputSystem, POINTER_DEVICE, KEYBOARD_DEVICE, MOUSE_DEVICE } from '../deviceInputSystem';
+import { DeviceInputSystem } from '../deviceInputSystem';
 import { Engine } from '../../Engines/engine';
 import { IDisposable } from '../../scene';
 import { DeviceType } from './deviceEnums';
@@ -13,9 +13,9 @@ export class DeviceSource<T extends DeviceType> {
     /**
      * Observable to handle device input changes per device
      */
-    public readonly onInputChangedObservable = new Observable<{ inputIndex: DeviceInput<T>, previousState: Nullable<number>, currentState: Nullable<number> }>();
+    public readonly onInputChangedObservable = new Observable<{ inputIndex: number, previousState: Nullable<number>, currentState: Nullable<number> }>();
     private readonly _deviceInputSystem: DeviceInputSystem;
-    private _touchPoints: Array<string>;
+    private _touchPoints: Array<number>;
 
     /**
      * Default Constructor
@@ -25,8 +25,6 @@ export class DeviceSource<T extends DeviceType> {
      * @param deviceSlot "Slot" or index that device is referenced in
      */
     constructor(deviceInputSystem: DeviceInputSystem,
-        /** Name of device to be used by DeviceInputSystem */
-        public readonly deviceName: string,
         /** Type of device */
         public readonly deviceType: DeviceType,
         /** "Slot" or index that device is referenced in */
@@ -34,7 +32,7 @@ export class DeviceSource<T extends DeviceType> {
         this._deviceInputSystem = deviceInputSystem;
 
         if (deviceType == DeviceType.Touch) {
-            this._touchPoints = new Array<string>();
+            this._touchPoints = new Array<number>();
         }
     }
 
@@ -45,19 +43,19 @@ export class DeviceSource<T extends DeviceType> {
      */
     public getInput(inputIndex: DeviceInput<T>): Nullable<number> {
         if (this.deviceType == DeviceType.Touch) {
-            return this._deviceInputSystem.pollInput(this._touchPoints[this.deviceSlot], inputIndex);
+            return this._deviceInputSystem.pollInput(this.deviceType, this._touchPoints[this.deviceSlot], inputIndex);
         }
 
-        return this._deviceInputSystem.pollInput(this.deviceName, inputIndex);
+        return this._deviceInputSystem.pollInput(this.deviceType, this.deviceSlot, inputIndex);
     }
 
     /**
      * Add specific point to array of touch points (DeviceType.Touch only)
      * @param name Name of Specific Touch Point
      */
-    public addTouchPoints(name: string) {
+    public addTouchPoints(slot: number) {
         if (this.deviceType == DeviceType.Touch) {
-            this._touchPoints.push(name);
+            this._touchPoints.push(slot);
         }
     }
 
@@ -65,9 +63,9 @@ export class DeviceSource<T extends DeviceType> {
      * Remove specific point from array of touch points (DeviceType.Touch only)
      * @param name Name of Specific Touch Point
      */
-    public removeTouchPoints(name: string) {
+    public removeTouchPoints(slot: number) {
         if (this.deviceType == DeviceType.Touch) {
-            const touchIndex = this._touchPoints.indexOf(name);
+            const touchIndex = this._touchPoints.indexOf(slot);
             this._touchPoints.splice(touchIndex, 1);
         }
     }
@@ -114,31 +112,20 @@ export class DeviceSourceManager implements IDisposable {
         this._firstDevice = new Array<number>(numberOfDeviceTypes);
         this._deviceInputSystem = new DeviceInputSystem(engine);
 
-        this._deviceInputSystem.onDeviceConnected = (deviceName) => {
-            const deviceType = this._getDeviceType(deviceName);
-            const deviceSlot = this._getDeviceSlot(deviceName);
-
+        this._deviceInputSystem.onDeviceConnected = (deviceType, deviceSlot) => {
             this.onBeforeDeviceConnectedObservable.notifyObservers({ deviceType, deviceSlot });
-            this._addDevice(deviceName);
+            this._addDevice(deviceType, deviceSlot);
             this.onAfterDeviceConnectedObservable.notifyObservers({ deviceType, deviceSlot });
         };
-        this._deviceInputSystem.onDeviceDisconnected = (deviceName) => {
-            const deviceType = this._getDeviceType(deviceName);
-            const deviceSlot = this._getDeviceSlot(deviceName);
-
+        this._deviceInputSystem.onDeviceDisconnected = (deviceType, deviceSlot) => {
             this.onBeforeDeviceDisconnectedObservable.notifyObservers({ deviceType, deviceSlot });
-            this._removeDevice(deviceName);
+            this._removeDevice(deviceType, deviceSlot);
             this.onAfterDeviceDisconnectedObservable.notifyObservers({ deviceType, deviceSlot });
         };
 
         if (!this._deviceInputSystem.onInputChanged && enableObserveEvents) {
-            this._deviceInputSystem.onInputChanged = (deviceName, inputIndex, previousState, currentState) => {
-                const deviceType = this._getDeviceType(deviceName);
-                const deviceSlot = this._getDeviceSlot(deviceName);
-
-                if (deviceType == DeviceType.Keyboard || deviceType == DeviceType.Mouse || deviceType == DeviceType.Touch) {
-                    this.getDeviceSource(deviceType, deviceSlot)?.onInputChangedObservable.notifyObservers({ inputIndex, previousState, currentState });
-                }
+            this._deviceInputSystem.onInputChanged = (deviceType, deviceSlot, inputIndex, previousState, currentState) => {
+                this.getDeviceSource(deviceType, deviceSlot)?.onInputChangedObservable.notifyObservers({ inputIndex, previousState, currentState });
             };
         }
     }
@@ -150,7 +137,7 @@ export class DeviceSourceManager implements IDisposable {
      * @param deviceSlot "Slot" or index that device is referenced in
      * @returns DeviceSource object
      */
-    public getDeviceSource<T extends DeviceType>(deviceType: T, deviceSlot: number = this._firstDevice[deviceType]): Nullable<DeviceSource<T>> {
+    public getDeviceSource<T extends DeviceType>(deviceType: DeviceType, deviceSlot: number = this._firstDevice[deviceType]): Nullable<DeviceSource<T>> {
         if (!this._devices[deviceType] || this._firstDevice[deviceType] === undefined || this._devices[deviceType][deviceSlot] === undefined) {
             return null;
         }
@@ -163,7 +150,7 @@ export class DeviceSourceManager implements IDisposable {
      * @param deviceType Enum specifiying device type
      * @returns Array of DeviceSource objects
      */
-    public getDeviceSources<T extends DeviceType>(deviceType: T): ReadonlyArray<DeviceSource<T>> {
+    public getDeviceSources<T extends DeviceType>(deviceType: DeviceType): ReadonlyArray<DeviceSource<T>> {
         return this._devices[deviceType];
     }
 
@@ -179,24 +166,21 @@ export class DeviceSourceManager implements IDisposable {
      * Function to add device name to device list
      * @param deviceName Name of Device
      */
-    private _addDevice(deviceName: string) {
-        const deviceSlot = this._getDeviceSlot(deviceName);
-        const deviceType = this._getDeviceType(deviceName);
-
+    private _addDevice<T extends DeviceType>(deviceType: DeviceType, deviceSlot: number) {
         if (!this._devices[deviceType]) {
-            this._devices[deviceType] = new Array<DeviceSource<DeviceType>>();
+            this._devices[deviceType] = new Array<DeviceSource<T>>();
 
             if (deviceType == DeviceType.Touch) {
-                this._devices[deviceType][0] = new DeviceSource<DeviceType>(this._deviceInputSystem, POINTER_DEVICE, DeviceType.Touch, 0);
+                this._devices[deviceType][0] = new DeviceSource<T>(this._deviceInputSystem, deviceType, 0);
             }
         }
 
         // If device is a touch device, update only touch points.  Otherwise, add new device.
         if (deviceType == DeviceType.Touch) {
-            this._devices[deviceType][0].addTouchPoints(deviceName);
+            this._devices[deviceType][0].addTouchPoints(deviceSlot);
         }
         else {
-            this._devices[deviceType][deviceSlot] = new DeviceSource<DeviceType>(this._deviceInputSystem, deviceName, deviceType, deviceSlot);
+            this._devices[deviceType][deviceSlot] = new DeviceSource(this._deviceInputSystem, deviceType, deviceSlot);
         }
 
         this._updateFirstDevices(deviceType);
@@ -206,35 +190,17 @@ export class DeviceSourceManager implements IDisposable {
      * Function to remove device name to device list
      * @param deviceName Name of Device
      */
-    private _removeDevice(deviceName: string) {
-        const deviceSlot = this._getDeviceSlot(deviceName);
-        const deviceType = this._getDeviceType(deviceName);
-
+    private _removeDevice(deviceType: DeviceType, deviceSlot: number) {
         if (deviceType == DeviceType.Touch) {
-            this._devices[deviceType][0].removeTouchPoints(deviceName);
+            this._devices[deviceType][0].removeTouchPoints(deviceSlot);
         }
         else {
             delete this._devices[deviceType][deviceSlot];
+            this._updateFirstDevices(deviceType);
         }
     }
 
     /**
-     * Get slot for a given input
-     * @param deviceName Name of Device
-     * @returns Slot Number
-     */
-    private _getDeviceSlot(deviceName: string): number {
-        const splitName = deviceName.split("-");
-        const deviceSlot = parseInt(splitName[splitName.length - 1]);
-
-        if (deviceSlot) {
-            return deviceSlot;
-        }
-
-        return 0;
-    }
-
-    /**
      * Updates array storing first connected device of each type
      * @param type Type of Device
      */
@@ -250,6 +216,7 @@ export class DeviceSourceManager implements IDisposable {
             case DeviceType.Switch:
             case DeviceType.Generic:
                 const devices = this._devices[type];
+                delete this._firstDevice[type];
                 for (let i = 0; i < devices.length; i++) {
                     if (devices[i]) {
                         this._firstDevice[type] = i;
@@ -259,32 +226,4 @@ export class DeviceSourceManager implements IDisposable {
                 break;
         }
     }
-
-    /**
-     * Gets DeviceType from the device name
-     * @param deviceName Name of Device from DeviceInputSystem
-     * @returns DeviceType enum value
-     */
-    private _getDeviceType(deviceName: string): DeviceType {
-        if (deviceName == KEYBOARD_DEVICE) {
-            return DeviceType.Keyboard;
-        }
-        else if (deviceName == MOUSE_DEVICE) {
-            return DeviceType.Mouse;
-        }
-        else if (deviceName.indexOf(POINTER_DEVICE) !== -1) {
-            return DeviceType.Touch;
-        }
-        else if (deviceName.indexOf("054c") !== -1) { // DualShock 4 Gamepad
-            return DeviceType.DualShock;
-        }
-        else if (deviceName.indexOf("Xbox One") !== -1 || deviceName.search("Xbox 360") !== -1 || deviceName.search("xinput") !== -1) { // Xbox Gamepad
-            return DeviceType.Xbox;
-        }
-        else if (deviceName.indexOf("057e") !== -1) { // Switch Gamepad
-            return DeviceType.Switch;
-        }
-
-        return DeviceType.Generic;
-    }
 }

+ 94 - 74
src/DeviceInput/deviceInputSystem.ts

@@ -1,22 +1,7 @@
 import { Engine } from '../Engines/engine';
 import { IDisposable } from '../scene';
 import { Nullable } from '../types';
-
-/**
- * POINTER_DEVICE
- * @hidden
- */
-export const POINTER_DEVICE: string = "Pointer";
-/**
- * KEYBOARD_DEVICE
- * @hidden
- */
-export const KEYBOARD_DEVICE: string = "Keyboard";
-/**
- * MOUSE_DEVICE
- * @hidden
- */
-export const MOUSE_DEVICE: string = "Mouse";
+import { DeviceType } from './InputDevices/deviceEnums';
 
 /**
  * This class will take all inputs from Keyboard, Pointer, and
@@ -28,21 +13,21 @@ export class DeviceInputSystem implements IDisposable {
     /**
      * Callback to be triggered when a device is connected
      */
-    public onDeviceConnected: (deviceName: string) => void;
+    public onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => void = () => {};
 
     /**
      * Callback to be triggered when a device is disconnected
      */
-    public onDeviceDisconnected: (deviceName: string) => void;
+    public onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => void = () => {};
 
     /**
      * Callback to be triggered when event driven input is updated
      */
-    public onInputChanged: (deviceName: string, inputIndex: number, previousState: Nullable<number>, currentState: Nullable<number>) => void;
+    public onInputChanged: (deviceType: DeviceType, deviceSlot: number, inputIndex: number, previousState: Nullable<number>, currentState: Nullable<number>) => void;
 
     // Private Members
-    private _inputs: { [key: string]: Array<Nullable<number>> } = {};
-    private _gamepads: Array<string>;
+    private _inputs: Array<Array<Array<Nullable<number>>>> = [];
+    private _gamepads: Array<DeviceType>;
     private _keyboardActive: boolean = false;
     private _pointerActive: boolean = false;
     private _elementToAttachTo: HTMLElement;
@@ -81,17 +66,17 @@ export class DeviceInputSystem implements IDisposable {
      * @param inputIndex Index of device input
      * @returns Current value of input
      */
-    public pollInput(deviceName: string, inputIndex: number): Nullable<number> {
-        const device = this._inputs[deviceName];
+    public pollInput(deviceType: DeviceType, deviceSlot: number, inputIndex: number): Nullable<number> {
+        const device = this._inputs[deviceType][deviceSlot];
 
         if (!device) {
-            return null;
+            throw `Unable to find device ${DeviceType[deviceType]}`;
         }
 
-        this._updateDevice(deviceName, inputIndex);
+        this._updateDevice(deviceType, deviceSlot, inputIndex);
 
         if (device[inputIndex] === undefined) {
-            throw `Unable to find input ${inputIndex} on device ${deviceName}`;
+            throw `Unable to find input ${inputIndex} for device ${DeviceType[deviceType]} in slot ${deviceSlot}`;
         }
 
         return device[inputIndex];
@@ -125,16 +110,20 @@ export class DeviceInputSystem implements IDisposable {
      * @param deviceName Assigned name of device (may be SN)
      * @param numberOfInputs Number of input entries to create for given device
      */
-    private _registerDevice(deviceName: string, numberOfInputs: number) {
-        if (!this._inputs[deviceName]) {
+    private _registerDevice(deviceType: DeviceType, deviceSlot: number, numberOfInputs: number) {
+        if (!this._inputs[deviceType]) {
+            this._inputs[deviceType] = [];
+        }
+
+        if (!this._inputs[deviceType][deviceSlot]) {
             const device = new Array<Nullable<number>>(numberOfInputs);
 
             for (let i = 0; i < numberOfInputs; i++) {
                 device[i] = null;
             }
 
-            this._inputs[deviceName] = device;
-            this.onDeviceConnected(deviceName);
+            this._inputs[deviceType][deviceSlot] = device;
+            this.onDeviceConnected(deviceType, deviceSlot);
         }
     }
 
@@ -142,10 +131,10 @@ export class DeviceInputSystem implements IDisposable {
      * Given a specific device name, remove that device from the device map
      * @param deviceName Name of device to be removed
      */
-    private _unregisterDevice(deviceName: string) {
-        if (this._inputs[deviceName]) {
-            delete this._inputs[deviceName];
-            this.onDeviceDisconnected(deviceName);
+    private _unregisterDevice(deviceType: DeviceType, deviceSlot: number) {
+        if (this._inputs[deviceType][deviceSlot]) {
+            delete this._inputs[deviceType][deviceSlot];
+            this.onDeviceDisconnected(deviceType, deviceSlot);
         }
     }
 
@@ -156,23 +145,23 @@ export class DeviceInputSystem implements IDisposable {
         this._keyboardDownEvent = ((evt) => {
             if (!this._keyboardActive) {
                 this._keyboardActive = true;
-                this._registerDevice(KEYBOARD_DEVICE, DeviceInputSystem._MAX_KEYCODES);
+                this._registerDevice(DeviceType.Keyboard, 0, DeviceInputSystem._MAX_KEYCODES);
             }
 
-            const kbKey = this._inputs[KEYBOARD_DEVICE];
+            const kbKey = this._inputs[DeviceType.Keyboard][0];
             if (kbKey) {
                 if (this.onInputChanged) {
-                    this.onInputChanged(KEYBOARD_DEVICE, evt.keyCode, kbKey[evt.keyCode], 1);
+                    this.onInputChanged(DeviceType.Keyboard, 0, evt.keyCode, kbKey[evt.keyCode], 1);
                 }
                 kbKey[evt.keyCode] = 1;
             }
         });
 
         this._keyboardUpEvent = ((evt) => {
-            const kbKey = this._inputs[KEYBOARD_DEVICE];
+            const kbKey = this._inputs[DeviceType.Keyboard][0];
             if (kbKey) {
                 if (this.onInputChanged) {
-                    this.onInputChanged(KEYBOARD_DEVICE, evt.keyCode, kbKey[evt.keyCode], 0);
+                    this.onInputChanged(DeviceType.Keyboard, 0, evt.keyCode, kbKey[evt.keyCode], 0);
                 }
                 kbKey[evt.keyCode] = 0;
             }
@@ -187,18 +176,23 @@ export class DeviceInputSystem implements IDisposable {
      */
     private _handlePointerActions() {
         this._pointerMoveEvent = ((evt) => {
-            const deviceName = (evt.pointerType == "mouse") ? MOUSE_DEVICE : `${POINTER_DEVICE}-${evt.pointerId}`;
+            const deviceType = (evt.pointerType == "mouse") ? DeviceType.Mouse : DeviceType.Touch;
+            const deviceSlot = (evt.pointerType == "mouse") ? 0 : evt.pointerId;
+            
+            if (!this._inputs[deviceType]) {
+                this._inputs[deviceType] = [];
+            }
 
-            if (!this._inputs[deviceName]) {
+            if (!this._inputs[deviceType][deviceSlot]) {
                 this._pointerActive = true;
-                this._registerDevice(deviceName, DeviceInputSystem._MAX_POINTER_INPUTS);
+                this._registerDevice(deviceType, deviceSlot, DeviceInputSystem._MAX_POINTER_INPUTS);
             }
 
-            const pointer = this._inputs[deviceName];
+            const pointer = this._inputs[deviceType][deviceSlot];
             if (pointer) {
                 if (this.onInputChanged) {
-                    this.onInputChanged(deviceName, 0, pointer[0], evt.clientX);
-                    this.onInputChanged(deviceName, 1, pointer[1], evt.clientY);
+                    this.onInputChanged(deviceType, deviceSlot, 0, pointer[0], evt.clientX);
+                    this.onInputChanged(deviceType, deviceSlot, 1, pointer[1], evt.clientY);
                 }
                 pointer[0] = evt.clientX;
                 pointer[1] = evt.clientY;
@@ -206,19 +200,24 @@ export class DeviceInputSystem implements IDisposable {
         });
 
         this._pointerDownEvent = ((evt) => {
+            const deviceType = (evt.pointerType == "mouse") ? DeviceType.Mouse : DeviceType.Touch;
+            const deviceSlot = (evt.pointerType == "mouse") ? 0 : evt.pointerId;
+
+            if (!this._inputs[deviceType]) {
+                this._inputs[deviceType] = [];
+            }
 
-            const deviceName = (evt.pointerType == "mouse") ? MOUSE_DEVICE : `${POINTER_DEVICE}-${evt.pointerId}`;
-            if (!this._inputs[deviceName]) {
+            if (!this._inputs[deviceType][deviceSlot]) {
                 this._pointerActive = true;
-                this._registerDevice(deviceName, DeviceInputSystem._MAX_POINTER_INPUTS);
+                this._registerDevice(deviceType, deviceSlot, DeviceInputSystem._MAX_POINTER_INPUTS);
             }
 
-            const pointer = this._inputs[deviceName];
+            const pointer = this._inputs[deviceType][deviceSlot];
             if (pointer) {
                 if (this.onInputChanged) {
-                    this.onInputChanged(deviceName, 0, pointer[0], evt.clientX);
-                    this.onInputChanged(deviceName, 1, pointer[1], evt.clientY);
-                    this.onInputChanged(deviceName, evt.button + 2, pointer[evt.button + 2], 1);
+                    this.onInputChanged(deviceType, deviceSlot, 0, pointer[0], evt.clientX);
+                    this.onInputChanged(deviceType, deviceSlot, 1, pointer[1], evt.clientY);
+                    this.onInputChanged(deviceType, deviceSlot, evt.button + 2, pointer[evt.button + 2], 1);
                 }
                 pointer[0] = evt.clientX;
                 pointer[1] = evt.clientY;
@@ -227,19 +226,20 @@ export class DeviceInputSystem implements IDisposable {
         });
 
         this._pointerUpEvent = ((evt) => {
-            const deviceName = (evt.pointerType == "mouse") ? MOUSE_DEVICE : `${POINTER_DEVICE}-${evt.pointerId}`;
+            const deviceType = (evt.pointerType == "mouse") ? DeviceType.Mouse : DeviceType.Touch;
+            const deviceSlot = (evt.pointerType == "mouse") ? 0 : evt.pointerId;
 
-            const pointer = this._inputs[deviceName];
+            const pointer = this._inputs[deviceType][deviceSlot];
             if (pointer) {
                 if (this.onInputChanged) {
-                    this.onInputChanged(deviceName, evt.button + 2, pointer[evt.button + 2], 0);
+                    this.onInputChanged(deviceType, deviceSlot, evt.button + 2, pointer[evt.button + 2], 0);
                 }
                 pointer[evt.button + 2] = 0;
             }
             // We don't want to unregister the mouse because we may miss input data when a mouse is moving after a click
             if (evt.pointerType != "mouse")
             {
-                this._unregisterDevice(deviceName);
+                this._unregisterDevice(deviceType, deviceSlot);
             }
 
         });
@@ -254,17 +254,21 @@ export class DeviceInputSystem implements IDisposable {
      */
     private _handleGamepadActions() {
         this._gamepadConnectedEvent = ((evt: any) => {
-            const deviceName = `${evt.gamepad.id}-${evt.gamepad.index}`;
-            this._registerDevice(deviceName, evt.gamepad.buttons.length + evt.gamepad.axes.length);
+            const deviceType = this._getGamepadDeviceType(evt.gamepad.id);
+            const deviceSlot = evt.gamepad.index;
+
+            this._registerDevice(deviceType, deviceSlot, evt.gamepad.buttons.length + evt.gamepad.axes.length);
             this._gamepads = this._gamepads || new Array<string>(evt.gamepad.index + 1);
-            this._gamepads[evt.gamepad.index] = deviceName;
+            this._gamepads[deviceSlot] = deviceType;
         });
 
         this._gamepadDisconnectedEvent = ((evt: any) => {
             if (this._gamepads) {
-                const deviceName = this._gamepads[evt.gamepad.index];
-                this._unregisterDevice(deviceName);
-                delete this._gamepads[evt.gamepad.index];
+                const deviceType = this._getGamepadDeviceType(evt.gamepad.id);
+                const deviceSlot = evt.gamepad.index;
+                
+                this._unregisterDevice(deviceType, deviceSlot);
+                delete this._gamepads[deviceSlot];
             }
         });
 
@@ -275,22 +279,38 @@ export class DeviceInputSystem implements IDisposable {
     /**
      * Update all non-event based devices with each frame
      */
-    private _updateDevice(deviceName: string, inputIndex: number) {
+    private _updateDevice(deviceType: DeviceType, deviceSlot: number, inputIndex: number) {
         // Gamepads
-        const gamepads = navigator.getGamepads();
+        const gp = navigator.getGamepads()[deviceSlot];
 
-        // Look for current gamepad and get updated values
-        for (const gp of gamepads) {
-            if (gp && deviceName == this._gamepads[gp.index]) {
-                const device = this._inputs[deviceName];
+        if (gp && deviceType == this._gamepads[deviceSlot]) {
+            const device = this._inputs[deviceType][deviceSlot];
 
-                if (inputIndex >= gp.buttons.length) {
-                    device[inputIndex] = gp.axes[inputIndex - gp.buttons.length].valueOf();
-                }
-                else {
-                    device[inputIndex] = gp.buttons[inputIndex].value;
-                }
+            if (inputIndex >= gp.buttons.length) {
+                device[inputIndex] = gp.axes[inputIndex - gp.buttons.length].valueOf();
             }
+            else {
+                device[inputIndex] = gp.buttons[inputIndex].value;
+            }
+        }
+    }
+
+    /**
+     * Gets DeviceType from the device name
+     * @param deviceName Name of Device from DeviceInputSystem
+     * @returns DeviceType enum value
+     */
+    private _getGamepadDeviceType(deviceName: string): DeviceType {
+        if (deviceName.indexOf("054c") !== -1) { // DualShock 4 Gamepad
+            return DeviceType.DualShock;
         }
+        else if (deviceName.indexOf("Xbox One") !== -1 || deviceName.search("Xbox 360") !== -1 || deviceName.search("xinput") !== -1) { // Xbox Gamepad
+            return DeviceType.Xbox;
+        }
+        else if (deviceName.indexOf("057e") !== -1) { // Switch Gamepad
+            return DeviceType.Switch;
+        }
+
+        return DeviceType.Generic;
     }
 }