From 1e223644295fd024f6618c7d893d2248b759cb91 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 8 Apr 2021 15:08:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B8=E7=8E=A9=E5=AE=B6=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E5=87=86=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/net.lua | 4 ++-- parts/scenes/net_game.lua | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/parts/net.lua b/parts/net.lua index ee47c9d5..11d33dc8 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -199,9 +199,9 @@ end function NET.checkPlayDisconn() return WS.status("play")~="running" end -function NET.signal_ready() +function NET.signal_ready(ready) if _lock("ready")then - WS.send("play",'{"action":6,"data":{"ready":true}}') + WS.send("play",'{"action":6,"data":{"ready":'..tostring(ready)..'}}') end end function NET.signal_quit() diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index ebf41cbf..4aea64c7 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -96,7 +96,7 @@ function scene.keyDown(key) end elseif key=="space"then if not NET.getLock("ready")then - NET.signal_ready() + NET.signal_ready(not PLAYERS[1].ready) end end end @@ -175,13 +175,17 @@ function scene.socketRead(cmd,data) end elseif cmd=="Ready"then if data.uid==USER.uid then - PLAYERS[1].ready=true - SFX.play("reach",.6) + if PLAYERS[1].ready~=data.ready then + PLAYERS[1].ready=data.ready + SFX.play("reach",.6) + end else for i=1,#PLAYERS do if PLAYERS[i].userID==data.uid then - PLAYERS[i].ready=true - SFX.play("reach",.6) + if PLAYERS[i].ready~=data.ready then + PLAYERS[i].ready=data.ready + SFX.play("reach",.6) + end break end end @@ -289,7 +293,12 @@ function scene.draw() end scene.widgetList={ textBox, - WIDGET.newKey{name="ready",x=640,y=440,w=200,h=80,color="yellow",font=40,code=pressKey"space",hide=function()return playing or not hideChatBox or PLAYERS[1].ready end}, + WIDGET.newKey{name="ready",x=640,y=440,w=200,h=80,color="yellow",font=40,code=pressKey"space",hide=function() + return + playing or + not hideChatBox or + NET.getLock("ready") + end}, WIDGET.newKey{name="hideChat",fText="...",x=380,y=35,w=60,font=35,code=pressKey"\\"}, WIDGET.newKey{name="quit",fText="X",x=900,y=35,w=60,font=40,code=pressKey"escape"}, }