Skip to content

Motion controller: Separate out value updates and visual responses inside component #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/motion-controllers/src/component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export class Component {
get data(): object;

updateFromGamepad(gamepad: Gamepad): void;
updateValuesFromGamepad(gamepad: Gamepad): void;
}
21 changes: 15 additions & 6 deletions packages/motion-controllers/src/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
});
}
}

Expand Down