整理网络相关全局变量放入NET,删除WSCONN,调整进入联网菜单的逻辑

This commit is contained in:
MrZ626
2021-03-28 02:40:49 +08:00
parent 0cc6840506
commit d34627fab6
6 changed files with 27 additions and 22 deletions

View File

@@ -1,3 +1,5 @@
-- local host="192.168.114.102"
-- local host="127.0.0.1"
local host="hdustea.3322.org" local host="hdustea.3322.org"
local port="10026" local port="10026"
local path="/tech/socket/v1" local path="/tech/socket/v1"

View File

@@ -25,8 +25,10 @@ LOADED=false
DAILYLAUNCH=false DAILYLAUNCH=false
LOGIN=false LOGIN=false
EDITING="" EDITING=""
WSCONN=false NET={
ALLOW_ONLINE=false allow_online=false,
try_enter_netmenu=false,
}
ERRDATA={} ERRDATA={}
--System setting --System setting

View File

@@ -1130,7 +1130,7 @@ do
else else
local res=JSON.decode(message) local res=JSON.decode(message)
if VERSION_CODE>=res.lowest then if VERSION_CODE>=res.lowest then
ALLOW_ONLINE=true NET.allow_online=true
end end
if VERSION_CODE<res.newestCode then if VERSION_CODE<res.newestCode then
LOG.print(text.oldVersion:gsub("$1",res.newestName),180,COLOR.sky) LOG.print(text.oldVersion:gsub("$1",res.newestName),180,COLOR.sky)
@@ -1168,7 +1168,8 @@ do
if res.id then if res.id then
USER.id=res.id USER.id=res.id
USER.authToken=res.authToken USER.authToken=res.authToken
SCN.go("net_menu") NET.try_enter_netmenu=true
WS.send("user",JSON.encode{action=0})
end end
FILE.save(USER,"conf/user","q") FILE.save(USER,"conf/user","q")
LOG.print(text.loginSuccessed) LOG.print(text.loginSuccessed)
@@ -1183,6 +1184,10 @@ do
elseif res.action==0 then elseif res.action==0 then
USER.accessToken=res.accessToken USER.accessToken=res.accessToken
LOG.print(text.accessSuccessed) LOG.print(text.accessSuccessed)
if NET.try_enter_netmenu then
NET.try_enter_netmenu=false
SCN.go("net_menu")
end
elseif res.action==1 then elseif res.action==1 then
USER.name=res.username USER.name=res.username
USER.motto=res.motto USER.motto=res.motto

View File

@@ -77,14 +77,13 @@ function scene.keyDown(key)
end end
elseif key=="a"then elseif key=="a"then
if testButton(3)then if testButton(3)then
if not ALLOW_ONLINE then if LOGIN then
TEXT.show(text.notFinished,640,450,60,"flicker") if not NET.allow_online then
SFX.play("finesseError") TEXT.show(text.needUpdate,640,450,60,"flicker")
elseif LOGIN then SFX.play("finesseError")
SCN.go("net_menu") else
WS.send("user",JSON.encode{ WS.send("user",JSON.encode{action=0})
action=0, end
})
else else
SCN.go("login") SCN.go("login")
end end
@@ -109,18 +108,18 @@ function scene.keyDown(key)
if testButton(8)then if testButton(8)then
SCN.go("manual") SCN.go("manual")
end end
elseif key=="f1"then elseif key=="2"then
if testButton(11)then
SCN.go("about")
end
elseif key=="f2"then
if testButton(9)then if testButton(9)then
SCN.go("music") SCN.go("music")
end end
elseif key=="f3"then elseif key=="0"then
if testButton(10)then if testButton(10)then
SCN.go("lang") SCN.go("lang")
end end
elseif key=="x"then
if testButton(11)then
SCN.go("about")
end
elseif key=="escape"then elseif key=="escape"then
if testButton(12)then if testButton(12)then
SCN.back() SCN.back()

View File

@@ -31,7 +31,6 @@ function scene.sceneInit()
end end
function scene.sceneBack() function scene.sceneBack()
WS.send("chat","Q") WS.send("chat","Q")
WSCONN=false
LOG.print(text.wsDisconnected,"warn") LOG.print(text.wsDisconnected,"warn")
end end

View File

@@ -31,7 +31,6 @@ local scene={}
function scene.sceneBack() function scene.sceneBack()
WS.send("play","Q") WS.send("play","Q")
WSCONN=false
LOG.print(text.wsDisconnected,"warn") LOG.print(text.wsDisconnected,"warn")
love.keyboard.setKeyRepeat(true) love.keyboard.setKeyRepeat(true)
end end
@@ -123,7 +122,6 @@ end
function scene.gamepadDown(key) function scene.gamepadDown(key)
if key=="back"then if key=="back"then
if TIME()-lastBackTime<1 then if TIME()-lastBackTime<1 then
WSCONN=false
SCN.back() SCN.back()
else else
lastBackTime=TIME() lastBackTime=TIME()
@@ -263,7 +261,7 @@ function scene.update(dt)
local _ local _
local GAME=GAME local GAME=GAME
if not WSCONN and not SCN.swapping then SCN.back()end if WS.status("play")~="running"and not SCN.swapping then SCN.back()end
if not playing then if not playing then
heartBeatTimer=heartBeatTimer+dt heartBeatTimer=heartBeatTimer+dt
if heartBeatTimer>42 then if heartBeatTimer>42 then