把所有网络操作抽象到NET中

This commit is contained in:
MrZ626
2021-03-28 21:08:15 +08:00
parent 35ac6eacbc
commit 4222fff2e3
8 changed files with 105 additions and 73 deletions

View File

@@ -3,12 +3,12 @@ local data=love.data
local textBox=WIDGET.newTextBox{name="texts",x=40,y=50,w=1200,h=430}
local remain--People in chat room
local heartBeatTimer
local escapeTimer=0
local function sendMessage()
local W=WIDGET.active.input
if #W.value>0 and WS.send("chat","T"..data.encode("string","base64",W.value))then
if #W.value>0 then
NET.sendChatMes(W.value)
W.value=""
end
end
@@ -16,7 +16,6 @@ end
local scene={}
function scene.sceneInit()
heartBeatTimer=0
remain=false
local texts=textBox.texts
@@ -30,7 +29,7 @@ function scene.sceneInit()
BG.set("none")
end
function scene.sceneBack()
WS.send("chat","Q")
NET.quitChat()
LOG.print(text.wsDisconnected,"warn")
end
@@ -80,13 +79,6 @@ function scene.socketRead(mes)
end
end
function scene.update(dt)
heartBeatTimer=heartBeatTimer+dt
if heartBeatTimer>42 then
heartBeatTimer=0
WS.send("chat","P")
end
end
function scene.draw()
setFont(25)
gc.setColor(1,1,1)