房间内玩家对象管理单独做进新模块netPlayer,为未来消息气泡和发表情做准备
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
local data=love.data
|
||||
local ins,rem=table.insert,table.remove
|
||||
local rem=table.remove
|
||||
local WS,TIME=WS,TIME
|
||||
|
||||
local NET={
|
||||
connected=false,
|
||||
allow_online=false,
|
||||
@@ -352,28 +353,28 @@ function NET.updateWS_play()
|
||||
elseif res.action==2 then--Player join
|
||||
if res.type=='Self'then
|
||||
--Enter new room
|
||||
TABLE.cut(PLY_NET)
|
||||
netPLY.clear()
|
||||
if d.players then
|
||||
for _,p in next,d.players do
|
||||
ins(PLY_NET,p.uid==USER.uid and 1 or #PLY_NET+1,{
|
||||
netPLY.add{
|
||||
uid=p.uid,
|
||||
username=p.username,
|
||||
sid=p.sid,
|
||||
ready=p.ready,
|
||||
config=p.config,
|
||||
})
|
||||
}
|
||||
end
|
||||
end
|
||||
loadGame('netBattle',true,true)
|
||||
else
|
||||
--Load other players
|
||||
ins(PLY_NET,{
|
||||
netPLY.add{
|
||||
uid=d.uid,
|
||||
username=d.username,
|
||||
sid=d.sid,
|
||||
ready=d.ready,
|
||||
config=d.config,
|
||||
})
|
||||
}
|
||||
if SCN.socketRead then SCN.socketRead('Join',d)end
|
||||
NET.allReady=false
|
||||
end
|
||||
@@ -384,12 +385,7 @@ function NET.updateWS_play()
|
||||
NET.unlock('quit')
|
||||
SCN.back()
|
||||
else
|
||||
for i=1,#PLY_NET do
|
||||
if PLY_NET[i].sid==d.sid then
|
||||
rem(PLY_NET,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
netPLY.remove(d.sid)
|
||||
for i=1,#PLAYERS do
|
||||
if PLAYERS[i].sid==d.sid then
|
||||
rem(PLAYERS,i)
|
||||
@@ -407,36 +403,9 @@ function NET.updateWS_play()
|
||||
elseif res.action==4 then--Player talk
|
||||
if SCN.socketRead then SCN.socketRead('Talk',d)end
|
||||
elseif res.action==5 then--Player change settings
|
||||
if tostring(USER.uid)~=d.uid then
|
||||
for i=1,#PLY_NET do
|
||||
if PLY_NET[i].uid==d.uid then
|
||||
PLY_NET[i].config=d.config
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
netPLY.setConf(d.uid,d.config)
|
||||
elseif res.action==6 then--One ready
|
||||
for i,p in next,PLY_NET do
|
||||
if p.uid==d.uid then
|
||||
if p.ready~=d.ready then
|
||||
p.ready=d.ready
|
||||
if not d.ready then NET.allReady=false end
|
||||
SFX.play('spin_0',.6)
|
||||
if i==1 then
|
||||
NET.unlock('ready')
|
||||
elseif not PLY_NET[1].ready then
|
||||
for j=2,#PLY_NET do
|
||||
if not PLY_NET[j].ready then
|
||||
goto BREAK_notAllReady
|
||||
end
|
||||
end
|
||||
SFX.play('blip_2',.5)
|
||||
::BREAK_notAllReady::
|
||||
end
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
netPLY.setReady(d.uid,d.ready)
|
||||
elseif res.action==7 then--All Ready
|
||||
SFX.play('reach',.6)
|
||||
NET.allReady=true
|
||||
|
||||
Reference in New Issue
Block a user