整理代码,把旧的wsWrite函数先改成新的WS.send,非最终稿

This commit is contained in:
MrZ626
2021-02-22 01:10:25 +08:00
parent 7d90a4dcfc
commit a8119bc9dd
4 changed files with 11 additions and 13 deletions

View File

@@ -1752,7 +1752,7 @@ function Player.lose(P,force)
gameOver() gameOver()
P:newTask(#PLAYERS>1 and tick_lose or tick_finish) P:newTask(#PLAYERS>1 and tick_lose or tick_finish)
if GAME.net then if GAME.net then
wsWrite("D") WS.send("play","D")
else else
TASK.new(tick_autoPause) TASK.new(tick_autoPause)
end end

View File

@@ -12,7 +12,7 @@ local function _init()
end end
local function sendMessage() local function sendMessage()
local W=WIDGET.active.input local W=WIDGET.active.input
if #W.value>0 and wsWrite("T"..data.encode("string","base64",W.value))then if #W.value>0 and WS.send("chat","T"..data.encode("string","base64",W.value))then
W.value="" W.value=""
end end
end end
@@ -31,11 +31,10 @@ function scene.sceneInit()
end end
textBox:scroll(1) textBox:scroll(1)
TASK.new(_init)--Widgets are not initialized, so active after 1 frame TASK.new(_init)--Widgets are not initialized, so active after 1 frame
TASK.new(TICK_wsRead)
BG.set("none") BG.set("none")
end end
function scene.sceneBack() function scene.sceneBack()
wsWrite("Q") WS.send("chat","Q")
WSCONN=false WSCONN=false
LOG.print(text.wsDisconnected,"warn") LOG.print(text.wsDisconnected,"warn")
end end
@@ -90,7 +89,7 @@ function scene.update(dt)
heartBeatTimer=heartBeatTimer+dt heartBeatTimer=heartBeatTimer+dt
if heartBeatTimer>42 then if heartBeatTimer>42 then
heartBeatTimer=0 heartBeatTimer=0
wsWrite("P") WS.send("chat","P")
end end
end end
function scene.draw() function scene.draw()

View File

@@ -31,14 +31,13 @@ local touchMoveLastFrame=false
local scene={} local scene={}
function scene.sceneBack() function scene.sceneBack()
wsWrite("Q") WS.send("play","Q")
WSCONN=false WSCONN=false
LOG.print(text.wsDisconnected,"warn") LOG.print(text.wsDisconnected,"warn")
love.keyboard.setKeyRepeat(true) love.keyboard.setKeyRepeat(true)
end end
function scene.sceneInit() function scene.sceneInit()
love.keyboard.setKeyRepeat(false) love.keyboard.setKeyRepeat(false)
TASK.new(TICK_wsRead)
hideChatBox=true hideChatBox=true
playerInitialized=false playerInitialized=false
textBox:clear() textBox:clear()
@@ -110,7 +109,7 @@ function scene.keyDown(key)
end end
elseif key=="space"then elseif key=="space"then
if not PLAYERS[1].ready then if not PLAYERS[1].ready then
wsWrite("R") WS.send("play","R")
end end
end end
end end
@@ -270,7 +269,7 @@ function scene.update(dt)
heartBeatTimer=heartBeatTimer+dt heartBeatTimer=heartBeatTimer+dt
if heartBeatTimer>42 then if heartBeatTimer>42 then
heartBeatTimer=0 heartBeatTimer=0
wsWrite("P") WS.send("play","P")
end end
return return
end end
@@ -293,7 +292,7 @@ function scene.update(dt)
local stream local stream
stream,upstreamProgress=dumpRecording(GAME.rep,upstreamProgress) stream,upstreamProgress=dumpRecording(GAME.rep,upstreamProgress)
if #stream>0 then if #stream>0 then
wsWrite("S"..data.encode("string","base64",stream)) WS.send("stream",data.encode("string","base64",stream))
else else
ins(GAME.rep,GAME.frame) ins(GAME.rep,GAME.frame)
ins(GAME.rep,0) ins(GAME.rep,0)

View File

@@ -8,7 +8,7 @@ local lastCreateRoomTime=0
local function enterRoom(roomID) local function enterRoom(roomID)
--[[TODO --[[TODO
wsWrite("???",json.encode{ WS.connect("play","/play",json.encode{
email=USER.email, email=USER.email,
token=USER.access_token, token=USER.access_token,
id=roomID, id=roomID,
@@ -21,7 +21,7 @@ local function fresh()
lastfreshTime=TIME() lastfreshTime=TIME()
rooms=nil rooms=nil
--[[TODO --[[TODO
wsWrite("???",json.encode{ WS.connect("play","/play",json.encode{
email=USER.email, email=USER.email,
access_token=USER.access_token, access_token=USER.access_token,
}) })
@@ -48,7 +48,7 @@ function scene.keyDown(k)
elseif k=="n"then elseif k=="n"then
if TIME()-lastCreateRoomTime>26 then if TIME()-lastCreateRoomTime>26 then
--[[TODO --[[TODO
wsWrite("???",json.encode{ WS.send("room",json.encode{
email=USER.email, email=USER.email,
access_token=USER.access_token, access_token=USER.access_token,
room_name=(USER.name or"???").."'s room", room_name=(USER.name or"???").."'s room",