diff --git a/src/message-dispatch.js b/src/message-dispatch.js index 5c2a586f06..e0050ffb25 100644 --- a/src/message-dispatch.js +++ b/src/message-dispatch.js @@ -9,7 +9,7 @@ import { ExitReason } from "./react-components/room/ExitedRoomScreen"; import { LogMessageType } from "./react-components/room/ChatSidebar"; import { createNetworkedEntity } from "./utils/create-networked-entity"; import qsTruthy from "./utils/qs_truthy"; -import { add } from "./utils/chat-commands"; +import { add, respawn } from "./utils/chat-commands"; let uiRoot; // Handles user-entered messages @@ -243,6 +243,13 @@ export default class MessageDispatch extends EventTarget { add(APP.world, avatarPov, args); } break; + case "respawn": + { + const sceneEl = AFRAME.scenes[0]; + const characterController = this.scene.systems["hubs-systems"].characterController; + respawn(APP.world, sceneEl, characterController); + } + break; } }; } diff --git a/src/utils/chat-commands.ts b/src/utils/chat-commands.ts index 833f54ab87..16b15c75ed 100644 --- a/src/utils/chat-commands.ts +++ b/src/utils/chat-commands.ts @@ -1,6 +1,10 @@ +import { AScene } from "aframe"; import { Object3D } from "three"; import { HubsWorld } from "../app"; +import { moveToSpawnPoint } from "../bit-systems/waypoint"; +import { CharacterControllerSystem } from "../systems/character-controller-system"; import { createNetworkedEntity } from "./create-networked-entity"; +import qsTruthy from "./qs_truthy"; function checkFlag(args: string[], flag: string) { return !!args.find(s => s === flag); @@ -54,3 +58,17 @@ export function add(world: HubsWorld, avatarPov: Object3D, args: string[]) { console.log(usage("add", ADD_FLAGS, null, ["url"])); } } + +export function respawn(world: HubsWorld, scene: AScene, characterController: CharacterControllerSystem) { + if (!scene.is("entered")) { + console.error("Cannot respawn until you have entered the room."); + return; + } + + if (!qsTruthy("newLoader")) { + console.error("This command only works with the newLoader query string parameter."); + return; + } + + moveToSpawnPoint(world, characterController); +}