Skip to content

Commit

Permalink
3.20.10
Browse files Browse the repository at this point in the history
  • Loading branch information
quinton-ashley committed Apr 5, 2024
1 parent 6b11d38 commit 2cf2302
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions p5play.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3080,7 +3080,7 @@ class Contro extends InputDevice {
* False if the controller has digital (button) triggers.
* @type {boolean}
*/
get hasAnalogTriggers(): boolean;
hasAnalogTriggers: boolean;
/**
* Alias for `leftStick`.
*/
Expand Down Expand Up @@ -3131,7 +3131,7 @@ class _Contros extends Array<Contro> {
swap(indexA: number, indexB: number): void;
/**
* Removes a controller from this controllers array
* by setting `contro[index] = null`.
* by setting `contros[index] = null`.
*
* Newly connected controllers fill the first empty slot.
* @param {Number} index
Expand Down
30 changes: 18 additions & 12 deletions p5play.js
Original file line number Diff line number Diff line change
Expand Up @@ -10108,6 +10108,15 @@ main {
this.isMock = true;
}

this._axeTriggers = this.gamepad.axes && this.gamepad.axes[this.axeMapping.leftTrigger] !== undefined;

/**
* True if the controller has analog triggers.
* False if the controller has digital (button) triggers.
* @type {boolean}
*/
this.hasAnalogTriggers = this._axeTriggers || undefined;

// corrects button mapping for GuliKit KingKong 2 Pro controllers
// which have a Nintendo Switch style button layout
// https://www.aliexpress.com/item/1005003624801819.html
Expand Down Expand Up @@ -10153,12 +10162,17 @@ main {
this.rightStick.y = pad.axes[this.axeMapping.rightStick.y];

// triggers
if (this.hasAnalogTriggers) {
if (this._axeTriggers) {
this.leftTrigger = pad.axes[this.axeMapping.leftTrigger];
this.rightTrigger = pad.axes[this.axeMapping.rightTrigger];
} else {
this.leftTrigger = pad.buttons[this.buttonMapping.lt].value;
this.rightTrigger = pad.buttons[this.buttonMapping.rt].value;

// only needs to be checked once
if (this.hasAnalogTriggers === undefined && (this.leftTrigger || this.rightTrigger)) {
this.hasAnalogTriggers = !Number.isInteger(this.leftTrigger) || !Number.isInteger(this.rightTrigger);
}
}
return true; // update completed
}
Expand All @@ -10174,14 +10188,6 @@ main {
this.leftTrigger = 0;
this.rightTrigger = 0;
}
/**
* True if the controller has analog triggers.
* False if the controller has digital (button) triggers.
* @type {boolean}
*/
get hasAnalogTriggers() {
return this.gamepad.axes && this.gamepad.axes[this.axeMapping.leftTrigger] !== undefined;
}
/**
* Alias for `leftStick`.
*/
Expand Down Expand Up @@ -10275,7 +10281,7 @@ main {

/**
* Removes a controller from this controllers array
* by setting `contro[index] = null`.
* by setting `contros[index] = null`.
*
* Newly connected controllers fill the first empty slot.
* @param {Number} index
Expand Down Expand Up @@ -10324,7 +10330,7 @@ main {
for (let i = 0; i < this.length; i++) {
if (this[i].gamepad?.index === gp.index) {
this[i].connected = true;
log('contro[' + i + '] reconnected: ' + gp.id);
log('contros[' + i + '] reconnected: ' + gp.id);
return;
}
}
Expand Down Expand Up @@ -10386,7 +10392,7 @@ main {

/**
* For convenience, `contro` can be used to attempt to check the
* input states of `contro[0]` and won't throw errors if a controller
* input states of `contros[0]` and won't throw errors if a controller
* isn't connected yet. By default it is set to a mock controller
* object which you can edit to test your game's input handling.
* @type {Contro}
Expand Down
2 changes: 1 addition & 1 deletion p5play.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
"version": "git add -A",
"postversion": "git push"
},
"version": "3.20.9"
"version": "3.20.10"
}

0 comments on commit 2cf2302

Please sign in to comment.