-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
freeze-controller.js
59 lines (54 loc) · 1.96 KB
/
freeze-controller.js
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
import { paths } from "../systems/userinput/paths";
import { SOUND_FREEZE, SOUND_THAW } from "../systems/sound-effects-system";
import { CAMERA_MODE_INSPECT } from "../systems/camera-system";
/**
* Toggles freezing of network traffic on the given event.
* @namespace network
* @component freeze-controller
*/
AFRAME.registerComponent("freeze-controller", {
init: function () {
this.onToggle = this.onToggle.bind(this);
},
tick: function () {
const scene = this.el.sceneEl;
if (!scene.is("entered")) return;
const inspecting = scene.systems["hubs-systems"].cameraSystem.mode === CAMERA_MODE_INSPECT;
if (inspecting) {
if (this.el.is("frozen")) {
this.onToggle();
}
if (!NAF.connection.adapter.frozen) {
NAF.connection.adapter.toggleFreeze();
}
this.wasInspecting = true;
} else if (this.wasInspecting) {
if (NAF.connection.adapter.frozen) {
NAF.connection.adapter.toggleFreeze();
}
this.wasInspecting = false;
} else {
const userinput = scene.systems.userinput;
const ensureFrozen = userinput.get(paths.actions.ensureFrozen);
const thaw = userinput.get(paths.actions.thaw);
const toggleFreeze = userinput.get(paths.actions.toggleFreeze);
const toggleFreezeDueToInput =
(this.el.is("frozen") && thaw) || (!this.el.is("frozen") && ensureFrozen) || toggleFreeze;
if (toggleFreezeDueToInput) {
this.onToggle();
}
}
},
onToggle: function () {
window.APP.store.update({ activity: { hasFoundFreeze: true } });
if (!NAF.connection.adapter) return;
NAF.connection.adapter.toggleFreeze();
if (NAF.connection.adapter.frozen) {
this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_FREEZE);
this.el.addState("frozen");
} else {
this.el.sceneEl.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_THAW);
this.el.removeState("frozen");
}
}
});