Skip to content

Commit 2b59338

Browse files
authored
Merge pull request #107 from wmurphyrd/nested-handling
Improve handling of nested entities
2 parents 9a0a578 + c5d595d commit 2b59338

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2931
-2774
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Thanks for helping with `super-hands`!
22

33
Two important things to know when contributing:
44

5-
1. This package uses semistandard js style. Run `npm run lint` before
5+
1. This package uses standard js style. Run `npm run lint` before
66
creating a pull request to check your code.
77
2. This package is validated through [machinima testing](https://github.com/wmurphyrd/aframe-machinima-testing).
88
In addition to the unit and integration tests (`npm run test`),

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Build Status](https://travis-ci.org/wmurphyrd/aframe-super-hands-component.svg?branch=master)](https://travis-ci.org/wmurphyrd/aframe-super-hands-component)
44
[![npm Dowloads](https://img.shields.io/npm/dt/super-hands.svg?style=flat-square)](https://www.npmjs.com/package/super-hands)
55
[![npm Version](http://img.shields.io/npm/v/super-hands.svg?style=flat-square)](https://www.npmjs.com/package/super-hands)
6-
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard)
6+
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
77

88
Effortlessly add natural, intuitive interactions with tracked controller,
99
touch, or mouse input in [A-Frame](https://aframe.io).
@@ -245,6 +245,15 @@ LIFO stack of collided entities to determine which will be affected.
245245
If needed, use `event.target` instead.
246246
* For events triggered by buttons, the triggering button event is passed
247247
along in `detail.buttonEvent`
248+
* When entities are nested, gesture events will bubble to the closest parent
249+
with a related reaction component. This makes it easy to make specific
250+
hotspots on larger objects by placing the collidable component on a child
251+
and the reaction component on the parent
252+
(e.g., a door with the handle as a collidable child and a `grabable` parent
253+
door so the whole door moves only when the handle is grabbed). To prevent
254+
a gesture form bubbling, trap it on the child by giving it reaction components
255+
or listening-for and cancelling the gesture events
256+
(see [Gesture acceptance and rejection](#Gesture-acceptance-and-rejection]))
248257

249258
#### Global Event Handler Integration
250259

dist/super-hands.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ AFRAME.registerComponent('clickable', AFRAME.utils.extendDeep({}, buttonCore, {
797797
this.el.removeEventListener(this.UNCLICK_EVENT, this.end);
798798
},
799799
start: function (evt) {
800-
if (!this.startButtonOk(evt)) {
800+
if (evt.defaultPrevented || !this.startButtonOk(evt)) {
801801
return;
802802
}
803803
this.el.addState(this.CLICKED_STATE);
@@ -810,7 +810,7 @@ AFRAME.registerComponent('clickable', AFRAME.utils.extendDeep({}, buttonCore, {
810810
},
811811
end: function (evt) {
812812
const handIndex = this.clickers.indexOf(evt.detail.hand);
813-
if (!this.endButtonOk(evt)) {
813+
if (evt.defaultPrevented || !this.endButtonOk(evt)) {
814814
return;
815815
}
816816
if (handIndex !== -1) {
@@ -923,7 +923,7 @@ AFRAME.registerComponent('draggable', inherit({}, buttonCore, {
923923
this.el.removeEventListener(this.UNDRAG_EVENT, this.dragEnd);
924924
},
925925
dragStart: function (evt) {
926-
if (!this.startButtonOk(evt)) {
926+
if (evt.defaultPrevented || !this.startButtonOk(evt)) {
927927
return;
928928
}
929929
this.el.addState(this.DRAGGED_STATE);
@@ -932,7 +932,7 @@ AFRAME.registerComponent('draggable', inherit({}, buttonCore, {
932932
}
933933
},
934934
dragEnd: function (evt) {
935-
if (!this.endButtonOk(evt)) {
935+
if (evt.defaultPrevented || !this.endButtonOk(evt)) {
936936
return;
937937
}
938938
this.el.removeState(this.DRAGGED_STATE);
@@ -1026,7 +1026,7 @@ AFRAME.registerComponent('droppable', {
10261026
return false;
10271027
},
10281028
hoverStart: function (evt) {
1029-
if (!this.entityAcceptable(evt.detail.carried)) {
1029+
if (evt.defaultPrevented || !this.entityAcceptable(evt.detail.carried)) {
10301030
return;
10311031
}
10321032
this.el.addState(this.HOVERED_STATE);
@@ -1035,9 +1035,15 @@ AFRAME.registerComponent('droppable', {
10351035
}
10361036
},
10371037
hoverEnd: function (evt) {
1038+
if (evt.defaultPrevented) {
1039+
return;
1040+
}
10381041
this.el.removeState(this.HOVERED_STATE);
10391042
},
10401043
dragDrop: function (evt) {
1044+
if (evt.defaultPrevented) {
1045+
return;
1046+
}
10411047
const dropped = evt.detail.dropped;
10421048
if (!this.entityAcceptable(dropped)) {
10431049
if (this.data.rejectEvent.length) {
@@ -1120,7 +1126,7 @@ AFRAME.registerComponent('grabbable', inherit({}, physicsCore, buttonsCore, {
11201126
this.physicsRemove();
11211127
},
11221128
start: function (evt) {
1123-
if (!this.startButtonOk(evt)) {
1129+
if (evt.defaultPrevented || !this.startButtonOk(evt)) {
11241130
return;
11251131
}
11261132
// room for more grabbers?
@@ -1147,7 +1153,7 @@ AFRAME.registerComponent('grabbable', inherit({}, physicsCore, buttonsCore, {
11471153
},
11481154
end: function (evt) {
11491155
const handIndex = this.grabbers.indexOf(evt.detail.hand);
1150-
if (!this.endButtonOk(evt)) {
1156+
if (evt.defaultPrevented || !this.endButtonOk(evt)) {
11511157
return;
11521158
}
11531159
if (handIndex !== -1) {
@@ -1209,6 +1215,9 @@ AFRAME.registerComponent('hoverable', {
12091215
this.el.removeEventListener(this.UNHOVER_EVENT, this.end);
12101216
},
12111217
start: function (evt) {
1218+
if (evt.defaultPrevented) {
1219+
return;
1220+
}
12121221
this.el.addState(this.HOVERED_STATE);
12131222
if (this.hoverers.indexOf(evt.detail.hand) === -1) {
12141223
this.hoverers.push(evt.detail.hand);
@@ -1218,6 +1227,9 @@ AFRAME.registerComponent('hoverable', {
12181227
}
12191228
},
12201229
end: function (evt) {
1230+
if (evt.defaultPrevented) {
1231+
return;
1232+
}
12211233
var handIndex = this.hoverers.indexOf(evt.detail.hand);
12221234
if (handIndex !== -1) {
12231235
this.hoverers.splice(handIndex, 1);
@@ -1375,7 +1387,7 @@ AFRAME.registerComponent('stretchable', inherit({}, buttonCore, {
13751387
this.el.removeEventListener(this.UNSTRETCH_EVENT, this.end);
13761388
},
13771389
start: function (evt) {
1378-
if (this.stretched || this.stretchers.includes(evt.detail.hand) || !this.startButtonOk(evt)) {
1390+
if (this.stretched || this.stretchers.includes(evt.detail.hand) || !this.startButtonOk(evt) || evt.defaultPrevented) {
13791391
return;
13801392
} // already stretched or already captured this hand or wrong button
13811393
this.stretchers.push(evt.detail.hand);
@@ -1390,7 +1402,7 @@ AFRAME.registerComponent('stretchable', inherit({}, buttonCore, {
13901402
},
13911403
end: function (evt) {
13921404
var stretcherIndex = this.stretchers.indexOf(evt.detail.hand);
1393-
if (!this.endButtonOk(evt)) {
1405+
if (evt.defaultPrevented || !this.endButtonOk(evt)) {
13941406
return;
13951407
}
13961408
if (stretcherIndex !== -1) {

0 commit comments

Comments
 (0)