From 42b713c7d69ea32d180652e0bc44f19f1f9add0f Mon Sep 17 00:00:00 2001 From: Greg Fodor <gfodor@gmail.com> Date: Sun, 21 Oct 2018 23:55:40 +0000 Subject: [PATCH] Basic pin events --- src/components/pin-networked-object-button.js | 20 +++++++++++++++++++ src/components/pinned.js | 8 ++++++++ src/hub.html | 10 +++++----- src/hub.js | 2 ++ src/scene-entry-manager.js | 5 +++++ 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/components/pin-networked-object-button.js create mode 100644 src/components/pinned.js diff --git a/src/components/pin-networked-object-button.js b/src/components/pin-networked-object-button.js new file mode 100644 index 000000000..a522fbb51 --- /dev/null +++ b/src/components/pin-networked-object-button.js @@ -0,0 +1,20 @@ +AFRAME.registerComponent("pin-networked-object-button", { + init() { + this.scene = document.querySelector("a-scene"); + + this.onClick = () => { + this.targetEl.setAttribute("pinned", ""); + this.scene.emit("object_pinned", { el: this.targetEl }); + }; + + NAF.utils.getNetworkedEntity(this.el).then(networkedEl => (this.targetEl = networkedEl)); + }, + + play() { + this.el.addEventListener("click", this.onClick); + }, + + pause() { + this.el.removeEventListener("click", this.onClick); + } +}); diff --git a/src/components/pinned.js b/src/components/pinned.js new file mode 100644 index 000000000..225fd7208 --- /dev/null +++ b/src/components/pinned.js @@ -0,0 +1,8 @@ +AFRAME.registerComponent("pinned", { + init() {}, + + update() { + console.log("Disabling"); + console.log(this.el); + } +}); diff --git a/src/hub.html b/src/hub.html index 991212013..cda3976f0 100644 --- a/src/hub.html +++ b/src/hub.html @@ -164,10 +164,10 @@ activatable__decrease-scale="buttonStartEvents: scroll_left; buttonEndEvents: horizontal_scroll_release; activatedState: scaleDown;" > <a-entity class="action-buttons" visible-while-frozen> - <a-entity mixin="rounded-text-button" remove-networked-object-button position="0 0.125 0.01"> </a-entity> - <a-entity text=" value:Pin; width:1.75; align:center;" text-raycast-hack position="0 0.125 0.02"></a-entity> + <a-entity mixin="rounded-text-button" pin-networked-object-button position="0 0.125 0.01"> </a-entity> + <a-entity text=" value:pin; width:1.75; align:center;" text-raycast-hack position="0 0.125 0.02"></a-entity> <a-entity mixin="rounded-text-button" remove-networked-object-button position="0 -0.125 0.01"> </a-entity> - <a-entity text=" value:Remove; width:1.75; align:center;" text-raycast-hack position="0 -0.125 0.02"></a-entity> + <a-entity text=" value:remove; width:1.75; align:center;" text-raycast-hack position="0 -0.125 0.02"></a-entity> </a-entity> </a-entity> </template> @@ -200,7 +200,7 @@ ></a-sphere> <a-entity class="delete-button" visible-while-frozen> <a-entity mixin="rounded-text-button" remove-networked-object-button position="0 0 0"> </a-entity> - <a-entity text=" value:Remove; width:2.5; align:center;" text-raycast-hack position="0 0 0.01"></a-entity> + <a-entity text=" value:remove; width:2.5; align:center;" text-raycast-hack position="0 0 0.01"></a-entity> </a-entity> </a-entity> </template> @@ -222,7 +222,7 @@ > <a-entity class="delete-button" visible-while-frozen> <a-entity mixin="rounded-text-button" remove-networked-object-button position="0 0 0"> </a-entity> - <a-entity text=" value:Remove; width:2.5; align:center;" text-raycast-hack position="0 0 0.01"></a-entity> + <a-entity text=" value:remove; width:2.5; align:center;" text-raycast-hack position="0 0 0.01"></a-entity> </a-entity> </a-entity> </template> diff --git a/src/hub.js b/src/hub.js index 03b191d39..64ab033db 100644 --- a/src/hub.js +++ b/src/hub.js @@ -67,6 +67,8 @@ import "./components/pitch-yaw-rotator"; import "./components/input-configurator"; import "./components/auto-scale-cannon-physics-body"; import "./components/position-at-box-shape-border"; +import "./components/pinned"; +import "./components/pin-networked-object-button"; import "./components/remove-networked-object-button"; import "./components/destroy-at-extreme-distances"; import "./components/gamma-factor"; diff --git a/src/scene-entry-manager.js b/src/scene-entry-manager.js index b39159838..70a1ee734 100644 --- a/src/scene-entry-manager.js +++ b/src/scene-entry-manager.js @@ -216,6 +216,11 @@ export default class SceneEntryManager { spawnMediaInfrontOfPlayer(e.detail, contentOrigin); }); + this.scene.addEventListener("object_pinned", e => { + console.log("pinned"); + console.log(e); + }); + this.scene.addEventListener("object_spawned", e => { this.hubChannel.sendObjectSpawnedEvent(e.detail.objectType); }); -- GitLab