adjust controller detection regexes
This commit is contained in:
parent
712d661135
commit
cdfd1f97b9
@ -4,6 +4,12 @@
|
|||||||
* @class Gamepad
|
* @class Gamepad
|
||||||
*/
|
*/
|
||||||
class Gamepad {
|
class Gamepad {
|
||||||
|
REGEX = {
|
||||||
|
CHROME: /^(?<name>.*) \((?:.*?Vendor: (?<vendor>[0-9a-f]{4}) Product: (?<product>[0-9a-f]{4})|(?<id>.*))\)$/i,
|
||||||
|
FIREFOX: /^((?<vendor>[0-9a-f]{4})-(?<product>[0-9a-f]{4})-(?<name>.*))$/i,
|
||||||
|
OTHER: /^(?<name>.*)$/i,
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of Gamepad.
|
* Creates an instance of Gamepad.
|
||||||
*/
|
*/
|
||||||
@ -375,7 +381,13 @@ class Gamepad {
|
|||||||
* @returns {object}
|
* @returns {object}
|
||||||
*/
|
*/
|
||||||
toGamepadInfo(id) {
|
toGamepadInfo(id) {
|
||||||
return /(?<name>.*?) \((?:.*?Vendor: (?<vendor>[0-9a-f]{4}) Product: (?<product>[0-9a-f]{4})|(?<id>.*?))\)/.exec(id).groups;
|
const chromeResults = this.REGEX.CHROME.exec(id);
|
||||||
|
if (chromeResults) return chromeResults.groups;
|
||||||
|
const firefoxResults = this.REGEX.FIREFOX.exec(id);
|
||||||
|
if (firefoxResults) return firefoxResults.groups;
|
||||||
|
const otherResults = this.REGEX.OTHER.exec(id);
|
||||||
|
if (otherResults) return otherResults.groups;
|
||||||
|
return { name: id, vendor: '', product: '' };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -887,12 +899,10 @@ class Gamepad {
|
|||||||
// load latest gamepad data
|
// load latest gamepad data
|
||||||
this.pollGamepads();
|
this.pollGamepads();
|
||||||
const activeGamepad = this.getActive();
|
const activeGamepad = this.getActive();
|
||||||
|
if (!activeGamepad) return;
|
||||||
|
|
||||||
// check for actual gamepad update
|
// check for actual gamepad update
|
||||||
if (
|
if (!force && activeGamepad.timestamp === this.lastTimestamp) return;
|
||||||
!force &&
|
|
||||||
(!activeGamepad || activeGamepad.timestamp === this.lastTimestamp)
|
|
||||||
) return;
|
|
||||||
this.lastTimestamp = activeGamepad.timestamp;
|
this.lastTimestamp = activeGamepad.timestamp;
|
||||||
|
|
||||||
// actually update the active gamepad graphically
|
// actually update the active gamepad graphically
|
||||||
|
Loading…
x
Reference in New Issue
Block a user