实现开始游戏信号与切换进游戏状态创建玩家

This commit is contained in:
MrZ_26
2022-10-21 00:16:15 +08:00
parent dc1973e049
commit 9a4e8ab4ec
3 changed files with 53 additions and 60 deletions

View File

@@ -18,11 +18,11 @@ return{
GAME.modeEnv.allowMod=false
GAME.modeEnv.task=marginTask
local L=TABLE.copy(NETPLY.list)
local L=TABLE.shift(NETPLY.list,0)
local N=1
for i,p in next,L do
if p.uid==USER.uid then
if p.connected then
if p.playMode=='Gamer' then
PLY.newPlayer(1)
N=2
end
@@ -31,7 +31,7 @@ return{
end
end
for _,p in next,L do
if p.connected then
if p.playMode=='Gamer' then
PLY.newRemotePlayer(N,false,p)
N=N+1
end

View File

@@ -393,7 +393,7 @@ local actMap={
local function wsSend(act,data)
-- print(("Send: $1 -->"):repD(act))
print(("Send: $1 -->"):repD(act)) print(type(data)=='table' and TABLE.dump(data) or tostring(data),"\n")
-- print(("Send: $1 -->"):repD(act)) print(type(data)=='table' and TABLE.dump(data) or tostring(data),"\n")
WS.send('game',JSON.encode{
action=assert(act),
data=data,
@@ -512,7 +512,7 @@ function NET.player_setHost(pid)
role='Admin',
})
end
function NET.player_setState(state)-- what state?
function NET.player_setState(state)-- not used
wsSend(actMap.player_setState,state)
end
function NET.player_stream(stream)
@@ -522,9 +522,7 @@ function NET.player_setPlayMode(mode)
wsSend(actMap.player_setPlayMode,mode)
end
-- Match
function NET.match_techminohaowan(arg)
end
-- WS
NET.wsCallBack={}
@@ -611,7 +609,7 @@ function NET.wsCallBack.player_joinGroup(body)-- TODO
end
function NET.wsCallBack.player_setHost(body)-- TODO
end
function NET.wsCallBack.player_setState(body)-- TODO
function NET.wsCallBack.player_setState(body)-- TODO (not used)
end
function NET.wsCallBack.player_stream(body)-- TODO
end
@@ -621,6 +619,14 @@ end
function NET.wsCallBack.player_setReadyMode(body)
NETPLY.setReadyMode(body.data.playerId,body.data.type)
end
function NET.wsCallBack.match_finish()
TASK.unlock('netPlaying')
end
function NET.wsCallBack.match_ready()-- TODO
end
function NET.wsCallBack.match_start()
TASK.lock('netPlaying')
end
function NET.ws_connect()
if WS.status('game')=='dead' then
@@ -688,7 +694,7 @@ function NET.ws_update()
elseif msg then
msg=JSON.decode(msg)
-- print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno))
print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno)) print(TABLE.dump(msg),"\n")
-- print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno)) print(TABLE.dump(msg),"\n")
if msg.errno~=0 then
parseError(msg.message~=nil and msg.message or msg)
else

View File

@@ -80,7 +80,7 @@ function scene.sceneInit()
end
end
function scene.sceneBack()
GAME.playing=false
TASK.unlock('netPlaying')
end
scene.mouseDown=NULL
@@ -193,41 +193,19 @@ function scene.gamepadUp(key)
end
end
function scene._(cmd,d)
if cmd=='join' then
textBox:push{
COLOR.lR,d.username,
COLOR.dY,"#"..d.uid.." ",
COLOR.Y,text.joinRoom,
}
SFX.play('warn_1')
elseif cmd=='leave' then
textBox:push{
COLOR.lR,d.username,
COLOR.dY,"#"..d.uid.." ",
COLOR.Y,text.leaveRoom,
}
elseif cmd=='go' then
if not playing then
playing=true
lastUpstreamTime=0
upstreamProgress=1
resetGameData('n',NET.seed)
NETPLY.mouseMove(0,0)
end
elseif cmd=='finish' then
playing=false
BG.set()
end
end
function scene.update(dt)
if WS.status('game')~='running' then
TASK.unlock('netPlaying')
NET.ws_close()
SCN.back()
return
end
if playing then
if not TASK.getLock('netPlaying') then
playing=false
BG.set()
return
else
local P1=PLAYERS[1]
touchMoveLastFrame=false
@@ -255,8 +233,17 @@ function scene.update(dt)
NET.player_stream(stream)
lastUpstreamTime=PLAYERS[1].alive and P1.frameRun or 1e99
end
end
else
NETPLY.update(dt)
if TASK.getLock('netPlaying') and not playing then
playing=true
TASK.lock('netPlaying')
lastUpstreamTime=0
upstreamProgress=1
resetGameData('n',NET.seed)
NETPLY.mouseMove(0,0)
end
end
end