summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-04-29 19:36:48 +0200
committerFxQnLr <[email protected]>2024-04-29 19:36:48 +0200
commitab76e442ab4fb4d41ccbc211f9ac05e19aaefd4b (patch)
tree20c5b52d8e2bb3a7ad00f6932d1a591bd22091fb /main.lua
parent9233e47a7afa1bee87c53b2bff22bfc5a862c435 (diff)
downloadfunsaac-ab76e442ab4fb4d41ccbc211f9ac05e19aaefd4b.tar
funsaac-ab76e442ab4fb4d41ccbc211f9ac05e19aaefd4b.tar.gz
funsaac-ab76e442ab4fb4d41ccbc211f9ac05e19aaefd4b.zip
connection, counter, messages and device scan
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua37
1 files changed, 24 insertions, 13 deletions
diff --git a/main.lua b/main.lua
index 40acc5b..31555ee 100644
--- a/main.lua
+++ b/main.lua
@@ -1,24 +1,35 @@
1---@diagnostic disable: duplicate-set-field
2
1local funsaac = RegisterMod("funsaac", 1) 3local funsaac = RegisterMod("funsaac", 1)
2local json = require("json") 4require("messages")
5
6local client = require("websocket").new("127.0.0.1", 12345, "/")
3 7
4local requestServerInfo = { 8CONNECTED = false
5 Id = 1,
6 ClientName = "Funsaac v.0.0.1",
7 MessageVersion = 3
8}
9 9
10local client = require("websocket").new("127.0.0.1", 12345)
11function client:onmessage(message) 10function client:onmessage(message)
12 print(message) 11 HandleResponse(ResponseContent(message))
12 if CONNECTED == true then
13 self:send(GetMessage(Messages.StartScanning))
14 CONNECTED = false
15 end
13end 16end
17
14function client:onopen() 18function client:onopen()
15 local msg = '[{"RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]" 19 self:send(GetMessage(Messages.RequestServerInfo))
16 print(msg)
17 self:send(msg)
18end 20end
19 21
20local function onUpdate() 22
23local render_tick = 0
24local s = 0;
25local function onRender()
21 client:update() 26 client:update()
27
28 render_tick = render_tick + 1
29 if render_tick >= 60 then
30 render_tick = 0
31 s = s + 1
32 end
22end 33end
23 34
24funsaac:AddCallback(ModCallbacks.MC_POST_UPDATE, onUpdate) \ No newline at end of file 35funsaac:AddCallback(ModCallbacks.MC_POST_RENDER, onRender) \ No newline at end of file