Skip to content

Commit

Permalink
Merge pull request #5946 from mozilla/feature/chat-command-respawn
Browse files Browse the repository at this point in the history
Add chat command to respawn
  • Loading branch information
johnshaughnessy authored Feb 16, 2023
2 parents 1053bd9 + 17a626d commit 288d638
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/message-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
};
}
18 changes: 18 additions & 0 deletions src/utils/chat-commands.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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);
}

0 comments on commit 288d638

Please sign in to comment.