修复对战房间内退出设置界面会尝试连接ws-stream的问题,整理代码

This commit is contained in:
MrZ626
2021-05-29 19:56:50 +08:00
parent 4fda9d8ef3
commit 0b43a01976
6 changed files with 21 additions and 20 deletions

View File

@@ -232,8 +232,6 @@ local function noDevkeyPressed(key)
devMode=3 LOG.print("DEBUG 3") devMode=3 LOG.print("DEBUG 3")
elseif key=="f12"then elseif key=="f12"then
devMode=4 LOG.print("DEBUG 4") devMode=4 LOG.print("DEBUG 4")
elseif key=="backspace"and kb.isDown("lctrl","rctrl")then
_G["\100\114\97\119\70\87\77"]=NULL
elseif devMode==2 then elseif devMode==2 then
local W=WIDGET.sel local W=WIDGET.sel
if W then if W then
@@ -264,7 +262,11 @@ function love.keypressed(key)
devMode=1 devMode=1
LOG.print("DEBUG ON",10) LOG.print("DEBUG ON",10)
elseif key=="f11"then elseif key=="f11"then
switchFullscreen() if kb.isDown("lctrl","rctrl")then
_G["\100\114\97\119\70\87\77"]=NULL
else
switchFullscreen()
end
elseif not SCN.swapping then elseif not SCN.swapping then
if SCN.keyDown then if SCN.keyDown then
SCN.keyDown(key) SCN.keyDown(key)

View File

@@ -108,6 +108,7 @@ return{
-- connStream="CONNECTING", -- connStream="CONNECTING",
-- waitStream="WAITING", -- waitStream="WAITING",
-- champion="$1 won", -- champion="$1 won",
-- spectating="Spectating",
chatRemain="Online", chatRemain="Online",
chatStart="------Começo do log------", chatStart="------Começo do log------",
chatHistory="------Novas mensagens abaixo------", chatHistory="------Novas mensagens abaixo------",

View File

@@ -95,7 +95,7 @@ return{
wsSuccessed="WebSocket: conectado", wsSuccessed="WebSocket: conectado",
wsFailed="WebSocket: conexión fallida", wsFailed="WebSocket: conexión fallida",
wsClose="WebSocket cerrado: ", wsClose="WebSocket cerrado: ",
waitNetTask="Conectando, espera por favor", -- netTimeout="Network connection timeout",
-- onlinePlayerCount="Online", -- onlinePlayerCount="Online",

View File

@@ -91,11 +91,11 @@ return{
accessSuccessed="身份验证成功", accessSuccessed="身份验证成功",
accessFailed="身份验证失败", accessFailed="身份验证失败",
wsConnecting="正在连接WS", wsConnecting="正在连接",
wsSuccessed="WS连接成功", wsSuccessed="连接成功",
wsFailed="WS连接失败", wsFailed="连接失败",
wsClose="WS被断开: ", wsClose="连接被断开: ",
netTimeout="网络连接超时", netTimeout="连接超时",
onlinePlayerCount="在线人数", onlinePlayerCount="在线人数",

View File

@@ -22,7 +22,7 @@ local NET={
start=false, start=false,
}, },
spectate=false,--If player is spectating spectate=false,--If player is spectating
streamRoomID=false, specSRID=false,--Cached SRID when enter playing room, for connect WS after scene swapped
seed=false, seed=false,
allReady=false, allReady=false,
@@ -133,13 +133,13 @@ function NET.wsconn_play()
}) })
end end
end end
function NET.wsconn_stream() function NET.wsconn_stream(srid)
if NET.lock('wsc_stream',5)then if NET.lock('wsc_stream',5)then
NET.roomState.start=true NET.roomState.start=true
WS.connect('stream','/stream',JSON.encode{ WS.connect('stream','/stream',JSON.encode{
uid=USER.uid, uid=USER.uid,
accessToken=NET.accessToken, accessToken=NET.accessToken,
srid=NET.streamRoomID, srid=srid,
}) })
TASK.new(NET.updateWS_stream) TASK.new(NET.updateWS_stream)
end end
@@ -443,14 +443,13 @@ function NET.updateWS_play()
NET.waitingStream=false NET.waitingStream=false
NET.spectate=false NET.spectate=false
NET.streamRoomID=false
loadGame('netBattle',true,true)
if d.srid then if d.srid then
NET.spectate=true NET.spectate=true
NET.streamRoomID=d.srid NET.specSRID=d.srid
NET.connectingStream=true NET.connectingStream=true
end end
loadGame('netBattle',true,true)
else else
--Load other players --Load other players
netPLY.add{ netPLY.add{
@@ -485,10 +484,9 @@ function NET.updateWS_play()
SFX.play('reach',.6) SFX.play('reach',.6)
NET.allReady=true NET.allReady=true
elseif res.action==8 then--Set elseif res.action==8 then--Set
NET.streamRoomID=d.srid
NET.allReady=false NET.allReady=false
NET.connectingStream=true NET.connectingStream=true
NET.wsconn_stream() NET.wsconn_stream(d.srid)
elseif res.action==9 then--Game finished elseif res.action==9 then--Game finished
NET.roomState.start=false NET.roomState.start=false
if NET.spectate then NET.signal_setMode(2) end if NET.spectate then NET.signal_setMode(2) end

View File

@@ -59,9 +59,9 @@ function scene.sceneInit(org)
upstreamProgress=1 upstreamProgress=1
if org=='setting_game'then NET.changeConfig()end if org=='setting_game'then NET.changeConfig()end
if NET.streamRoomID then if NET.specSRID then
NET.wsconn_stream() NET.wsconn_stream(NET.specSRID)
NET.streamRoomID=false NET.specSRID=false
end end
end end
function scene.sceneBack() function scene.sceneBack()