UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 1.64 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import a from"../../../../core/Handles.js";import{watch as e,initial as t}from"../../../../core/reactiveUtils.js";import{GamepadKeyboardController as r}from"../../state/controllers/GamepadKeyboardController.js";import{InputHandler as i}from"../../../input/InputHandler.js";class n extends i{constructor(e){super(!0),this._view=e,this._watchHandles=new a,this._handle=this.registerIncoming("gamepad",a=>this._handleEventGamepad(a)),this._handle.pause()}onInstall(a){super.onInstall(a),this._watchHandles.add([e(()=>this._view.navigation.gamepad.enabled,a=>{a?this._handle.resume():(this._handle.pause(),this._cameraControllerGamepad&&(this._cameraControllerGamepad.finishController(),this._cameraControllerGamepad=null))},t),e(()=>this._view.navigation.gamepad.device,a=>{this._cameraControllerGamepad&&a&&this._cameraControllerGamepad.gamepadDevice!==a&&(this._cameraControllerGamepad.finishController(),this._cameraControllerGamepad=null)})])}onUninstall(){this._watchHandles.removeAll(),super.onUninstall()}_handleEventGamepad(a){const e=this._view.navigation.gamepad.device;if(e&&a.data.device!==e)return;const t=this._cameraControllerGamepad?.running;if(t||r.activatesFor(this._view,a.data)){if(!t){const e=new r({view:this._view,gamepadDevice:a.data.device});this._view.state.switchCameraController(e),1!==e.state&&(this._cameraControllerGamepad=e)}this._cameraControllerGamepad&&this._cameraControllerGamepad.running&&this._cameraControllerGamepad.gamepadDevice===a.data.device&&this._cameraControllerGamepad.handleEventGamepad(a.data)}}}export{n as GamepadNavigation};