From a5ee43cf576ad60d631ef55c335d0196bff7ce59 Mon Sep 17 00:00:00 2001 From: Ayaskant Panigrahi Date: Tue, 15 Nov 2022 13:33:59 -0800 Subject: [PATCH 1/2] Separate out value update logic into a public method --- packages/motion-controllers/src/components.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/motion-controllers/src/components.js b/packages/motion-controllers/src/components.js index 54c83d26b..6919b9989 100644 --- a/packages/motion-controllers/src/components.js +++ b/packages/motion-controllers/src/components.js @@ -44,10 +44,24 @@ class Component { } /** - * @description Poll for updated data based on current gamepad state + * @description Poll for updated values and visual response weights based on current gamepad state * @param {Object} gamepad - The gamepad object from which the component data should be polled */ updateFromGamepad(gamepad) { + // Update the values with latest data from the gamepad + this.updateValuesFromGamepad(gamepad); + + // Update the visual response weights based on the current component data + Object.values(this.visualResponses).forEach((visualResponse) => { + visualResponse.updateFromComponent(this.values); + }); + } + + /** + * @description Poll for updated component values based on current gamepad state + * @param {Object} gamepad - The gamepad object from which the component values should be polled + */ + updateValuesFromGamepad(gamepad) { // Set the state to default before processing other data sources this.values.state = Constants.ComponentState.DEFAULT; @@ -94,11 +108,6 @@ class Component { this.values.state = Constants.ComponentState.TOUCHED; } } - - // Update the visual response weights based on the current component data - Object.values(this.visualResponses).forEach((visualResponse) => { - visualResponse.updateFromComponent(this.values); - }); } } From b16b3a22d5b15ec9f7b486e60a53be528cf74951 Mon Sep 17 00:00:00 2001 From: Ayaskant Panigrahi Date: Tue, 15 Nov 2022 13:35:31 -0800 Subject: [PATCH 2/2] Update component definition with new method --- packages/motion-controllers/src/component.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/motion-controllers/src/component.d.ts b/packages/motion-controllers/src/component.d.ts index f279482a7..aa6a75c97 100644 --- a/packages/motion-controllers/src/component.d.ts +++ b/packages/motion-controllers/src/component.d.ts @@ -20,4 +20,5 @@ export class Component { get data(): object; updateFromGamepad(gamepad: Gamepad): void; + updateValuesFromGamepad(gamepad: Gamepad): void; }