From 3b82a144eaceb88b682927af45e4fc81ee8cc6e3 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 17 May 2021 00:59:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=9C=AC=E5=9C=B0=E5=92=8C?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=8F=90=E4=BE=9B=E7=9A=84=E6=88=BF?= =?UTF-8?q?=E9=97=B4=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F=EF=BC=88=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=EF=BC=9A=E5=92=8C=E6=97=A7=E7=89=88=E6=9C=AC=E4=B8=8D?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=EF=BC=89=EF=BC=8C=E4=BF=AE=E5=A4=8D=E2=80=9C?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E4=B8=AD=E2=80=9D=E6=A0=87=E8=AE=B0=E4=BC=9A?= =?UTF-8?q?=E8=A2=AB=E5=B8=A6=E5=88=B0=E5=88=AB=E7=9A=84=E6=88=BF=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/net.lua | 41 ++++++++++++++------------ parts/netPlayer.lua | 2 +- parts/scenes/net_game.lua | 10 +++---- parts/scenes/net_rooms.lua | 59 ++++++++++++++++++++++++-------------- 4 files changed, 66 insertions(+), 46 deletions(-) diff --git a/parts/net.lua b/parts/net.lua index 4c95feec..d1da9fd8 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -16,12 +16,12 @@ local NET={ private=false, -- count=false, capacity=false, + allReady=false, + connectingStream=false, + waitingStream=false, start=false, }, - allReady=false, connectingStream=false, - waitingStream=false, - serverGaming=false, streamRoomID=false, UserCount="_", @@ -130,7 +130,7 @@ function NET.wsconn_play() end function NET.wsconn_stream() if NET.lock('wsc_stream',5)then - NET.serverGaming=true + NET.roomInfo.start=true WS.connect('stream','/stream',JSON.encode{ uid=USER.uid, accessToken=NET.accessToken, @@ -145,7 +145,7 @@ function NET.wsclose_app()WS.close('app')end function NET.wsclose_user()WS.close('user')end function NET.wsclose_play()WS.close('play')end function NET.wsclose_stream() - NET.serverGaming=false + NET.roomInfo.start=false WS.close('stream') end @@ -223,10 +223,15 @@ function NET.createRoom(roomName,capacity,roomType,password) WS.send('play',JSON.encode{ action=1, data={ - name=roomName, capacity=capacity, - roomData={type=roomType}, password=password, + roomInfo={ + name=roomName, + type=roomType, + version=VERSION.code, + }, + roomData={_=0}, + config=dumpBasicConfig(), } }) @@ -235,8 +240,8 @@ end function NET.enterRoom(room,password) if NET.lock('enterRoom',1.26)then SFX.play('reach',.6) - NET.roomInfo.name=room.name - NET.roomInfo.type=room.type + NET.roomInfo.name=room.roomInfo.name + NET.roomInfo.type=room.roomInfo.type NET.roomInfo.private=not not password NET.roomInfo.capacity=room.capacity NET.roomInfo.start=room.start @@ -267,7 +272,7 @@ function NET.changeConfig() WS.send('play','{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}') end function NET.signal_ready(ready) - if NET.lock('ready',3)and not NET.serverGaming then + if NET.lock('ready',3)and not NET.roomInfo.start then WS.send('play','{"action":6,"data":{"ready":'..tostring(ready)..'}}') end end @@ -428,7 +433,7 @@ function NET.updateWS_play() } end end - --TODO: d.roomData (json) + --TODO: d.roomInfo,d.roomData (json) loadGame('netBattle',true,true) else --Load other players @@ -440,7 +445,7 @@ function NET.updateWS_play() config=d.config, } if SCN.socketRead then SCN.socketRead('join',d)end - NET.allReady=false + NET.roomInfo.allReady=false end elseif res.action==3 then--Player leave if not d.uid then @@ -462,11 +467,11 @@ function NET.updateWS_play() netPLY.setReady(d.uid,d.ready) elseif res.action==7 then--All Ready SFX.play('reach',.6) - NET.allReady=true + NET.roomInfo.allReady=true elseif res.action==8 then--Set NET.streamRoomID=d.rid - NET.allReady=false - NET.connectingStream=true + NET.roomInfo.allReady=false + NET.roomInfo.connectingStream=true NET.wsconn_stream() elseif res.action==9 then--Game finished NET.wsclose_stream() @@ -499,12 +504,12 @@ function NET.updateWS_stream() local d=res.data if res.type=='Connect'then NET.unlock('wsc_stream') - NET.connectingStream=false - NET.waitingStream=true + NET.roomInfo.connectingStream=false + NET.roomInfo.waitingStream=true netPLY.setConnect(USER.uid) netPLY.freshStreamConn(res.data.connected) elseif res.action==0 then--Game start - NET.waitingStream=false + NET.roomInfo.waitingStream=false NET.roomInfo.start=true if SCN.socketRead then SCN.socketRead('go',d)end elseif res.action==1 then--Game finished diff --git a/parts/netPlayer.lua b/parts/netPlayer.lua index cca53c2a..ebc17c55 100644 --- a/parts/netPlayer.lua +++ b/parts/netPlayer.lua @@ -108,7 +108,7 @@ function netPLY.setReady(uid,ready) if p.uid==uid then if p.ready~=ready then p.ready=ready - if not ready then NET.allReady=false end + if not ready then NET.roomInfo.allReady=false end SFX.play('spin_0',.6) if i==1 then NET.unlock('ready') diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index 204137a9..4b5a2cf1 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -273,13 +273,13 @@ function scene.draw() --Ready & Set mark setFont(50) - if NET.allReady then + if NET.roomInfo.allReady then gc.setColor(0,1,.5,.9) mStr(text.ready,640,15) - elseif NET.connectingStream then + elseif NET.roomInfo.connectingStream then gc.setColor(.1,1,.8,.9) mStr(text.connStream,640,15) - elseif NET.waitingStream then + elseif NET.roomInfo.waitingStream then gc.setColor(0,.8,1,.9) mStr(text.waitStream,640,15) end @@ -315,7 +315,7 @@ scene.widgetList={ hideF=function() return playing or - NET.serverGaming or + NET.roomInfo.start or netPLY.getSelfReady()or NET.getlock('ready') end}, @@ -323,7 +323,7 @@ scene.widgetList={ hideF=function() return playing or - NET.serverGaming or + NET.roomInfo.start or not netPLY.getSelfReady()or NET.getlock('ready') end}, diff --git a/parts/scenes/net_rooms.lua b/parts/scenes/net_rooms.lua index c931d2a1..92425f4e 100644 --- a/parts/scenes/net_rooms.lua +++ b/parts/scenes/net_rooms.lua @@ -8,6 +8,18 @@ local scrollPos,selected local fetchTimer local lastCreateRoomTime=0 +--[[room={ + rid="qwe", + roomInfo={ + name="MrZ's room", + type="classic", + version=1409, + }, + private=false, + start=false, + count=4, + capacity=5, +}]] local function fetchRoom() fetchTimer=5 NET.fetchRoom() @@ -17,9 +29,9 @@ local scene={} function scene.sceneInit() BG.set() - NET.allReady=false - NET.connectingStream=false - NET.waitingStream=false + NET.roomInfo.allReady=false + NET.roomInfo.connectingStream=false + NET.roomInfo.waitingStream=false scrollPos=0 selected=1 fetchRoom() @@ -74,11 +86,10 @@ function scene.keyDown(k) end elseif k=="return"then if NET.getlock('fetchRoom')or not NET.roomList[selected]then return end - if NET.roomList[selected].private then - LOG.print("Can't enter private room now",'message') - return - end - NET.enterRoom(NET.roomList[selected])--,password + local R=NET.roomList[selected] + if R.roomInfo.version~=VERSION.code then LOG.print("Version doesn't match",'message')return end + if R.private then LOG.print("Can't enter private room now",'message')return end + NET.enterRoom(R)--,password end end end @@ -137,6 +148,10 @@ function scene.draw() gc.rectangle('line',50,110,1060,400) local roomCount=#NET.roomList if roomCount>0 then + if roomCount>10 then + local len=400*10/roomCount + gc.rectangle('fill',1097,110+(400-len)*scrollPos/(roomCount-10),12,len) + end setFont(35) gc.push('transform') gc.stencil(roomListStencil,'replace',1) @@ -149,27 +164,27 @@ function scene.draw() gc.setColor(1,1,1,.3) gc.rectangle('fill',50,70+40*i,1060,40) end - if R.start then - gc.setColor(0,1,0) - gc.print(text.started,660,66+40*i) + gc.setColor(1,1,1) + if R.private then gc.draw(IMG.lock,60,75+40*i)end + gc.printf(R.roomInfo.type,440,66+40*i,500,'right') + gc.print(R.count.."/"..R.capacity,980,66+40*i) + if R.roomInfo.version~=VERSION.code then + gc.setColor(1,.2,0) + gc.print("V"..R.roomInfo.version,600,66+40*i) end + gc.setColor(.9,.9,1) gc.print(pos+i,95,66+40*i) - gc.setColor(1,1,.7) - gc.print(R.name,250,66+40*i) - gc.setColor(1,1,1) - gc.printf(R.type,430,66+40*i,500,'right') - gc.print(R.count.."/"..R.capacity,980,66+40*i) - if R.private then - gc.draw(IMG.lock,59,75+40*i) + + if R.start then + gc.setColor(0,.4,.05) + else + gc.setColor(1,1,.7) end + gc.print(R.roomInfo.name,250,66+40*i) end gc.setStencilTest() gc.pop() - if roomCount>10 then - local len=400*10/roomCount - gc.rectangle('fill',1218,110+(400-len)*scrollPos/(roomCount-10),12,len) - end end --Profile