Skip to content
Snippets Groups Projects
Commit 71a0c3f8 authored by Greg Fodor's avatar Greg Fodor
Browse files

Re-bind every time

parent 9f2ecbed
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,43 @@ AFRAME.registerSystem("userinput", {
this.registeredMappings = new Set([keyboardDebuggingBindings]);
this.xformStates = new Map();
const vrGamepadMappings = new Map();
vrGamepadMappings.set(ViveControllerDevice, viveUserBindings);
vrGamepadMappings.set(OculusTouchControllerDevice, oculusTouchUserBindings);
vrGamepadMappings.set(OculusGoControllerDevice, oculusGoUserBindings);
vrGamepadMappings.set(DaydreamControllerDevice, daydreamUserBindings);
const nonVRGamepadMappings = new Map();
nonVRGamepadMappings.set(XboxControllerDevice, xboxControllerUserBindings);
nonVRGamepadMappings.set(GamepadDevice, gamepadBindings);
const updateBindingsForVRMode = () => {
const inVRMode = this.el.sceneEl.is("vr-mode");
const isMobile = AFRAME.utils.device.isMobile();
if (inVRMode) {
console.log("Using VR bindings.");
this.registeredMappings.delete(isMobile ? touchscreenUserBindings : keyboardMouseUserBindings);
// add mappings for all active VR input devices
for (const activeDevice of this.activeDevices) {
const mapping = vrGamepadMappings.get(activeDevice.constructor);
mapping && this.registeredMappings.add(mapping);
}
} else {
console.log("Using Non-VR bindings.");
// remove mappings for all active VR input devices
for (const activeDevice of this.activeDevices) {
this.registeredMappings.delete(vrGamepadMappings.get(activeDevice.constructor));
}
this.registeredMappings.add(isMobile ? touchscreenUserBindings : keyboardMouseUserBindings);
}
for (const activeDevice of this.activeDevices) {
const mapping = nonVRGamepadMappings.get(activeDevice.constructor);
mapping && this.registeredMappings.add(mapping);
}
};
const gamepadConnected = e => {
let gamepadDevice;
for (const activeDevice of this.activeDevices) {
......@@ -87,36 +124,22 @@ AFRAME.registerSystem("userinput", {
}
if (e.gamepad.id === "OpenVR Gamepad") {
gamepadDevice = new ViveControllerDevice(e.gamepad);
this.registeredMappings.add(viveUserBindings);
} else if (e.gamepad.id.startsWith("Oculus Touch")) {
gamepadDevice = new OculusTouchControllerDevice(e.gamepad);
this.registeredMappings.add(oculusTouchUserBindings);
} else if (e.gamepad.id === "Oculus Go Controller") {
gamepadDevice = new OculusGoControllerDevice(e.gamepad);
this.registeredMappings.add(oculusGoUserBindings);
} else if (e.gamepad.id === "Daydream Controller") {
gamepadDevice = new DaydreamControllerDevice(e.gamepad);
this.registeredMappings.add(daydreamUserBindings);
} else if (e.gamepad.id.includes("Xbox")) {
gamepadDevice = new XboxControllerDevice(e.gamepad);
this.registeredMappings.add(xboxControllerUserBindings);
} else {
gamepadDevice = new GamepadDevice(e.gamepad);
this.registeredMappings.add(gamepadBindings);
}
this.activeDevices.add(gamepadDevice);
};
const vrGamepadMappings = new Map();
vrGamepadMappings.set(ViveControllerDevice, viveUserBindings);
vrGamepadMappings.set(OculusTouchControllerDevice, oculusTouchUserBindings);
vrGamepadMappings.set(OculusGoControllerDevice, oculusGoUserBindings);
vrGamepadMappings.set(DaydreamControllerDevice, daydreamUserBindings);
const nonVRGamepadMappings = new Map();
nonVRGamepadMappings.set(XboxControllerDevice, xboxControllerUserBindings);
nonVRGamepadMappings.set(GamepadDevice, gamepadBindings);
updateBindingsForVRMode();
};
const gamepadDisconnected = e => {
for (const device of this.activeDevices) {
......@@ -128,28 +151,8 @@ AFRAME.registerSystem("userinput", {
return;
}
}
};
const updateBindingsForVRMode = () => {
const inVRMode = this.el.sceneEl.is("vr-mode");
const isMobile = AFRAME.utils.device.isMobile();
if (inVRMode) {
console.log("Using VR bindings.");
this.registeredMappings.delete(isMobile ? touchscreenUserBindings : keyboardMouseUserBindings);
// add mappings for all active VR input devices
for (const activeDevice of this.activeDevices) {
const mapping = vrGamepadMappings.get(activeDevice.constructor);
mapping && this.registeredMappings.add(mapping);
}
} else {
console.log("Using Non-VR bindings.");
// remove mappings for all active VR input devices
for (const activeDevice of this.activeDevices) {
this.registeredMappings.delete(vrGamepadMappings.get(activeDevice.constructor));
}
this.registeredMappings.add(isMobile ? touchscreenUserBindings : keyboardMouseUserBindings);
}
updateBindingsForVRMode();
};
window.addEventListener("gamepadconnected", gamepadConnected, false);
......@@ -161,12 +164,6 @@ AFRAME.registerSystem("userinput", {
this.el.sceneEl.addEventListener("enter-vr", updateBindingsForVRMode);
this.el.sceneEl.addEventListener("exit-vr", updateBindingsForVRMode);
this.el.sceneEl.addEventListener("stateadded", evt => {
if (evt.detail === "entered") {
updateBindingsForVRMode();
}
});
updateBindingsForVRMode();
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment