-
Notifications
You must be signed in to change notification settings - Fork 74
activatable reaction component #148
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
df3c055
04aa99a
e979d1c
e7c640e
bf2873d
99f6e5e
b57ca23
79be259
4c2ad93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ require('./reaction_components/drag-droppable.js') | |
| require('./reaction_components/draggable.js') | ||
| require('./reaction_components/droppable.js') | ||
| require('./reaction_components/clickable.js') | ||
| require('./reaction_components/activatable.js') | ||
|
|
||
| /** | ||
| * Super Hands component for A-Frame. | ||
|
|
@@ -58,6 +59,18 @@ AFRAME.registerComponent('super-hands', { | |
| 'pointdown', 'thumbdown', 'pointingend', 'pistolend', | ||
| 'thumbstickup', 'mouseup', 'touchend'] | ||
| }, | ||
| activateStartButtons: { | ||
| default: ['gripdown', 'trackpaddown', 'triggerdown', 'gripclose', | ||
| 'abuttondown', 'bbuttondown', 'xbuttondown', 'ybuttondown', | ||
| 'pointup', 'thumbup', 'pointingstart', 'pistolstart', | ||
| 'thumbstickdown', 'mousedown', 'touchstart'] | ||
| }, | ||
| activateEndButtons: { | ||
| default: ['gripup', 'trackpadup', 'triggerup', 'gripopen', | ||
| 'abuttonup', 'bbuttonup', 'xbuttonup', 'ybuttonup', | ||
| 'pointdown', 'thumbdown', 'pointingend', 'pistolend', | ||
| 'thumbstickup', 'mouseup', 'touchend'] | ||
| }, | ||
| interval: { default: 0 } | ||
| }, | ||
|
|
||
|
|
@@ -82,6 +95,8 @@ AFRAME.registerComponent('super-hands', { | |
| this.DRAGOVER_EVENT = 'dragover-start' | ||
| this.UNDRAGOVER_EVENT = 'dragover-end' | ||
| this.DRAGDROP_EVENT = 'drag-drop' | ||
| this.ACTIVATE_EVENT = 'activate-start' | ||
| this.DEACTIVATE_EVENT = 'activate-end' | ||
|
|
||
| // links to other systems/components | ||
| this.otherSuperHand = null | ||
|
|
@@ -106,6 +121,8 @@ AFRAME.registerComponent('super-hands', { | |
| this.onStretchEndButton = this.onStretchEndButton.bind(this) | ||
| this.onDragDropStartButton = this.onDragDropStartButton.bind(this) | ||
| this.onDragDropEndButton = this.onDragDropEndButton.bind(this) | ||
| this.onActivateStartButton = this.onActivateStartButton.bind(this) | ||
| this.onActivateEndButton = this.onActivateEndButton.bind(this) | ||
| this.system.registerMe(this) | ||
| }, | ||
|
|
||
|
|
@@ -281,6 +298,30 @@ AFRAME.registerComponent('super-hands', { | |
| } | ||
| } | ||
| }, | ||
| onActivateStartButton: function (evt) { | ||
| const carried = this.state.get(this.GRAB_EVENT) | ||
| let activated = this.state.get(this.ACTIVATE_EVENT) | ||
| if (carried) { | ||
| if (!activated && !this.emitCancelable(carried, this.ACTIVATE_EVENT, {hand: this.el, buttonEvent: evt})) { | ||
| activated = this.state.get(this.ACTIVATE_EVENT) | ||
| } | ||
| if (activated) { | ||
| this.state.set(this.ACTIVATE_EVENT, activated) | ||
|
||
| } | ||
| } | ||
| }, | ||
| onActivateEndButton: function (evt) { | ||
| const carried = this.state.get(this.GRAB_EVENT) | ||
| let deactivated = this.state.get(this.DEACTIVATE_EVENT) | ||
| if (carried) { | ||
| if (!deactivated && !this.emitCancelable(carried, this.DEACTIVATE_EVENT, {hand: this.el, buttonEvent: evt})) { | ||
| deactivated = this.state.get(this.DEACTIVATE_EVENT) | ||
| } | ||
| if (deactivated) { | ||
| this.state.set(this.DEACTIVATE_EVENT, deactivated) | ||
|
||
| } | ||
| } | ||
| }, | ||
| processHitEl: function (hitEl, intersection) { | ||
| const dist = intersection && intersection.distance | ||
| const sects = this.hoverElsIntersections | ||
|
|
@@ -434,6 +475,9 @@ AFRAME.registerComponent('super-hands', { | |
| this.data.dragDropStartButtons.forEach(b => { | ||
| this.el.addEventListener(b, this.onDragDropStartButton) | ||
| }) | ||
| this.data.activateStartButtons.forEach(b => { | ||
| this.el.addEventListener(b, this.onActivateStartButton) | ||
| }) | ||
| this.data.dragDropEndButtons.forEach(b => { | ||
| this.el.addEventListener(b, this.onDragDropEndButton) | ||
| }) | ||
|
|
@@ -443,6 +487,9 @@ AFRAME.registerComponent('super-hands', { | |
| this.data.grabEndButtons.forEach(b => { | ||
| this.el.addEventListener(b, this.onGrabEndButton) | ||
| }) | ||
| this.data.activateEndButtons.forEach(b => { | ||
| this.el.addEventListener(b, this.onActivateEndButton) | ||
| }) | ||
| }, | ||
| unRegisterListeners: function (data) { | ||
| data = data || this.data | ||
|
|
@@ -463,6 +510,9 @@ AFRAME.registerComponent('super-hands', { | |
| data.stretchStartButtons.forEach(b => { | ||
| this.el.removeEventListener(b, this.onStretchStartButton) | ||
| }) | ||
| data.activateStartButtons.forEach(b => { | ||
| this.el.removeEventListener(b, this.onActivateStartButton) | ||
| }) | ||
| data.stretchEndButtons.forEach(b => { | ||
| this.el.removeEventListener(b, this.onStretchEndButton) | ||
| }) | ||
|
|
@@ -472,6 +522,9 @@ AFRAME.registerComponent('super-hands', { | |
| data.dragDropEndButtons.forEach(b => { | ||
| this.el.removeEventListener(b, this.onDragDropEndButton) | ||
| }) | ||
| data.activateEndButtons.forEach(b => { | ||
| this.el.removeEventListener(b, this.onActivateEndButton) | ||
| }) | ||
| }, | ||
| emitCancelable: function (target, name, detail) { | ||
| var data, evt | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* global AFRAME */ | ||
| const inherit = AFRAME.utils.extendDeep | ||
| const buttonCore = require('./prototypes/buttons-proto.js') | ||
|
|
||
| AFRAME.registerComponent('activatable', inherit({}, buttonCore, { | ||
| multiple: true, | ||
| schema: { | ||
| buttonStartEvent: {default: ''}, | ||
| buttonEndEvent: {default: ''}, | ||
| activatedState: {default: 'activated'} | ||
| }, | ||
| init: function () { | ||
| this.ACTIVATE_EVENT = 'activate-start' | ||
| this.DEACTIVATE_EVENT = 'activate-end' | ||
|
|
||
| this.activateStart = this.activateStart.bind(this) | ||
| this.activateEnd = this.activateEnd.bind(this) | ||
|
|
||
| this.el.addEventListener(this.ACTIVATE_EVENT, this.activateStart) | ||
| this.el.addEventListener(this.DEACTIVATE_EVENT, this.activateEnd) | ||
| }, | ||
| remove: function () { | ||
| this.el.removeEventListener(this.ACTIVATE_EVENT, this.activateStart) | ||
| this.el.removeEventListener(this.DEACTIVATE_EVENT, this.activateEnd) | ||
| }, | ||
| activateStart: function (evt) { | ||
| if (evt.defaultPrevented || !this.startButtonOk(evt)) { return } | ||
| if (evt.detail.buttonEvent.type !== this.data.buttonStartEvent) { return } | ||
| this.el.addState(this.data.activatedState) | ||
| if (evt.preventDefault) { evt.preventDefault() } | ||
| }, | ||
| activateEnd: function (evt) { | ||
| if (evt.defaultPrevented || !this.endButtonOk(evt)) { return } | ||
| if (evt.detail.buttonEvent.type !== this.data.buttonEndEvent) { return } | ||
| this.el.removeState(this.data.activatedState) | ||
| if (evt.preventDefault) { evt.preventDefault() } | ||
| } | ||
| })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would mean only an entity which is already the grabbed entity can be activated. In this respect, it wouldn't be much different from the drag gesture. What would you say to making this a more general gesture, just the act of pressing a button while targeting an entity? I'm thinking this way the
activatablecomponent would replace theclickablecomponent and do a better job of what it has been trying to do without interfering with grabbing. When you do want an activation that is dependent on also being grabbed, that logic could be handled within the reaction component instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was definitely intended to be similar to
draggable, but more generic and customizable (since you can specify exactly what state to set on the objects so you can have multiple). Also, givenclickableexists, I didn't see the need to allowactivatableto work on ungrabbed objects. I am not opposed to rolling all three of these together since they are pretty similar.