联网推进,整理代码

This commit is contained in:
MrZ626
2021-04-08 14:00:15 +08:00
parent 194bd8085f
commit f3f63454d3
7 changed files with 102 additions and 54 deletions

View File

@@ -180,12 +180,9 @@ local loadingThread=coroutine.wrap(function()
TASK.new(NET.updateWS_app)
TASK.new(NET.updateWS_user)
TASK.new(NET.updateWS_play)
WS.connect("app","/app")
NET.wsconn_app()
if USER.authToken then
WS.connect("user","/user",JSON.encode{
uid=USER.uid,
authToken=USER.authToken,
})
NET.wsconn_user_token(USER.uid,USER.authToken)
end
while true do

View File

@@ -6,10 +6,7 @@ local function login()
elseif #password==0 then
LOG.print(text.noPassword)return
end
WS.connect("user","/user",JSON.encode{
email=email,
password=password,
})
NET.wsconn_user_pswd(email,password)
end
local scene={}

View File

@@ -23,6 +23,7 @@ local scene={}
function scene.sceneBack()
NET.signal_quit()
NET.wsclose_stream()
love.keyboard.setKeyRepeat(true)
end
function scene.sceneInit()
@@ -187,7 +188,7 @@ function scene.socketRead(cmd,data)
end
elseif cmd=="Set"then
NET.rsid=data.rid
NET.wsConnectStream()
NET.wsconn_stream()
TASK.new(NET.updateWS_stream)
elseif cmd=="Begin"then
if not playing then
@@ -196,20 +197,27 @@ function scene.socketRead(cmd,data)
upstreamProgress=1
resetGameData("n",data.seed)
else
LOG.print("Redundant signal: B(begin)",30,COLOR.green)
LOG.print("Redundant signal: Begin",30,COLOR.green)
end
elseif cmd=="Finish"then
playing=false
resetGameData("n")
TEXT.show(text.champion:gsub("$1","SOMEBODY"),640,260,80,"zoomout",.26)
elseif cmd=="Die"then
--?
elseif cmd=="Stream"then
if data.uid==USER.uid then
LOG.print("SELF STREAM")
return
local winnerUID
for _,p in data.result do
if p.place==1 then
winnerUID=p.uid
break
end
end
if playing then
if not winnerUID then return end
for _,d in next,PLY_NET do
if d.uid==winnerUID then
TEXT.show(text.champion:gsub("$1",d.username),640,260,80,"zoomout",.26)
break
end
end
elseif cmd=="Stream"then
if data.uid~=USER.uid and playing then
for _,P in next,PLAYERS do
if P.userID==data.uid then
local res,stream=pcall(love.data.decode,"string","base64",data.stream)
@@ -225,12 +233,12 @@ function scene.socketRead(cmd,data)
end
function scene.update(dt)
if NET.checkPlayDisconn()then SCN.back()end
if not playing then return end
local _
local GAME=GAME
if WS.status("play")~="running"then SCN.back()end
if not playing then return end
touchMoveLastFrame=false
updateVirtualkey()
GAME.frame=GAME.frame+1

View File

@@ -3,6 +3,9 @@ local scene={}
function scene.sceneInit()
BG.set("space")
end
function scene.sceneBack()
NET.wsclose_play()
end
scene.widgetList={
-- WIDGET.newButton{name="ffa", x=640, y=200,w=350,h=120,font=40,code=NULL},