diff --git a/src/systems/userinput/userinput-debug.js b/src/systems/userinput/userinput-debug.js index 9eea8a87a2abdfa0db4dd228f12a3bbcd801cb7e..fe0362c2fe0c2f40d9fc011c28a494cbc052f797 100644 --- a/src/systems/userinput/userinput-debug.js +++ b/src/systems/userinput/userinput-debug.js @@ -2,6 +2,7 @@ import { paths } from "./paths"; const line = "__________________________________________________________________"; const bindingToString = b => { const sb = []; + sb.push("{\n"); sb.push(" "); sb.push("src: "); sb.push("\n"); @@ -36,8 +37,8 @@ const bindingToString = b => { sb.push(s); sb.push("\n"); } - sb.push(line); sb.push("\n"); + sb.push("}\n"); return sb.join(""); }; AFRAME.registerSystem("userinput-debug", { @@ -66,7 +67,19 @@ AFRAME.registerSystem("userinput-debug", { sb.push("\n"); for (let i = 0; i < userinput.runners.length; i++) { if (!userinput.actives[i]) { + sb.push("\n"); + sb.push("The inactive binding:\n"); sb.push(bindingToString(userinput.runners[i])); + sb.push("\n"); + sb.push("is overridden by the following "); + sb.push(userinput.overrides[i].length); + sb.push(" bindings.\n"); + for (const o of userinput.overrides[i]) { + sb.push("\n"); + sb.push("Override:\n"); + sb.push(bindingToString(o)); + sb.push("\n"); + } } } console.log("active and inactive bindings"); diff --git a/src/systems/userinput/userinput.js b/src/systems/userinput/userinput.js index fc84e80f7a971ce43dec6ec5b0228557d5968d26..4bd2c9916b7446c2a1159798100528601529a021 100644 --- a/src/systems/userinput/userinput.js +++ b/src/systems/userinput/userinput.js @@ -157,6 +157,7 @@ AFRAME.registerSystem("userinput", { if (this.pendingSetChanges.length) { this.pendingSetChanges.length = 0; this.actives = []; + this.overrides = []; for (const mapping of this.registeredMappings) { for (const setName in mapping) { if (!this.activeSets.has(setName) || !mapping[setName]) continue; @@ -169,12 +170,13 @@ AFRAME.registerSystem("userinput", { } this.actives.push(active); runners.push(binding); + this.overrides.push([]); } } } const maxAmongActive = (path, map) => { - let max = -1; + let max = { priority: -1 }; const bindings = map.get(path); if (!bindings) { return -1; @@ -186,8 +188,8 @@ AFRAME.registerSystem("userinput", { active = true; } } - if (active && binding.priority && binding.priority > max) { - max = binding.priority; + if (active && binding.priority && binding.priority > max.priority) { + max = binding; } } return max; @@ -201,7 +203,13 @@ AFRAME.registerSystem("userinput", { const path = binding.src[p]; const subpaths = String.split(path, "/"); while (subpaths.length > 1) { - if ((binding.priority || 0) < maxAmongActive(Array.join(subpaths, "/"), this.map, this.activeSets)) { + const highestPriorityBindingForSubpath = maxAmongActive( + Array.join(subpaths, "/"), + this.map, + this.activeSets + ); + if ((binding.priority || 0) < highestPriorityBindingForSubpath.priority) { + this.overrides[i].push(highestPriorityBindingForSubpath); active = false; } subpaths.pop();