forked from wisq/ex_osc
/
jump.exs
56 lines (47 loc) · 994 Bytes
/
jump.exs
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
defmodule MyConsumer do
use GenStage
def init(:ok) do
{:consumer, nil}
end
def handle_events(events, {_, _}, state) do
events
|> Enum.each(fn event ->
handle_event(event)
end)
{:noreply, [], state}
end
defp handle_event(%VRChatOSC.OSC.Message{path: "/avatar/parameters/Grounded", args: [true]}) do
IO.puts("Grounded!")
VRChatOSC.send_message(
VRChatOSC.OSC,
path: "/input/Jump",
args: [1]
)
end
defp handle_event(%VRChatOSC.OSC.Message{path: "/avatar/parameters/Grounded", args: [false]}) do
IO.puts("Jumping!")
VRChatOSC.send_message(VRChatOSC.OSC,
path: "/input/Jump",
args: [0]
)
end
defp handle_event(_) do
# noop
end
end
{:ok, _osc} =
VRChatOSC.OSC.start_link(
vrchat: [
ip: {127, 0, 0, 1},
port: 9000
],
client: [
port: 9001
],
consumer: [
module: MyConsumer,
args: :ok,
opts: []
]
)
Process.sleep(:infinity)