Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { spawnChatMessage } from "./react-components/chat-message";
const DUCK_URL = "https://asset-bundles-prod.reticulum.io/interactables/Ducky/DuckyMesh-438ff8e022.gltf";
// Handles user-entered messages
export default class MessageDispatch {
constructor(scene, entryManager, hubChannel, addToPresenceLog, remountUI) {
this.scene = scene;
this.entryManager = entryManager;
this.hubChannel = hubChannel;
this.addToPresenceLog = addToPresenceLog;
this.remountUI = remountUI;
}
dispatch = message => {
if (message.startsWith("/")) {
this.dispatchCommand(message.substring(1));
document.activeElement.blur(); // Commands should blur
} else {
this.hubChannel.sendMessage(message);
}
};
dispatchCommand = command => {
const entered = this.scene.is("entered");
switch (command) {
case "help":
// HACK for now, non-trivial to properly send this into React
document.querySelector(".help-button").click();
return;
}
if (!entered) {
this.addToPresenceLog({ type: "log", body: "You must enter the room to use this command." });
return;
}
const playerRig = document.querySelector("#player-rig");
const scales = [0.0625, 0.125, 0.25, 0.5, 1.0, 1.5, 3, 5, 7.5, 12.5];
const curScale = playerRig.object3D.scale;
switch (command) {
case "fly":
if (playerRig.getAttribute("character-controller").fly !== true) {
playerRig.setAttribute("character-controller", "fly", true);
this.addToPresenceLog({ type: "log", body: "Fly mode enabled." });
} else {
playerRig.setAttribute("character-controller", "fly", false);
this.addToPresenceLog({ type: "log", body: "Fly mode disabled." });
}
break;
case "bigger":
for (let i = 0; i < scales.length; i++) {
if (scales[i] > curScale.x) {
playerRig.object3D.scale.set(scales[i], scales[i], scales[i]);
break;
}
}
break;
case "smaller":
for (let i = scales.length - 1; i >= 0; i--) {
if (curScale.x > scales[i]) {
playerRig.object3D.scale.set(scales[i], scales[i], scales[i]);
break;
}
}
break;
case "leave":
this.entryManager.exitScene();
this.remountUI({ roomUnavailableReason: "left" });
break;
case "duck":
spawnChatMessage(DUCK_URL);