修改房间准备状态变量修改条件,减少出现问题状态的可能性

This commit is contained in:
MrZ626
2021-06-24 14:26:14 +08:00
parent 096f162ea6
commit 36a30a6318
3 changed files with 15 additions and 18 deletions

View File

@@ -25,9 +25,7 @@ local NET={
specSRID=false,--Cached SRID when enter playing room, for connect WS after scene swapped specSRID=false,--Cached SRID when enter playing room, for connect WS after scene swapped
seed=false, seed=false,
allReady=false, roomReadyState=false,
connectingStream=false,
waitingStream=false,
UserCount="_", UserCount="_",
PlayCount="_", PlayCount="_",
@@ -535,16 +533,14 @@ function NET.updateWS_play()
NET.roomState.private=d.private NET.roomState.private=d.private
NET.roomState.start=d.start NET.roomState.start=d.start
NET.allReady=false NET.roomReadyState=false
NET.connectingStream=false
NET.waitingStream=false
NET.spectate=false NET.spectate=false
if d.srid then if d.srid then
NET.spectate=true NET.spectate=true
NET.specSRID=d.srid NET.specSRID=d.srid
NET.connectingStream=true NET.roomReadyState='connecting'
end end
loadGame('netBattle',true,true) loadGame('netBattle',true,true)
else else
@@ -557,7 +553,9 @@ function NET.updateWS_play()
config=d.config, config=d.config,
} }
if SCN.cur=='net_game'then SCN.socketRead('join',d)end if SCN.cur=='net_game'then SCN.socketRead('join',d)end
NET.allReady=false if NET.roomReadyState=='allReady'then
NET.roomReadyState=false
end
end end
elseif res.action==3 then--Player leave elseif res.action==3 then--Player leave
if not d.uid then if not d.uid then
@@ -579,10 +577,9 @@ function NET.updateWS_play()
netPLY.setJoinMode(d.uid,d.mode) netPLY.setJoinMode(d.uid,d.mode)
elseif res.action==7 then--All Ready elseif res.action==7 then--All Ready
SFX.play('reach',.6) SFX.play('reach',.6)
NET.allReady=true NET.roomReadyState='allReady'
elseif res.action==8 then--Set elseif res.action==8 then--Set
NET.allReady=false NET.roomReadyState='connecting'
NET.connectingStream=true
NET.wsconn_stream(d.srid) NET.wsconn_stream(d.srid)
elseif res.action==9 then--Game finished elseif res.action==9 then--Game finished
if SCN.cur=='net_game'then SCN.socketRead('finish',d)end if SCN.cur=='net_game'then SCN.socketRead('finish',d)end
@@ -629,9 +626,9 @@ function NET.updateWS_stream()
local d=res.data local d=res.data
if res.type=='Connect'then if res.type=='Connect'then
NET.unlock('wsc_stream') NET.unlock('wsc_stream')
NET.connectingStream=false NET.roomReadyState=false
elseif res.action==0 then--Game start elseif res.action==0 then--Game start
NET.waitingStream=false NET.roomReadyState=false
SCN.socketRead('go') SCN.socketRead('go')
elseif res.action==1 then--Game finished elseif res.action==1 then--Game finished
--? --?
@@ -655,7 +652,7 @@ function NET.updateWS_stream()
end end
end end
else else
NET.waitingStream=true NET.roomReadyState='waitConn'
end end
else else
if d.spectate then if d.spectate then

View File

@@ -124,7 +124,7 @@ function netPLY.setJoinMode(uid,ready)
if p.uid==uid then if p.uid==uid then
if p.mode~=ready then if p.mode~=ready then
p.mode=ready p.mode=ready
if ready==0 then NET.allReady=false end if ready==0 then NET.roomReadyState=false end
SFX.play('spin_0',.6) SFX.play('spin_0',.6)
if p.uid==USER.uid then if p.uid==USER.uid then
NET.unlock('ready') NET.unlock('ready')

View File

@@ -287,13 +287,13 @@ function scene.draw()
--Ready & Set mark --Ready & Set mark
setFont(50) setFont(50)
if NET.allReady then if NET.roomReadyState=='allReady'then
gc_setColor(0,1,.5,.9) gc_setColor(0,1,.5,.9)
mStr(text.ready,640,15) mStr(text.ready,640,15)
elseif NET.connectingStream then elseif NET.roomReadyState=='connecting'then
gc_setColor(.1,1,.8,.9) gc_setColor(.1,1,.8,.9)
mStr(text.connStream,640,15) mStr(text.connStream,640,15)
elseif NET.waitingStream then elseif NET.roomReadyState=='waitConn'then
gc_setColor(0,.8,1,.9) gc_setColor(0,.8,1,.9)
mStr(text.waitStream,640,15) mStr(text.waitStream,640,15)
end end