diff --git a/src/index.js b/src/index.js index df8b464678bfef1eafe5530b38361f279d541557..0c43229b2204e8958341bf67542ec51a4d5c2695 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 0000000000000000000000000000000000000000..c6112d69742f775a7b3d335f8388765e6f0e52af --- /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 0000000000000000000000000000000000000000..ac56e2be8a5f3b6028988c4a70e2610b4baa5648 --- /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 f109a82e2e2dd29769bf05258a6b9843fdc89ab4..bc8a96af6c4d9f63e74016c98354f70a335024c9 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; +}