Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aframe-gamepad-controls

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aframe-gamepad-controls - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

2

dist/aframe-gamepad-controls.js

@@ -307,3 +307,3 @@ /******/ (function(modules) { // webpackBootstrap

&& navigator.getGamepads()[this.data.controller],
proxyControls = this.el.components['proxy-controls'],
proxyControls = this.el.sceneEl.components['proxy-controls'],
proxyGamepad = proxyControls && proxyControls.isConnected()

@@ -310,0 +310,0 @@ && proxyControls.getGamepad(this.data.controller);

@@ -1,1 +0,1 @@

!function(t){function e(n){if(o[n])return o[n].exports;var i=o[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var o={};return e.m=t,e.c=o,e.p="",e(0)}([function(t,e,o){!function(t){return t?void(t.aframeCore||t).registerComponent("gamepad-controls",o(1)):void console.error("Component attempted to register before AFRAME was available.")}(window.AFRAME)},function(t,e,o){var n=o(2),i=o(3),a=.2,s=Math.PI/2,r=.2;t.exports={GamepadButton:n,schema:{controller:{"default":0,oneOf:[0,1,2,3]},enabled:{"default":!0},movementEnabled:{"default":!0},lookEnabled:{"default":"auto",oneOf:["auto","true","false"]},flyEnabled:{"default":!1},easing:{"default":20},acceleration:{"default":65},sensitivity:{"default":.04},pitchAxis:{"default":"x",oneOf:["x","y","z"]},yawAxis:{"default":"y",oneOf:["x","y","z"]},rollAxis:{"default":"z",oneOf:["x","y","z"]},debug:{"default":!1}},init:function(){var t=this.el.sceneEl;this.prevTime=window.performance.now(),this.velocity=new THREE.Vector3(0,0,0),this.direction=new THREE.Vector3(0,0,0),this.rotation=new THREE.Euler(0,0,0,"YXZ"),this.pitch=new THREE.Object3D,this.yaw=new THREE.Object3D,this.yaw.position.y=10,this.yaw.add(this.pitch),this.buttons={},t.addBehavior(this),this.getGamepad()||console.warn("Gamepad #%d not found. Connect controller and press any button to continue.",this.data.controller)},update:function(t){this.updateRotation(),this.updatePosition(!!t),this.updateButtonState()},remove:function(){},updatePosition:function(t){var e=this.data,o=e.acceleration,n=e.easing,i=this.velocity,s=window.performance.now(),d=(s-this.prevTime)/1e3,u=e.rollAxis,c=e.pitchAxis,h=this.el,l=this.getGamepad();if(this.prevTime=s,t||d>a)return i[u]=0,void(i[c]=0);i[u]-=i[u]*n*d,i[c]-=i[c]*n*d;var p=h.getComputedAttribute("position");if(e.enabled&&e.movementEnabled&&l){var f=this.getDpad(),E=f.x||this.getJoystick(0).x,m=f.y||this.getJoystick(0).y;Math.abs(E)>r&&(i[c]+=E*o*d),Math.abs(m)>r&&(i[u]+=m*o*d)}var b=this.getMovementVector(d);h.object3D.translateX(b.x),h.object3D.translateY(b.y),h.object3D.translateZ(b.z),h.setAttribute("position",{x:p.x+b.x,y:p.y+b.y,z:p.z+b.z})},getMovementVector:function(t){var e=this.el.getAttribute("rotation");return this.direction.copy(this.velocity),this.direction.multiplyScalar(t),e?(this.data.flyEnabled||(e.x=0),this.rotation.set(THREE.Math.degToRad(e.x),THREE.Math.degToRad(e.y),0),this.direction.applyEuler(this.rotation),this.direction):this.direction},updateRotation:function(){if(this.isLookEnabled()&&this.getGamepad()){var t=this.getJoystick(1);Math.abs(t.x)<=r&&(t.x=0),Math.abs(t.y)<=r&&(t.y=0),t.multiplyScalar(this.data.sensitivity),this.yaw.rotation.y-=t.x,this.pitch.rotation.x-=t.y,this.pitch.rotation.x=Math.max(-s,Math.min(s,this.pitch.rotation.x)),this.el.setAttribute("rotation",{x:THREE.Math.radToDeg(this.pitch.rotation.x),y:THREE.Math.radToDeg(this.yaw.rotation.y),z:0})}},updateButtonState:function(){var t=this.getGamepad();if(this.data.enabled&&t)for(var e=0;e<t.buttons.length;e++)t.buttons[e].pressed&&!this.buttons[e]?this.emit(new i("gamepadbuttondown",e,t.buttons[e])):!t.buttons[e].pressed&&this.buttons[e]&&this.emit(new i("gamepadbuttonup",e,t.buttons[e])),this.buttons[e]=t.buttons[e].pressed;else Object.keys(this.buttons)&&(this.buttons={})},emit:function(t){this.el.emit(t.type,t),this.el.emit(t.type+":"+t.index,new i(t.type,t.index,t))},getGamepad:function(){var t=navigator.getGamepads&&navigator.getGamepads()[this.data.controller],e=this.el.components["proxy-controls"],o=e&&e.isConnected()&&e.getGamepad(this.data.controller);return o||t},getButton:function(t){return this.getGamepad().buttons[t]},getAxis:function(t){return this.getGamepad().axes[t]},getJoystick:function(t){var e=this.getGamepad();switch(t){case 0:return new THREE.Vector2(e.axes[0],e.axes[1]);case 1:return new THREE.Vector2(e.axes[2],e.axes[3]);default:throw new Error('Unexpected joystick index "%d".',t)}},getDpad:function(){var t=this.getGamepad();return t.buttons[n.DPAD_RIGHT]?new THREE.Vector2((t.buttons[n.DPAD_RIGHT].pressed?1:0)+(t.buttons[n.DPAD_LEFT].pressed?-1:0),(t.buttons[n.DPAD_UP].pressed?-1:0)+(t.buttons[n.DPAD_DOWN].pressed?1:0)):new THREE.Vector2},isConnected:function(){var t=this.getGamepad();return!(!t||!t.connected)},getID:function(){return this.getGamepad().id},isLookEnabled:function(){if("auto"!==this.data.lookEnabled)return"true"===this.data.lookEnabled;var t=document.fullscreen||document.mozFullScreen||document.webkitIsFullScreen,e=!!this.el.components["look-controls"];return!(t&&e)}}},function(t,e){t.exports=Object.assign(function(){},{FACE_1:0,FACE_2:1,FACE_3:2,FACE_4:3,L_SHOULDER_1:4,R_SHOULDER_1:5,L_SHOULDER_2:6,R_SHOULDER_2:7,SELECT:8,START:9,DPAD_UP:12,DPAD_DOWN:13,DPAD_LEFT:14,DPAD_RIGHT:15,VENDOR:16})},function(t,e){function o(t,e,o){this.type=t,this.index=e,this.pressed=o.pressed,this.value=o.value}t.exports=o}]);
!function(t){function e(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){!function(t){return t?void(t.aframeCore||t).registerComponent("gamepad-controls",n(1)):void console.error("Component attempted to register before AFRAME was available.")}(window.AFRAME)},function(t,e,n){var o=n(2),i=n(3),a=.2,s=Math.PI/2,r=.2;t.exports={GamepadButton:o,schema:{controller:{"default":0,oneOf:[0,1,2,3]},enabled:{"default":!0},movementEnabled:{"default":!0},lookEnabled:{"default":"auto",oneOf:["auto","true","false"]},flyEnabled:{"default":!1},easing:{"default":20},acceleration:{"default":65},sensitivity:{"default":.04},pitchAxis:{"default":"x",oneOf:["x","y","z"]},yawAxis:{"default":"y",oneOf:["x","y","z"]},rollAxis:{"default":"z",oneOf:["x","y","z"]},debug:{"default":!1}},init:function(){var t=this.el.sceneEl;this.prevTime=window.performance.now(),this.velocity=new THREE.Vector3(0,0,0),this.direction=new THREE.Vector3(0,0,0),this.rotation=new THREE.Euler(0,0,0,"YXZ"),this.pitch=new THREE.Object3D,this.yaw=new THREE.Object3D,this.yaw.position.y=10,this.yaw.add(this.pitch),this.buttons={},t.addBehavior(this),this.getGamepad()||console.warn("Gamepad #%d not found. Connect controller and press any button to continue.",this.data.controller)},update:function(t){this.updateRotation(),this.updatePosition(!!t),this.updateButtonState()},remove:function(){},updatePosition:function(t){var e=this.data,n=e.acceleration,o=e.easing,i=this.velocity,s=window.performance.now(),d=(s-this.prevTime)/1e3,u=e.rollAxis,c=e.pitchAxis,h=this.el,l=this.getGamepad();if(this.prevTime=s,t||d>a)return i[u]=0,void(i[c]=0);i[u]-=i[u]*o*d,i[c]-=i[c]*o*d;var p=h.getComputedAttribute("position");if(e.enabled&&e.movementEnabled&&l){var f=this.getDpad(),E=f.x||this.getJoystick(0).x,m=f.y||this.getJoystick(0).y;Math.abs(E)>r&&(i[c]+=E*n*d),Math.abs(m)>r&&(i[u]+=m*n*d)}var b=this.getMovementVector(d);h.object3D.translateX(b.x),h.object3D.translateY(b.y),h.object3D.translateZ(b.z),h.setAttribute("position",{x:p.x+b.x,y:p.y+b.y,z:p.z+b.z})},getMovementVector:function(t){var e=this.el.getAttribute("rotation");return this.direction.copy(this.velocity),this.direction.multiplyScalar(t),e?(this.data.flyEnabled||(e.x=0),this.rotation.set(THREE.Math.degToRad(e.x),THREE.Math.degToRad(e.y),0),this.direction.applyEuler(this.rotation),this.direction):this.direction},updateRotation:function(){if(this.isLookEnabled()&&this.getGamepad()){var t=this.getJoystick(1);Math.abs(t.x)<=r&&(t.x=0),Math.abs(t.y)<=r&&(t.y=0),t.multiplyScalar(this.data.sensitivity),this.yaw.rotation.y-=t.x,this.pitch.rotation.x-=t.y,this.pitch.rotation.x=Math.max(-s,Math.min(s,this.pitch.rotation.x)),this.el.setAttribute("rotation",{x:THREE.Math.radToDeg(this.pitch.rotation.x),y:THREE.Math.radToDeg(this.yaw.rotation.y),z:0})}},updateButtonState:function(){var t=this.getGamepad();if(this.data.enabled&&t)for(var e=0;e<t.buttons.length;e++)t.buttons[e].pressed&&!this.buttons[e]?this.emit(new i("gamepadbuttondown",e,t.buttons[e])):!t.buttons[e].pressed&&this.buttons[e]&&this.emit(new i("gamepadbuttonup",e,t.buttons[e])),this.buttons[e]=t.buttons[e].pressed;else Object.keys(this.buttons)&&(this.buttons={})},emit:function(t){this.el.emit(t.type,t),this.el.emit(t.type+":"+t.index,new i(t.type,t.index,t))},getGamepad:function(){var t=navigator.getGamepads&&navigator.getGamepads()[this.data.controller],e=this.el.sceneEl.components["proxy-controls"],n=e&&e.isConnected()&&e.getGamepad(this.data.controller);return n||t},getButton:function(t){return this.getGamepad().buttons[t]},getAxis:function(t){return this.getGamepad().axes[t]},getJoystick:function(t){var e=this.getGamepad();switch(t){case 0:return new THREE.Vector2(e.axes[0],e.axes[1]);case 1:return new THREE.Vector2(e.axes[2],e.axes[3]);default:throw new Error('Unexpected joystick index "%d".',t)}},getDpad:function(){var t=this.getGamepad();return t.buttons[o.DPAD_RIGHT]?new THREE.Vector2((t.buttons[o.DPAD_RIGHT].pressed?1:0)+(t.buttons[o.DPAD_LEFT].pressed?-1:0),(t.buttons[o.DPAD_UP].pressed?-1:0)+(t.buttons[o.DPAD_DOWN].pressed?1:0)):new THREE.Vector2},isConnected:function(){var t=this.getGamepad();return!(!t||!t.connected)},getID:function(){return this.getGamepad().id},isLookEnabled:function(){if("auto"!==this.data.lookEnabled)return"true"===this.data.lookEnabled;var t=document.fullscreen||document.mozFullScreen||document.webkitIsFullScreen,e=!!this.el.components["look-controls"];return!(t&&e)}}},function(t,e){t.exports=Object.assign(function(){},{FACE_1:0,FACE_2:1,FACE_3:2,FACE_4:3,L_SHOULDER_1:4,R_SHOULDER_1:5,L_SHOULDER_2:6,R_SHOULDER_2:7,SELECT:8,START:9,DPAD_UP:12,DPAD_DOWN:13,DPAD_LEFT:14,DPAD_RIGHT:15,VENDOR:16})},function(t,e){function n(t,e,n){this.type=t,this.index=e,this.pressed=n.pressed,this.value=n.value}t.exports=n}]);

@@ -244,3 +244,3 @@ /**

&& navigator.getGamepads()[this.data.controller],
proxyControls = this.el.components['proxy-controls'],
proxyControls = this.el.sceneEl.components['proxy-controls'],
proxyGamepad = proxyControls && proxyControls.isConnected()

@@ -247,0 +247,0 @@ && proxyControls.getGamepad(this.data.controller);

{
"name": "aframe-gamepad-controls",
"version": "0.3.1",
"version": "0.3.2",
"description": "Gamepad controls for A-Frame.",

@@ -5,0 +5,0 @@ "main": "gamepad-controls.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc