forked from Hubs-Foundation/hubs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
print-bindings.mjs
167 lines (149 loc) · 5.23 KB
/
print-bindings.mjs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { paths } from "../msrc/src/systems/userinput/paths";
function capitalize(str) {
return str && str[0].toUpperCase() + str.substring(1);
}
function fromCamelCase(str) {
return capitalize(str.replace(/([^A-Z])([A-Z])/g, "$1 $2").toLowerCase());
}
function pretty(str) {
const words = fromCamelCase(str)
.replace(/keyboard-var/, "keyboard")
.replace(/vive-var/, "keyboard")
.replace(/pressed2/, "pressed")
.replace(/joy y2/, "joy y")
.replace(/_vec2/, "")
.replace(/rising/, "pressed")
.replace(/falling/, "released")
.split("/")
.slice(2);
words[0] = capitalize(words[0]);
return words.join(" ");
}
function prettyXform(xform) {
return capitalize(fromCamelCase(xform.replace("falling", "released")));
}
function getSources(src) {
if (src instanceof Array) {
return src;
} else {
return Object.values(src);
}
}
const excludeXforms = [
"always",
"any",
"compose_vec2",
"copy",
"copyIfTrue",
"max_vec2",
"normalize_vec2",
"rising",
"risingWithFrameDelay",
"scale",
"touch_axis_scroll"
];
function getPaths(set, dest) {
const paths = [];
for (const binding of set) {
if (!(binding.dest && binding.dest.value)) continue;
if (!binding.src) continue;
if (binding.dest.value === dest) {
if (!excludeXforms.includes(binding.xform.name)) paths.push(prettyXform(binding.xform.name));
for (const src of getSources(binding.src)) {
const subPaths = getPaths(set, src);
if (subPaths) paths.push(subPaths);
}
}
}
if (paths.length === 0) {
return pretty(dest);
}
if (paths.length === 1 && typeof paths[0] === "string") {
return paths[0];
}
return paths;
}
const exclude = [
paths.actions.cameraDelta,
paths.actions.cursor.right.stopDrawing,
paths.actions.leftHand.index,
paths.actions.leftHand.middleRingPinky,
paths.actions.leftHand.pose,
paths.actions.leftHand.stopDrawing,
paths.actions.leftHand.stopTeleport,
paths.actions.leftHand.thumb,
paths.actions.rightHand.index,
paths.actions.rightHand.middleRingPinky,
paths.actions.rightHand.pose,
paths.actions.rightHand.stopDrawing,
paths.actions.rightHand.stopTeleport,
paths.actions.rightHand.thumb,
paths.actions.stopGazeTeleport,
paths.actions.thaw
];
function quoteLast(sentence) {
const words = sentence.split(" ");
if (words.length < 2) return words[0];
return `${words[0]} "${words.slice(1).join(" ")}"`;
}
function formatSource(source, indent) {
if (typeof source === "string") return indent + quoteLast(source);
if (source.every(x => typeof x === "string")) return source.map(x => indent + " " + quoteLast(x)).join("\n");
return source.map(x => formatSource(x, indent + " ")).join("\n") + "\n";
}
function formatSources(sources) {
const indent = " ";
if (sources.length === 1 && typeof sources[0] === "string") {
return indent + quoteLast(sources[0]);
} else if (typeof sources === "string") {
return indent + quoteLast(sources);
} else {
return sources.map(x => formatSource(x, indent)).join("\n");
}
}
function flatten(arr) {
if (arr.length === 1) {
return flatten(arr[0]);
}
return arr;
}
function printSet(set) {
for (const binding of set) {
if (!(binding.dest && binding.dest.value)) continue;
const dest = binding.dest.value;
if (!dest.includes("/actions/") || exclude.includes(dest)) continue;
if (!binding.src) continue;
console.log(
"\n [" + pretty(binding.dest.value) + "]",
"\n" +
(excludeXforms.includes(binding.xform.name) ? "" : " " + prettyXform(binding.xform.name) + "\n") +
formatSources(flatten(getSources(binding.src).map(src => flatten(getPaths(set, src)))))
);
}
}
function printBindings(bindingsName, bindings) {
console.log("\n" + fromCamelCase(bindingsName));
for (const setName in bindings) {
console.log("\n <" + fromCamelCase(setName) + ">");
printSet(bindings[setName]);
}
}
import { touchscreenUserBindings } from "../msrc/src/systems/userinput/bindings/touchscreen-user";
import { keyboardMouseUserBindings } from "../msrc/src/systems/userinput/bindings/keyboard-mouse-user";
import { oculusTouchUserBindings } from "../msrc/src/systems/userinput/bindings/oculus-touch-user";
import { viveUserBindings } from "../msrc/src/systems/userinput/bindings/vive-user";
import generate3DOFTriggerBindings from "../msrc/src/systems/userinput/bindings/oculus-go-user";
import { daydreamUserBindings } from "../msrc/src/systems/userinput/bindings/daydream-user";
import { xboxControllerUserBindings } from "../msrc/src/systems/userinput/bindings/xbox-controller-user";
const oculusGoUserBindings = generate3DOFTriggerBindings(paths.device.oculusgo);
const gearVRControllerUserBindings = generate3DOFTriggerBindings(paths.device.gearVRController);
[
["touchscreenUserBindings", touchscreenUserBindings],
["keyboardMouseUserBindings", keyboardMouseUserBindings],
["oculusTouchUserBindings", oculusTouchUserBindings],
["viveUserBindings", viveUserBindings],
["oculusGoUserBindings", oculusGoUserBindings],
["daydreamUserBindings", daydreamUserBindings],
["gearVRControllerUserBindings", gearVRControllerUserBindings],
["xboxControllerUserBindings", xboxControllerUserBindings]
].forEach(([name, bindings]) => printBindings(name, bindings));