cdda07e2801274b76df4851e3f75b2e8f49ade55170a493ce8b746c748819415.json 17 KB

1
  1. {"ast":null,"code":"import { DeviceType } from \"./deviceEnums.js\";\nimport { Observable } from \"../../Misc/observable.js\";\nimport { InternalDeviceSourceManager } from \"../internalDeviceSourceManager.js\";\n/**\n * Class to keep track of devices\n */\nexport class DeviceSourceManager {\n // Public Functions\n /**\n * Gets a DeviceSource, given a type and slot\n * @param deviceType - Type of Device\n * @param deviceSlot - Slot or ID of device\n * @returns DeviceSource\n */\n getDeviceSource(deviceType, deviceSlot) {\n if (deviceSlot === undefined) {\n if (this._firstDevice[deviceType] === undefined) {\n return null;\n }\n deviceSlot = this._firstDevice[deviceType];\n }\n if (!this._devices[deviceType] || this._devices[deviceType][deviceSlot] === undefined) {\n return null;\n }\n return this._devices[deviceType][deviceSlot];\n }\n /**\n * Gets an array of DeviceSource objects for a given device type\n * @param deviceType - Type of Device\n * @returns All available DeviceSources of a given type\n */\n getDeviceSources(deviceType) {\n // If device type hasn't had any devices connected yet, return empty array.\n if (!this._devices[deviceType]) {\n return [];\n }\n return this._devices[deviceType].filter(source => {\n return !!source;\n });\n }\n /**\n * Default constructor\n * @param engine - Used to get canvas (if applicable)\n */\n constructor(engine) {\n const numberOfDeviceTypes = Object.keys(DeviceType).length / 2;\n this._devices = new Array(numberOfDeviceTypes);\n this._firstDevice = new Array(numberOfDeviceTypes);\n this._engine = engine;\n if (!this._engine._deviceSourceManager) {\n this._engine._deviceSourceManager = new InternalDeviceSourceManager(engine);\n }\n this._engine._deviceSourceManager._refCount++;\n // Observables\n this.onDeviceConnectedObservable = new Observable(observer => {\n for (const devices of this._devices) {\n if (devices) {\n for (const device of devices) {\n if (device) {\n this.onDeviceConnectedObservable.notifyObserver(observer, device);\n }\n }\n }\n }\n });\n this.onDeviceDisconnectedObservable = new Observable();\n this._engine._deviceSourceManager.registerManager(this);\n this._onDisposeObserver = engine.onDisposeObservable.add(() => {\n this.dispose();\n });\n }\n /**\n * Dispose of DeviceSourceManager\n */\n dispose() {\n // Null out observable refs\n this.onDeviceConnectedObservable.clear();\n this.onDeviceDisconnectedObservable.clear();\n if (this._engine._deviceSourceManager) {\n this._engine._deviceSourceManager.unregisterManager(this);\n if (--this._engine._deviceSourceManager._refCount < 1) {\n this._engine._deviceSourceManager.dispose();\n delete this._engine._deviceSourceManager;\n }\n }\n this._engine.onDisposeObservable.remove(this._onDisposeObserver);\n }\n // Hidden Functions\n /**\n * @param deviceSource - Source to add\n * @internal\n */\n _addDevice(deviceSource) {\n if (!this._devices[deviceSource.deviceType]) {\n this._devices[deviceSource.deviceType] = new Array();\n }\n if (!this._devices[deviceSource.deviceType][deviceSource.deviceSlot]) {\n this._devices[deviceSource.deviceType][deviceSource.deviceSlot] = deviceSource;\n this._updateFirstDevices(deviceSource.deviceType);\n }\n this.onDeviceConnectedObservable.notifyObservers(deviceSource);\n }\n /**\n * @param deviceType - DeviceType\n * @param deviceSlot - DeviceSlot\n * @internal\n */\n _removeDevice(deviceType, deviceSlot) {\n var _this$_devices$device, _this$_devices$device2;\n const deviceSource = (_this$_devices$device = this._devices[deviceType]) === null || _this$_devices$device === void 0 ? void 0 : _this$_devices$device[deviceSlot]; // Grab local reference to use before removing from devices\n this.onDeviceDisconnectedObservable.notifyObservers(deviceSource);\n if ((_this$_devices$device2 = this._devices[deviceType]) !== null && _this$_devices$device2 !== void 0 && _this$_devices$device2[deviceSlot]) {\n delete this._devices[deviceType][deviceSlot];\n }\n // Even if we don't delete a device, we should still check for the first device as things may have gotten out of sync.\n this._updateFirstDevices(deviceType);\n }\n /**\n * @param deviceType - DeviceType\n * @param deviceSlot - DeviceSlot\n * @param eventData - Event\n * @internal\n */\n _onInputChanged(deviceType, deviceSlot, eventData) {\n var _this$_devices$device3;\n (_this$_devices$device3 = this._devices[deviceType]) === null || _this$_devices$device3 === void 0 || (_this$_devices$device3 = _this$_devices$device3[deviceSlot]) === null || _this$_devices$device3 === void 0 || _this$_devices$device3.onInputChangedObservable.notifyObservers(eventData);\n }\n // Private Functions\n _updateFirstDevices(type) {\n switch (type) {\n case DeviceType.Keyboard:\n case DeviceType.Mouse:\n this._firstDevice[type] = 0;\n break;\n case DeviceType.Touch:\n case DeviceType.DualSense:\n case DeviceType.DualShock:\n case DeviceType.Xbox:\n case DeviceType.Switch:\n case DeviceType.Generic:\n {\n delete this._firstDevice[type];\n // eslint-disable-next-line no-case-declarations\n const devices = this._devices[type];\n if (devices) {\n for (let i = 0; i < devices.length; i++) {\n if (devices[i]) {\n this._firstDevice[type] = i;\n break;\n }\n }\n }\n break;\n }\n }\n }\n}","map":{"version":3,"names":["DeviceType","Observable","InternalDeviceSourceManager","DeviceSourceManager","getDeviceSource","deviceType","deviceSlot","undefined","_firstDevice","_devices","getDeviceSources","filter","source","constructor","engine","numberOfDeviceTypes","Object","keys","length","Array","_engine","_deviceSourceManager","_refCount","onDeviceConnectedObservable","observer","devices","device","notifyObserver","onDeviceDisconnectedObservable","registerManager","_onDisposeObserver","onDisposeObservable","add","dispose","clear","unregisterManager","remove","_addDevice","deviceSource","_updateFirstDevices","notifyObservers","_removeDevice","_this$_devices$device","_this$_devices$device2","_onInputChanged","eventData","_this$_devices$device3","onInputChangedObservable","type","Keyboard","Mouse","Touch","DualSense","DualShock","Xbox","Switch","Generic","i"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/DeviceInput/InputDevices/deviceSourceManager.js"],"sourcesContent":["import { DeviceType } from \"./deviceEnums.js\";\nimport { Observable } from \"../../Misc/observable.js\";\nimport { InternalDeviceSourceManager } from \"../internalDeviceSourceManager.js\";\n/**\n * Class to keep track of devices\n */\nexport class DeviceSourceManager {\n // Public Functions\n /**\n * Gets a DeviceSource, given a type and slot\n * @param deviceType - Type of Device\n * @param deviceSlot - Slot or ID of device\n * @returns DeviceSource\n */\n getDeviceSource(deviceType, deviceSlot) {\n if (deviceSlot === undefined) {\n if (this._firstDevice[deviceType] === undefined) {\n return null;\n }\n deviceSlot = this._firstDevice[deviceType];\n }\n if (!this._devices[deviceType] || this._devices[deviceType][deviceSlot] === undefined) {\n return null;\n }\n return this._devices[deviceType][deviceSlot];\n }\n /**\n * Gets an array of DeviceSource objects for a given device type\n * @param deviceType - Type of Device\n * @returns All available DeviceSources of a given type\n */\n getDeviceSources(deviceType) {\n // If device type hasn't had any devices connected yet, return empty array.\n if (!this._devices[deviceType]) {\n return [];\n }\n return this._devices[deviceType].filter((source) => {\n return !!source;\n });\n }\n /**\n * Default constructor\n * @param engine - Used to get canvas (if applicable)\n */\n constructor(engine) {\n const numberOfDeviceTypes = Object.keys(DeviceType).length / 2;\n this._devices = new Array(numberOfDeviceTypes);\n this._firstDevice = new Array(numberOfDeviceTypes);\n this._engine = engine;\n if (!this._engine._deviceSourceManager) {\n this._engine._deviceSourceManager = new InternalDeviceSourceManager(engine);\n }\n this._engine._deviceSourceManager._refCount++;\n // Observables\n this.onDeviceConnectedObservable = new Observable((observer) => {\n for (const devices of this._devices) {\n if (devices) {\n for (const device of devices) {\n if (device) {\n this.onDeviceConnectedObservable.notifyObserver(observer, device);\n }\n }\n }\n }\n });\n this.onDeviceDisconnectedObservable = new Observable();\n this._engine._deviceSourceManager.registerManager(this);\n this._onDisposeObserver = engine.onDisposeObservable.add(() => {\n this.dispose();\n });\n }\n /**\n * Dispose of DeviceSourceManager\n */\n dispose() {\n // Null out observable refs\n this.onDeviceConnectedObservable.clear();\n this.onDeviceDisconnectedObservable.clear();\n if (this._engine._deviceSourceManager) {\n this._engine._deviceSourceManager.unregisterManager(this);\n if (--this._engine._deviceSourceManager._refCount < 1) {\n this._engine._deviceSourceManager.dispose();\n delete this._engine._deviceSourceManager;\n }\n }\n this._engine.onDisposeObservable.remove(this._onDisposeObserver);\n }\n // Hidden Functions\n /**\n * @param deviceSource - Source to add\n * @internal\n */\n _addDevice(deviceSource) {\n if (!this._devices[deviceSource.deviceType]) {\n this._devices[deviceSource.deviceType] = new Array();\n }\n if (!this._devices[deviceSource.deviceType][deviceSource.deviceSlot]) {\n this._devices[deviceSource.deviceType][deviceSource.deviceSlot] = deviceSource;\n this._updateFirstDevices(deviceSource.deviceType);\n }\n this.onDeviceConnectedObservable.notifyObservers(deviceSource);\n }\n /**\n * @param deviceType - DeviceType\n * @param deviceSlot - DeviceSlot\n * @internal\n */\n _removeDevice(deviceType, deviceSlot) {\n const deviceSource = this._devices[deviceType]?.[deviceSlot]; // Grab local reference to use before removing from devices\n this.onDeviceDisconnectedObservable.notifyObservers(deviceSource);\n if (this._devices[deviceType]?.[deviceSlot]) {\n delete this._devices[deviceType][deviceSlot];\n }\n // Even if we don't delete a device, we should still check for the first device as things may have gotten out of sync.\n this._updateFirstDevices(deviceType);\n }\n /**\n * @param deviceType - DeviceType\n * @param deviceSlot - DeviceSlot\n * @param eventData - Event\n * @internal\n */\n _onInputChanged(deviceType, deviceSlot, eventData) {\n this._devices[deviceType]?.[deviceSlot]?.onInputChangedObservable.notifyObservers(eventData);\n }\n // Private Functions\n _updateFirstDevices(type) {\n switch (type) {\n case DeviceType.Keyboard:\n case DeviceType.Mouse:\n this._firstDevice[type] = 0;\n break;\n case DeviceType.Touch:\n case DeviceType.DualSense:\n case DeviceType.DualShock:\n case DeviceType.Xbox:\n case DeviceType.Switch:\n case DeviceType.Generic: {\n delete this._firstDevice[type];\n // eslint-disable-next-line no-case-declarations\n const devices = this._devices[type];\n if (devices) {\n for (let i = 0; i < devices.length; i++) {\n if (devices[i]) {\n this._firstDevice[type] = i;\n break;\n }\n }\n }\n break;\n }\n }\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,UAAU,QAAQ,0BAA0B;AACrD,SAASC,2BAA2B,QAAQ,mCAAmC;AAC/E;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,CAAC;EAC7B;EACA;AACJ;AACA;AACA;AACA;AACA;EACIC,eAAeA,CAACC,UAAU,EAAEC,UAAU,EAAE;IACpC,IAAIA,UAAU,KAAKC,SAAS,EAAE;MAC1B,IAAI,IA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