From c8480a17e9775f8d643603be7a5169d39cba26d2 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Fri, 25 Jun 2021 20:20:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E5=86=8D=E6=AC=A1=E4=BC=98=E5=8C=96=E4=B8=BB=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E8=81=94=E7=BD=91=E6=B8=B8=E6=88=8F=E6=8C=89=E9=92=AE=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=EF=BC=8C=E8=BF=9E=E6=8E=A5=E8=BF=87=E7=A8=8B=E4=B8=AD?= =?UTF-8?q?=E4=B8=8D=E5=85=81=E8=AE=B8=E5=88=87=E5=8E=BB=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/screen.lua | 2 +- parts/net.lua | 45 +++++++++++++++++++------------------------ parts/scenes/main.lua | 23 +++++++++++++++++----- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/Zframework/screen.lua b/Zframework/screen.lua index 84169ac4..08863769 100644 --- a/Zframework/screen.lua +++ b/Zframework/screen.lua @@ -13,8 +13,8 @@ local SCR={ --Screen transformation objects origin=love.math.newTransform(), - xOy_m=love.math.newTransform(), xOy=love.math.newTransform(), + xOy_m=love.math.newTransform(), xOy_ul=love.math.newTransform(), xOy_u=love.math.newTransform(), xOy_ur=love.math.newTransform(), diff --git a/parts/net.lua b/parts/net.lua index c20e20ff..e728e973 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -119,13 +119,13 @@ end --Connect function NET.wsconn_app() - WS.connect('app','/app') - TASK.new(NET.updateWS_app) - TASK.new(NET.freshPlayerCount) + if WS.status('app')=='dead'then + WS.connect('app','/app',nil,6) + TASK.new(NET.updateWS_app) + end end function NET.wsconn_user_pswd(email,password) - if WS.status('wsc_user')=='dead'then NET.unlock('wsc_user')end - if NET.lock('wsc_user',5)then + if WS.status('user')=='dead'then WS.connect('user','/user',JSON.encode{ email=email, password=password, @@ -134,8 +134,7 @@ function NET.wsconn_user_pswd(email,password) end end function NET.wsconn_user_token(uid,authToken) - if WS.status('wsc_user')=='dead'then NET.unlock('wsc_user')end - if NET.lock('wsc_user',5)then + if WS.status('user')=='dead'then WS.connect('user','/user',JSON.encode{ uid=uid, authToken=authToken, @@ -144,8 +143,7 @@ function NET.wsconn_user_token(uid,authToken) end end function NET.wsconn_play() - if WS.status('wsc_play')=='dead'then NET.unlock('wsc_play')end - if NET.lock('wsc_play',5)then + if WS.status('play')=='dead'then WS.connect('play','/play',JSON.encode{ uid=USER.uid, accessToken=NET.accessToken, @@ -154,23 +152,22 @@ function NET.wsconn_play() end end function NET.wsconn_stream(srid) - if NET.lock('wsc_stream',5)then + if WS.status('stream')=='dead'then NET.roomState.start=true WS.connect('stream','/stream',JSON.encode{ uid=USER.uid, accessToken=NET.accessToken, srid=srid, - },10) + },6) TASK.new(NET.updateWS_stream) end end function NET.wsconn_manage() - if WS.status('wsc_manage')=='dead'then NET.unlock('wsc_manage')end - if NET.lock('wsc_manage',5)then + if WS.status('manage')=='dead'then WS.connect('manage','/manage',JSON.encode{ uid=USER.uid, authToken=USER.authToken, - },10) + },6) TASK.new(NET.updateWS_manage) end end @@ -201,7 +198,9 @@ end function NET.tryLogin(ifAuto) if NET.allow_online then if WS.status('user')=='running'then - NET.getAccessToken() + if NET.lock('access_and_login',8)then + WS.send('user',JSON.encode{action=0}) + end elseif not ifAuto then SCN.go('login') end @@ -210,11 +209,6 @@ function NET.tryLogin(ifAuto) SFX.play('finesseError') end end -function NET.getAccessToken() - if NET.lock('access_and_login',10)then - WS.send('user',JSON.encode{action=0}) - end -end function NET.getUserInfo(uid) WS.send('user',JSON.encode{ action=1, @@ -227,7 +221,7 @@ end --Save function NET.uploadSave() - if NET.lock('uploadSave',10)then + if NET.lock('uploadSave',8)then WS.send('user','{"action":2,"data":{"sections":'..JSON.encode{ {section=1,data=STRING.packTable(STAT)}, {section=2,data=STRING.packTable(RANKS)}, @@ -241,7 +235,7 @@ function NET.uploadSave() end end function NET.downloadSave() - if NET.lock('downloadSave',10)then + if NET.lock('downloadSave',8)then WS.send('user','{"action":3,"data":{"sections":[1,2,3,4,5,6,7]}}') MES.new('info',"Downloading") end @@ -305,7 +299,7 @@ function NET.fetchRoom() end end function NET.createRoom(roomName,description,capacity,roomType,roomData,password) - if NET.lock('enterRoom',1.26)then + if NET.lock('enterRoom',2)then NET.roomState.private=not not password NET.roomState.capacity=capacity WS.send('play',JSON.encode{ @@ -327,7 +321,7 @@ function NET.createRoom(roomName,description,capacity,roomType,roomData,password end end function NET.enterRoom(room,password) - if NET.lock('enterRoom',1.26)then + if NET.lock('enterRoom',2)then SFX.play('reach',.6) WS.send('play',JSON.encode{ action=2, @@ -377,7 +371,7 @@ end --WS tick funcs function NET.freshPlayerCount() - while WS.status('app')~='dead'do + while WS.status('app')=='running'do for _=1,260 do yield()end WS.send('app',JSON.encode{action=3}) end @@ -410,6 +404,7 @@ function NET.updateWS_app() end MES.new('broadcast',res.notice,5) NET.tryLogin(true) + TASK.new(NET.freshPlayerCount) elseif res.action==0 then--Broadcast MES.new('broadcast',res.data.message,5) elseif res.action==1 then--Get notice diff --git a/parts/scenes/main.lua b/parts/scenes/main.lua index 65bc1fde..3ddcf5bb 100644 --- a/parts/scenes/main.lua +++ b/parts/scenes/main.lua @@ -46,10 +46,14 @@ function scene.mouseDown(x,y) end scene.touchDown=scene.mouseDown local function testButton(n) - if WIDGET.isFocus(scene.widgetList[n])then - return true + if NET.getlock('access_and_login')then + MES.new('warn',text.wsConnecting) else - WIDGET.focus(scene.widgetList[n]) + if WIDGET.isFocus(scene.widgetList[n])then + return true + else + WIDGET.focus(scene.widgetList[n]) + end end end function scene.keyDown(key,isRep) @@ -66,10 +70,11 @@ function scene.keyDown(key,isRep) if testButton(3)then if WS.status('app')=='running'then NET.tryLogin(false) - else - NET.wsconn_app() MES.new('info',text.wsConnecting) + elseif WS.status('app')=='dead'then + NET.wsconn_app() SFX.play('connect') + MES.new('info',text.wsConnecting) end end elseif key=="z"then @@ -159,6 +164,14 @@ function scene.draw() --Player count drawOnlinePlayerCount() + + --Connecting mark + if NET.getlock('access_and_login')then + gc.setColor(1,1,1) + gc.setLineWidth(10) + local t=TIME()*6.26%6.2832 + gc.arc('line','open',scene.widgetList[3].x+865,450,40,t,t+4.26) + end end scene.widgetList={