From 2abdbc6c3bd970bff5cfd2d297b51a9fc931f365 Mon Sep 17 00:00:00 2001
From: netpro2k <netpro2k@gmail.com>
Date: Wed, 1 Nov 2017 17:15:31 -0700
Subject: [PATCH] quick cleanup of index.js

---
 src/index.js           | 57 +++++-------------------------------------
 src/input-mappings.js  | 27 ++++++++++++++++++++
 src/network-schemas.js | 19 ++++++++++++++
 src/utils.js           |  8 ++++++
 4 files changed, 60 insertions(+), 51 deletions(-)
 create mode 100644 src/input-mappings.js
 create mode 100644 src/network-schemas.js

diff --git a/src/index.js b/src/index.js
index df8b46467..0c43229b2 100644
--- a/src/index.js
+++ b/src/index.js
@@ -16,60 +16,15 @@ import "./components/hand-controls-visibility";
 
 import "./systems/personal-space-bubble";
 
-import { generateName } from "./utils";
+import registerNetworkScheams from "./network-schemas";
+import registerInputMappings from "./input-mappings";
+import { promptForName } from "./utils";
 
-NAF.schemas.add({
-  template: "#nametag-template",
-  components: [
-    {
-      selector: ".nametag",
-      component: "text",
-      property: "value"
-    }
-  ]
-});
+registerNetworkScheams();
+registerInputMappings();
 
-NAF.schemas.add({
-  template: "#hand-template",
-  components: ["position", "rotation", "visible"]
-});
-
-AFRAME.registerInputMappings({
-  default: {
-    common: {
-      // @TODO these dpad events are emmited by an axis-dpad component. This should probalby move into either tracked-controller or input-mapping
-      dpadleftdown: "action_snap_rotate_left",
-      dpadrightdown: "action_snap_rotate_right",
-      dpadcenterdown: "action_teleport_down", // @TODO once once #30 lands in aframe-teleport controls this just maps to "action_teleport_aim"
-      dpadcenterup: "action_teleport_up" // @TODO once once #30 lands in aframe-teleport controls this just maps to "action_teleport_teleport"
-    },
-    "vive-controls": {
-      menudown: "action_mute"
-    },
-    "oculus-touch-controls": {
-      xbuttondown: "action_mute"
-    },
-    daydream: {
-      menudown: "action_mute"
-    },
-    keyboard: {
-      m_press: "action_mute",
-      q_press: "action_snap_rotate_left",
-      e_press: "action_snap_rotate_right"
-    }
-  }
-});
-
-const promptForName = function() {
-  var username = generateName();
-  do {
-    username = prompt("Choose a username", username);
-  } while (!(username && username.length));
-  return username;
-};
-
-const qs = queryString.parse(location.search);
 window.onSceneLoad = function() {
+  const qs = queryString.parse(location.search);
   const scene = document.querySelector("a-scene");
 
   if (qs.room && !isNaN(parseInt(qs.room))) {
diff --git a/src/input-mappings.js b/src/input-mappings.js
new file mode 100644
index 000000000..c6112d697
--- /dev/null
+++ b/src/input-mappings.js
@@ -0,0 +1,27 @@
+export default function registerInputMappings() {
+  AFRAME.registerInputMappings({
+    default: {
+      common: {
+        // @TODO these dpad events are emmited by an axis-dpad component. This should probalby move into either tracked-controller or input-mapping
+        dpadleftdown: "action_snap_rotate_left",
+        dpadrightdown: "action_snap_rotate_right",
+        dpadcenterdown: "action_teleport_down", // @TODO once once #30 lands in aframe-teleport controls this just maps to "action_teleport_aim"
+        dpadcenterup: "action_teleport_up" // @TODO once once #30 lands in aframe-teleport controls this just maps to "action_teleport_teleport"
+      },
+      "vive-controls": {
+        menudown: "action_mute"
+      },
+      "oculus-touch-controls": {
+        xbuttondown: "action_mute"
+      },
+      daydream: {
+        menudown: "action_mute"
+      },
+      keyboard: {
+        m_press: "action_mute",
+        q_press: "action_snap_rotate_left",
+        e_press: "action_snap_rotate_right"
+      }
+    }
+  });
+}
diff --git a/src/network-schemas.js b/src/network-schemas.js
new file mode 100644
index 000000000..ac56e2be8
--- /dev/null
+++ b/src/network-schemas.js
@@ -0,0 +1,19 @@
+function registerNetworkSchemas() {
+  NAF.schemas.add({
+    template: "#nametag-template",
+    components: [
+      {
+        selector: ".nametag",
+        component: "text",
+        property: "value"
+      }
+    ]
+  });
+
+  NAF.schemas.add({
+    template: "#hand-template",
+    components: ["position", "rotation", "visible"]
+  });
+}
+
+export default registerNetworkSchemas;
diff --git a/src/utils.js b/src/utils.js
index f109a82e2..bc8a96af6 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -165,3 +165,11 @@ export function generateName() {
   const name = names[Math.floor(Math.random() * names.length)];
   return name.replace(/^./, name[0].toUpperCase());
 }
+
+export function promptForName() {
+  var username = generateName();
+  do {
+    username = prompt("Choose a username", username);
+  } while (!(username && username.length));
+  return username;
+}
-- 
GitLab