@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.81 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import e from"../../../../core/Handles.js";import{watch as a,initial as t}from"../../../../core/reactiveUtils.js";import{State as r}from"../../state/controllers/CameraController.js";import{GamepadKeyboardController as i}from"../../state/controllers/GamepadKeyboardController.js";import{InputHandler as n}from"../../../input/InputHandler.js";class l extends n{constructor(a){super(!0),this._view=a,this._watchHandles=new e,this._handle=this.registerIncoming("gamepad",(e=>this._handleEventGamepad(e))),this._handle.pause()}onInstall(e){super.onInstall(e),this._watchHandles.add([a((()=>this._view.navigation.gamepad.enabled),(e=>{e?this._handle.resume():(this._handle.pause(),this._cameraControllerGamepad&&(this._cameraControllerGamepad.finishController(),this._cameraControllerGamepad=null))}),t),a((()=>this._view.navigation.gamepad.device),(e=>{this._cameraControllerGamepad&&e&&this._cameraControllerGamepad.gamepadDevice!==e&&(this._cameraControllerGamepad.finishController(),this._cameraControllerGamepad=null)}))])}onUninstall(){this._watchHandles.removeAll(),super.onUninstall()}_handleEventGamepad(e){const a=this._view.navigation.gamepad.device;if(a&&e.data.device!==a)return;const t=this._cameraControllerGamepad?.running;if(t||i.activatesFor(this._view,e.data)){if(!t){const a=new i({view:this._view,gamepadDevice:e.data.device});this._view.state.switchCameraController(a),a.state!==r.Rejected&&(this._cameraControllerGamepad=a)}this._cameraControllerGamepad&&this._cameraControllerGamepad.running&&this._cameraControllerGamepad.gamepadDevice===e.data.device&&this._cameraControllerGamepad.handleEventGamepad(e.data)}}}export{l as GamepadNavigation};