Skip to content

Commit

Permalink
Merge pull request #16 from poeticAndroid/dev
Browse files Browse the repository at this point in the history
v0.17.0
  • Loading branch information
poeticAndroid authored Jul 11, 2021
2 parents 5362455 + 94e6ced commit ecb894f
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Essential game components for [A-Frame](https://aframe.io/)!
<html>
<head>
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v0.16.0/dist/a-game.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v0.17.0/dist/a-game.min.js"></script>
</head>
<body>
<a-scene physics>
Expand Down
53 changes: 34 additions & 19 deletions dist/a-game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module.exports={
"name": "a-game",
"title": "A-Game",
"version": "0.16.0",
"version": "0.17.0",
"description": "game components for A-Frame",
"homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md",
"main": "index.js",
Expand Down Expand Up @@ -89,6 +89,7 @@ AFRAME.registerComponent("grabbing", {
this._btnPress = {}
this._btnFlex = {}
this._keysDown = {}
this._grabCount = 0

this._hands = ["head", "left", "right"]
this._head = {}
Expand Down Expand Up @@ -401,6 +402,7 @@ AFRAME.registerComponent("grabbing", {
// if (this[_hand].glove.getAttribute("body"))
this[_hand].glove.setAttribute("body", "collidesWith", 0)
this.emit("grab", this[_hand].glove, this[_hand].grabbed, { intersection: hit })
this._grabCount = Math.min(2, this._grabCount + 1)
this.el.addState("grabbing")
this[_hand].grabbed.addState("grabbed")
this.sticky = true
Expand All @@ -426,9 +428,11 @@ AFRAME.registerComponent("grabbing", {
// if (this[_hand].glove.getAttribute("body"))
this[_hand].glove.setAttribute("body", "collidesWith", 1)
}, 1024)
this.emit("drop", this[_hand].glove, this[_hand].grabbed)
this.el.removeState("grabbing")
if (this[_hand].grabbed) {
this.emit("drop", this[_hand].glove, this[_hand].grabbed)
this._grabCount = Math.max(0, this._grabCount - 1)
if (!this._grabCount)
this.el.removeState("grabbing")
this._flexFinger(hand, 5, 0)
this[_hand].grabbed.removeState("grabbed")
this[_hand].grabbed = null
Expand Down Expand Up @@ -606,12 +610,14 @@ AFRAME.registerComponent("grabbing", {
this.useDown("head", btn ? ((btn % 2) ? btn + 1 : btn - 1) : btn)
},
_onWheel(e) {
if (this._keysDown["KeyR"] && e.deltaY > 0) return this.moveHeadHand(0, 0, 0, -0.125)
if (this._keysDown["KeyR"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0, 0.125)
if (this._keysDown["KeyY"] && e.deltaY > 0) return this.moveHeadHand(0, 0, -0.125)
if (this._keysDown["KeyY"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0.125)
if (this._keysDown["KeyT"] && e.deltaY > 0) return this.moveHeadHand(0, 0.125)
if (this._keysDown["KeyT"] && e.deltaY < 0) return this.moveHeadHand(0, -0.125)
let x = 0, y = 0, z = 0
if (this._keysDown["Digit3"] && e.deltaY > 0) z += -0.125
if (this._keysDown["Digit3"] && e.deltaY < 0) z += 0.125
if (this._keysDown["Digit2"] && e.deltaY > 0) y += -0.125
if (this._keysDown["Digit2"] && e.deltaY < 0) y += 0.125
if (this._keysDown["Digit1"] && e.deltaY > 0) x += 0.125
if (this._keysDown["Digit1"] && e.deltaY < 0) x += -0.125
if (x || y || z) return this.moveHeadHand(0, x, y, z)
if (e.deltaY > 0) return this.moveHeadHand(0.125)
if (e.deltaY < 0) return this.moveHeadHand(-0.125)
},
Expand Down Expand Up @@ -689,17 +695,18 @@ AFRAME.registerComponent("climbable", {

init() {
this.el.setAttribute("grabbable", "physics:false; kinematicGrab:false;")
this._player = this.el.sceneEl.querySelector("[locomotion")
this._quat = new THREE.Quaternion()
this._lpos = new THREE.Vector3()
this._wpos = new THREE.Vector3()
this._handpos = new THREE.Vector3()
this._player = this.el.sceneEl.querySelector("[locomotion]")

this._onBump = this._onBump.bind(this)
this._onBumpThis = this._onBumpThis.bind(this)
this._autoGrab = true

setTimeout(() => {
this._quat = new THREE.Quaternion()
this._lpos = new THREE.Vector3()
this._wpos = new THREE.Vector3()
this._handpos = new THREE.Vector3()

this._quat.copy(this.el.object3D.quaternion)
this._lpos.copy(this.el.object3D.position)
this.el.object3D.getWorldPosition(this._wpos)
Expand All @@ -714,9 +721,14 @@ AFRAME.registerComponent("climbable", {
pause() {
this._player.removeEventListener("bump", this._onBump)
this.el.removeEventListener("bump", this._onBumpThis)
this._climbing = false
},

tick() {
if (!this._lpos) return
this.el.object3D.quaternion.copy(this._quat)
this.el.object3D.position.copy(this._lpos)

if (!this._climbing) return
let delta = THREE.Vector3.temp()
this._hand.object3D.getWorldPosition(delta)
Expand All @@ -729,9 +741,6 @@ AFRAME.registerComponent("climbable", {
this._player.components.locomotion.stopFall()
this._player.components.locomotion.move(delta)
if (this._handpos.y - this._wpos.y > this._top) this._player.components.grabbing.dropObject(this.el)

this.el.object3D.quaternion.copy(this._quat)
this.el.object3D.position.copy(this._lpos)
},

events: {
Expand Down Expand Up @@ -848,6 +857,7 @@ AFRAME.registerComponent("receptacle", {
schema: {
objects: { type: "string", default: "[grabbable]" },
radius: { type: "number", default: 0.125 },
onlyGrabbed: { type: "boolean", default: false },
},

init() {
Expand Down Expand Up @@ -892,6 +902,7 @@ AFRAME.registerComponent("receptacle", {
})
}
this._hover = false
this._grabbed = false
} else if (delta.length() > this.data.radius) {
if (this.el.is("filled")) {
this._anchor.removeAttribute("joint__put")
Expand All @@ -915,6 +926,7 @@ AFRAME.registerComponent("receptacle", {
})
}
this._hover = false
this._grabbed = false
} else if (this.nearest.is("grabbed") || !this._hover) {
if (!this._hover) {
this.el.emit("hover", {
Expand All @@ -928,7 +940,9 @@ AFRAME.registerComponent("receptacle", {
this._anchor.removeAttribute("animation__rot")
this._anchor.copyWorldPosRot(this.nearest)
this._hover = true
} else {
if (this.nearest.is("grabbed"))
this._grabbed = true
} else if (this._grabbed || !this.data.onlyGrabbed) {
if (!this.el.is("filled")) {
this._anchor.copyWorldPosRot(this.nearest)
this._anchor.components.body.commit()
Expand Down Expand Up @@ -2458,10 +2472,11 @@ AFRAME.registerComponent("trigger", {
trigger: this.el,
object: obj,
}
this.el.removeState("triggered")
this.el.emit("untrigger", d)
obj.emit("untrigger", d)
this.triggered.splice(this.triggered.indexOf(obj), 1)
if (!this.triggered.length)
this.el.removeState("triggered")
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion dist/a-game.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<a-entity include="./scenes/_assets.html"></a-entity>
<a-player include="./scenes/_player.html">
</a-player>
<a-main include="./scenes/ballmachine.html">
<a-main include="./scenes/demo.html">
<a-box floor color="gray" width="32" height="0.25" depth="32"></a-box>
</a-main>
</a-scene>
Expand Down
2 changes: 1 addition & 1 deletion dist/scenes/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<a-box src="#granite" material="repeat: 20 1" floor width="20" height="0.1" position="0 -2.5 -8.5"
rotation="0 0 21"></a-box>
<a-box rotation="-90 0 0" src="#woodImg" material="repeat: 2 2" width="16" height="16" depth="0.25" floor></a-box>
<a-sphere radius="0.125" receptacle position="0 1 0"></a-sphere>
<a-sphere radius="0.125" receptacle="onlyGrabbed:true;" position="0 1 0"></a-sphere>
<a-sphere radius="0.125" receptacle position="1 1 0"></a-sphere>
<a-sphere radius="0.125" receptacle position="-1 1 0"></a-sphere>
<a-sphere radius="0.125" receptacle position="2 1 0"></a-sphere>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "a-game",
"title": "A-Game",
"version": "0.16.0",
"version": "0.17.0",
"description": "game components for A-Frame",
"homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md",
"main": "index.js",
Expand Down
22 changes: 14 additions & 8 deletions src/components/grabbing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ AFRAME.registerComponent("grabbing", {
this._btnPress = {}
this._btnFlex = {}
this._keysDown = {}
this._grabCount = 0

this._hands = ["head", "left", "right"]
this._head = {}
Expand Down Expand Up @@ -332,6 +333,7 @@ AFRAME.registerComponent("grabbing", {
// if (this[_hand].glove.getAttribute("body"))
this[_hand].glove.setAttribute("body", "collidesWith", 0)
this.emit("grab", this[_hand].glove, this[_hand].grabbed, { intersection: hit })
this._grabCount = Math.min(2, this._grabCount + 1)
this.el.addState("grabbing")
this[_hand].grabbed.addState("grabbed")
this.sticky = true
Expand All @@ -357,9 +359,11 @@ AFRAME.registerComponent("grabbing", {
// if (this[_hand].glove.getAttribute("body"))
this[_hand].glove.setAttribute("body", "collidesWith", 1)
}, 1024)
this.emit("drop", this[_hand].glove, this[_hand].grabbed)
this.el.removeState("grabbing")
if (this[_hand].grabbed) {
this.emit("drop", this[_hand].glove, this[_hand].grabbed)
this._grabCount = Math.max(0, this._grabCount - 1)
if (!this._grabCount)
this.el.removeState("grabbing")
this._flexFinger(hand, 5, 0)
this[_hand].grabbed.removeState("grabbed")
this[_hand].grabbed = null
Expand Down Expand Up @@ -537,12 +541,14 @@ AFRAME.registerComponent("grabbing", {
this.useDown("head", btn ? ((btn % 2) ? btn + 1 : btn - 1) : btn)
},
_onWheel(e) {
if (this._keysDown["KeyR"] && e.deltaY > 0) return this.moveHeadHand(0, 0, 0, -0.125)
if (this._keysDown["KeyR"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0, 0.125)
if (this._keysDown["KeyY"] && e.deltaY > 0) return this.moveHeadHand(0, 0, -0.125)
if (this._keysDown["KeyY"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0.125)
if (this._keysDown["KeyT"] && e.deltaY > 0) return this.moveHeadHand(0, 0.125)
if (this._keysDown["KeyT"] && e.deltaY < 0) return this.moveHeadHand(0, -0.125)
let x = 0, y = 0, z = 0
if (this._keysDown["Digit3"] && e.deltaY > 0) z += -0.125
if (this._keysDown["Digit3"] && e.deltaY < 0) z += 0.125
if (this._keysDown["Digit2"] && e.deltaY > 0) y += -0.125
if (this._keysDown["Digit2"] && e.deltaY < 0) y += 0.125
if (this._keysDown["Digit1"] && e.deltaY > 0) x += 0.125
if (this._keysDown["Digit1"] && e.deltaY < 0) x += -0.125
if (x || y || z) return this.moveHeadHand(0, x, y, z)
if (e.deltaY > 0) return this.moveHeadHand(0.125)
if (e.deltaY < 0) return this.moveHeadHand(-0.125)
},
Expand Down
9 changes: 8 additions & 1 deletion src/components/grabbing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This makes it possible to grab and use grabbable objects using the following con
| Primary use | Trigger | Left click | Tap |
| Secondary | A | Right click |
| Tertiary | B | Middle click |
| Move hand | X + D-pad | R/T/Y + scroll wheel |
| Move hand | X + D-pad | 1/2/3 + scroll wheel |


## Properties
Expand Down Expand Up @@ -63,6 +63,13 @@ These events are emitted by both the glove and the `grabbable` that it's grabbin
| unhover | button no longer pointed at |


## States

| State | Description |
| -------- | ---------------------------- |
| grabbing | currently grabbing something |


## Related components

- [button](./grabbing/button.md)
Expand Down
7 changes: 7 additions & 0 deletions src/components/grabbing/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ Add the `button` component to any object you want the player to be able to press
| press | button got pressed |
| unpress | button no longer pressed |
| unhover | button no longer pointed at |


## States

| State | Description |
| ------- | ----------------------- |
| pressed | currently being pressed |
19 changes: 11 additions & 8 deletions src/components/grabbing/climbable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ AFRAME.registerComponent("climbable", {

init() {
this.el.setAttribute("grabbable", "physics:false; kinematicGrab:false;")
this._player = this.el.sceneEl.querySelector("[locomotion")
this._quat = new THREE.Quaternion()
this._lpos = new THREE.Vector3()
this._wpos = new THREE.Vector3()
this._handpos = new THREE.Vector3()
this._player = this.el.sceneEl.querySelector("[locomotion]")

this._onBump = this._onBump.bind(this)
this._onBumpThis = this._onBumpThis.bind(this)
this._autoGrab = true

setTimeout(() => {
this._quat = new THREE.Quaternion()
this._lpos = new THREE.Vector3()
this._wpos = new THREE.Vector3()
this._handpos = new THREE.Vector3()

this._quat.copy(this.el.object3D.quaternion)
this._lpos.copy(this.el.object3D.position)
this.el.object3D.getWorldPosition(this._wpos)
Expand All @@ -32,9 +33,14 @@ AFRAME.registerComponent("climbable", {
pause() {
this._player.removeEventListener("bump", this._onBump)
this.el.removeEventListener("bump", this._onBumpThis)
this._climbing = false
},

tick() {
if (!this._lpos) return
this.el.object3D.quaternion.copy(this._quat)
this.el.object3D.position.copy(this._lpos)

if (!this._climbing) return
let delta = THREE.Vector3.temp()
this._hand.object3D.getWorldPosition(delta)
Expand All @@ -47,9 +53,6 @@ AFRAME.registerComponent("climbable", {
this._player.components.locomotion.stopFall()
this._player.components.locomotion.move(delta)
if (this._handpos.y - this._wpos.y > this._top) this._player.components.grabbing.dropObject(this.el)

this.el.object3D.quaternion.copy(this._quat)
this.el.object3D.position.copy(this._lpos)
},

events: {
Expand Down
8 changes: 8 additions & 0 deletions src/components/grabbing/grabbable.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ Add the `grabbable` component to any object you want the player to be able to pi
| useup | use-button is released. |
| drop | dropping. |
| fingerflex | a finger is flexing. |


## States

| State | Description |
| ------- | --------------------------- |
| grabbed | currently being grabbed |
| put | currently in a `receptacle` |
7 changes: 6 additions & 1 deletion src/components/grabbing/receptacle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AFRAME.registerComponent("receptacle", {
schema: {
objects: { type: "string", default: "[grabbable]" },
radius: { type: "number", default: 0.125 },
onlyGrabbed: { type: "boolean", default: false },
},

init() {
Expand Down Expand Up @@ -48,6 +49,7 @@ AFRAME.registerComponent("receptacle", {
})
}
this._hover = false
this._grabbed = false
} else if (delta.length() > this.data.radius) {
if (this.el.is("filled")) {
this._anchor.removeAttribute("joint__put")
Expand All @@ -71,6 +73,7 @@ AFRAME.registerComponent("receptacle", {
})
}
this._hover = false
this._grabbed = false
} else if (this.nearest.is("grabbed") || !this._hover) {
if (!this._hover) {
this.el.emit("hover", {
Expand All @@ -84,7 +87,9 @@ AFRAME.registerComponent("receptacle", {
this._anchor.removeAttribute("animation__rot")
this._anchor.copyWorldPosRot(this.nearest)
this._hover = true
} else {
if (this.nearest.is("grabbed"))
this._grabbed = true
} else if (this._grabbed || !this.data.onlyGrabbed) {
if (!this.el.is("filled")) {
this._anchor.copyWorldPosRot(this.nearest)
this._anchor.components.body.commit()
Expand Down
Loading

0 comments on commit ecb894f

Please sign in to comment.