整理网络相关全局变量放入NET,删除WSCONN,调整进入联网菜单的逻辑
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
-- local host="192.168.114.102"
|
||||
-- local host="127.0.0.1"
|
||||
local host="hdustea.3322.org"
|
||||
local port="10026"
|
||||
local path="/tech/socket/v1"
|
||||
|
||||
6
main.lua
6
main.lua
@@ -25,8 +25,10 @@ LOADED=false
|
||||
DAILYLAUNCH=false
|
||||
LOGIN=false
|
||||
EDITING=""
|
||||
WSCONN=false
|
||||
ALLOW_ONLINE=false
|
||||
NET={
|
||||
allow_online=false,
|
||||
try_enter_netmenu=false,
|
||||
}
|
||||
ERRDATA={}
|
||||
|
||||
--System setting
|
||||
|
||||
@@ -1130,7 +1130,7 @@ do
|
||||
else
|
||||
local res=JSON.decode(message)
|
||||
if VERSION_CODE>=res.lowest then
|
||||
ALLOW_ONLINE=true
|
||||
NET.allow_online=true
|
||||
end
|
||||
if VERSION_CODE<res.newestCode then
|
||||
LOG.print(text.oldVersion:gsub("$1",res.newestName),180,COLOR.sky)
|
||||
@@ -1168,7 +1168,8 @@ do
|
||||
if res.id then
|
||||
USER.id=res.id
|
||||
USER.authToken=res.authToken
|
||||
SCN.go("net_menu")
|
||||
NET.try_enter_netmenu=true
|
||||
WS.send("user",JSON.encode{action=0})
|
||||
end
|
||||
FILE.save(USER,"conf/user","q")
|
||||
LOG.print(text.loginSuccessed)
|
||||
@@ -1183,6 +1184,10 @@ do
|
||||
elseif res.action==0 then
|
||||
USER.accessToken=res.accessToken
|
||||
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
|
||||
USER.name=res.username
|
||||
USER.motto=res.motto
|
||||
|
||||
@@ -77,14 +77,13 @@ function scene.keyDown(key)
|
||||
end
|
||||
elseif key=="a"then
|
||||
if testButton(3)then
|
||||
if not ALLOW_ONLINE then
|
||||
TEXT.show(text.notFinished,640,450,60,"flicker")
|
||||
SFX.play("finesseError")
|
||||
elseif LOGIN then
|
||||
SCN.go("net_menu")
|
||||
WS.send("user",JSON.encode{
|
||||
action=0,
|
||||
})
|
||||
if LOGIN then
|
||||
if not NET.allow_online then
|
||||
TEXT.show(text.needUpdate,640,450,60,"flicker")
|
||||
SFX.play("finesseError")
|
||||
else
|
||||
WS.send("user",JSON.encode{action=0})
|
||||
end
|
||||
else
|
||||
SCN.go("login")
|
||||
end
|
||||
@@ -109,18 +108,18 @@ function scene.keyDown(key)
|
||||
if testButton(8)then
|
||||
SCN.go("manual")
|
||||
end
|
||||
elseif key=="f1"then
|
||||
if testButton(11)then
|
||||
SCN.go("about")
|
||||
end
|
||||
elseif key=="f2"then
|
||||
elseif key=="2"then
|
||||
if testButton(9)then
|
||||
SCN.go("music")
|
||||
end
|
||||
elseif key=="f3"then
|
||||
elseif key=="0"then
|
||||
if testButton(10)then
|
||||
SCN.go("lang")
|
||||
end
|
||||
elseif key=="x"then
|
||||
if testButton(11)then
|
||||
SCN.go("about")
|
||||
end
|
||||
elseif key=="escape"then
|
||||
if testButton(12)then
|
||||
SCN.back()
|
||||
|
||||
@@ -31,7 +31,6 @@ function scene.sceneInit()
|
||||
end
|
||||
function scene.sceneBack()
|
||||
WS.send("chat","Q")
|
||||
WSCONN=false
|
||||
LOG.print(text.wsDisconnected,"warn")
|
||||
end
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ local scene={}
|
||||
|
||||
function scene.sceneBack()
|
||||
WS.send("play","Q")
|
||||
WSCONN=false
|
||||
LOG.print(text.wsDisconnected,"warn")
|
||||
love.keyboard.setKeyRepeat(true)
|
||||
end
|
||||
@@ -123,7 +122,6 @@ end
|
||||
function scene.gamepadDown(key)
|
||||
if key=="back"then
|
||||
if TIME()-lastBackTime<1 then
|
||||
WSCONN=false
|
||||
SCN.back()
|
||||
else
|
||||
lastBackTime=TIME()
|
||||
@@ -263,7 +261,7 @@ function scene.update(dt)
|
||||
local _
|
||||
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
|
||||
heartBeatTimer=heartBeatTimer+dt
|
||||
if heartBeatTimer>42 then
|
||||
|
||||
Reference in New Issue
Block a user