@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.6 kB
JavaScript
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 l 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&&this._cameraControllerGamepad.active;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)&&(this._cameraControllerGamepad=e)}this._cameraControllerGamepad&&this._cameraControllerGamepad.active&&this._cameraControllerGamepad.gamepadDevice===a.data.device&&this._cameraControllerGamepad.handleEventGamepad(a.data)}}}export{l as GamepadNavigation};