新的对战房间数据结构,整理相关内容
This commit is contained in:
@@ -9,19 +9,20 @@ local NET={
|
|||||||
allow_online=false,
|
allow_online=false,
|
||||||
accessToken=false,
|
accessToken=false,
|
||||||
roomList={},
|
roomList={},
|
||||||
roomInfo={
|
roomState={
|
||||||
-- rid=false,
|
roomInfo={
|
||||||
name=false,
|
name=false,
|
||||||
-- type=false,
|
type=false,
|
||||||
private=false,
|
version=false,
|
||||||
-- count=false,
|
},
|
||||||
|
roomData={},
|
||||||
|
count=false,
|
||||||
capacity=false,
|
capacity=false,
|
||||||
allReady=false,
|
private=false,
|
||||||
connectingStream=false,
|
|
||||||
waitingStream=false,
|
|
||||||
start=false,
|
start=false,
|
||||||
},
|
},
|
||||||
connectingStream=false,
|
allReady=false,
|
||||||
|
waitingStream=false,
|
||||||
streamRoomID=false,
|
streamRoomID=false,
|
||||||
|
|
||||||
UserCount="_",
|
UserCount="_",
|
||||||
@@ -130,7 +131,7 @@ function NET.wsconn_play()
|
|||||||
end
|
end
|
||||||
function NET.wsconn_stream()
|
function NET.wsconn_stream()
|
||||||
if NET.lock('wsc_stream',5)then
|
if NET.lock('wsc_stream',5)then
|
||||||
NET.roomInfo.start=true
|
NET.roomState.start=true
|
||||||
WS.connect('stream','/stream',JSON.encode{
|
WS.connect('stream','/stream',JSON.encode{
|
||||||
uid=USER.uid,
|
uid=USER.uid,
|
||||||
accessToken=NET.accessToken,
|
accessToken=NET.accessToken,
|
||||||
@@ -145,7 +146,7 @@ function NET.wsclose_app()WS.close('app')end
|
|||||||
function NET.wsclose_user()WS.close('user')end
|
function NET.wsclose_user()WS.close('user')end
|
||||||
function NET.wsclose_play()WS.close('play')end
|
function NET.wsclose_play()WS.close('play')end
|
||||||
function NET.wsclose_stream()
|
function NET.wsclose_stream()
|
||||||
NET.roomInfo.start=false
|
NET.roomState.start=false
|
||||||
WS.close('stream')
|
WS.close('stream')
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -216,10 +217,8 @@ function NET.fetchRoom()
|
|||||||
end
|
end
|
||||||
function NET.createRoom(roomName,capacity,roomType,password)
|
function NET.createRoom(roomName,capacity,roomType,password)
|
||||||
if NET.lock('enterRoom',1.26)then
|
if NET.lock('enterRoom',1.26)then
|
||||||
NET.roomInfo.name=roomName
|
NET.roomState.private=not not password
|
||||||
NET.roomInfo.type=roomType
|
NET.roomState.capacity=capacity
|
||||||
NET.roomInfo.private=not not password
|
|
||||||
NET.roomInfo.capacity=capacity
|
|
||||||
WS.send('play',JSON.encode{
|
WS.send('play',JSON.encode{
|
||||||
action=1,
|
action=1,
|
||||||
data={
|
data={
|
||||||
@@ -240,11 +239,6 @@ end
|
|||||||
function NET.enterRoom(room,password)
|
function NET.enterRoom(room,password)
|
||||||
if NET.lock('enterRoom',1.26)then
|
if NET.lock('enterRoom',1.26)then
|
||||||
SFX.play('reach',.6)
|
SFX.play('reach',.6)
|
||||||
NET.roomInfo.name=room.roomInfo.name
|
|
||||||
NET.roomInfo.type=room.roomInfo.type
|
|
||||||
NET.roomInfo.private=not not password
|
|
||||||
NET.roomInfo.capacity=room.capacity
|
|
||||||
NET.roomInfo.start=room.start
|
|
||||||
WS.send('play',JSON.encode{
|
WS.send('play',JSON.encode{
|
||||||
action=2,
|
action=2,
|
||||||
data={
|
data={
|
||||||
@@ -272,7 +266,7 @@ function NET.changeConfig()
|
|||||||
WS.send('play','{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}')
|
WS.send('play','{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}')
|
||||||
end
|
end
|
||||||
function NET.signal_ready(ready)
|
function NET.signal_ready(ready)
|
||||||
if NET.lock('ready',3)and not NET.roomInfo.start then
|
if NET.lock('ready',3)and not NET.roomState.start then
|
||||||
WS.send('play','{"action":6,"data":{"ready":'..tostring(ready)..'}}')
|
WS.send('play','{"action":6,"data":{"ready":'..tostring(ready)..'}}')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -433,7 +427,13 @@ function NET.updateWS_play()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--TODO: d.roomInfo,d.roomData (json)
|
NET.roomState.roomInfo=d.roomInfo
|
||||||
|
NET.roomState.roomData=d.roomData
|
||||||
|
NET.roomState.count=d.count
|
||||||
|
NET.roomState.capacity=d.capacity
|
||||||
|
NET.roomState.private=d.private
|
||||||
|
NET.roomState.start=d.start
|
||||||
|
NET.srid=d.srid
|
||||||
loadGame('netBattle',true,true)
|
loadGame('netBattle',true,true)
|
||||||
else
|
else
|
||||||
--Load other players
|
--Load other players
|
||||||
@@ -445,7 +445,7 @@ function NET.updateWS_play()
|
|||||||
config=d.config,
|
config=d.config,
|
||||||
}
|
}
|
||||||
if SCN.socketRead then SCN.socketRead('join',d)end
|
if SCN.socketRead then SCN.socketRead('join',d)end
|
||||||
NET.roomInfo.allReady=false
|
NET.allReady=false
|
||||||
end
|
end
|
||||||
elseif res.action==3 then--Player leave
|
elseif res.action==3 then--Player leave
|
||||||
if not d.uid then
|
if not d.uid then
|
||||||
@@ -467,16 +467,16 @@ function NET.updateWS_play()
|
|||||||
netPLY.setReady(d.uid,d.ready)
|
netPLY.setReady(d.uid,d.ready)
|
||||||
elseif res.action==7 then--All Ready
|
elseif res.action==7 then--All Ready
|
||||||
SFX.play('reach',.6)
|
SFX.play('reach',.6)
|
||||||
NET.roomInfo.allReady=true
|
NET.allReady=true
|
||||||
elseif res.action==8 then--Set
|
elseif res.action==8 then--Set
|
||||||
NET.streamRoomID=d.rid
|
NET.streamRoomID=d.rid
|
||||||
NET.roomInfo.allReady=false
|
NET.allReady=false
|
||||||
NET.roomInfo.connectingStream=true
|
NET.connectingStream=true
|
||||||
NET.wsconn_stream()
|
NET.wsconn_stream()
|
||||||
elseif res.action==9 then--Game finished
|
elseif res.action==9 then--Game finished
|
||||||
NET.wsclose_stream()
|
NET.wsclose_stream()
|
||||||
if SCN.socketRead then SCN.socketRead('finish',d)end
|
if SCN.socketRead then SCN.socketRead('finish',d)end
|
||||||
NET.roomInfo.start=false
|
NET.roomState.start=false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
WS.alert('play')
|
WS.alert('play')
|
||||||
@@ -504,19 +504,25 @@ function NET.updateWS_stream()
|
|||||||
local d=res.data
|
local d=res.data
|
||||||
if res.type=='Connect'then
|
if res.type=='Connect'then
|
||||||
NET.unlock('wsc_stream')
|
NET.unlock('wsc_stream')
|
||||||
NET.roomInfo.connectingStream=false
|
NET.connectingStream=false
|
||||||
NET.roomInfo.waitingStream=true
|
NET.waitingStream=true
|
||||||
for _,uid in next,d.connected do
|
|
||||||
netPLY.setConnect(uid)
|
|
||||||
end
|
|
||||||
elseif res.action==0 then--Game start
|
elseif res.action==0 then--Game start
|
||||||
NET.roomInfo.waitingStream=false
|
NET.waitingStream=false
|
||||||
NET.roomInfo.start=true
|
NET.roomState.start=true
|
||||||
if SCN.socketRead then SCN.socketRead('go',d)end
|
if SCN.socketRead then SCN.socketRead('go',d)end
|
||||||
elseif res.action==1 then--Game finished
|
elseif res.action==1 then--Game finished
|
||||||
--?
|
--?
|
||||||
elseif res.action==2 then--Player join
|
elseif res.action==2 then--Player join
|
||||||
if not d.watch then
|
if res.type=='Self'then
|
||||||
|
for _,p in next,d.connected do
|
||||||
|
if not p.watch then
|
||||||
|
netPLY.setConnect(p.uid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if d.watch then
|
||||||
|
--TODO: Join in-game
|
||||||
|
else
|
||||||
netPLY.setConnect(d.uid)
|
netPLY.setConnect(d.uid)
|
||||||
end
|
end
|
||||||
elseif res.action==3 then--Player leave
|
elseif res.action==3 then--Player leave
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ function netPLY.setReady(uid,ready)
|
|||||||
if p.uid==uid then
|
if p.uid==uid then
|
||||||
if p.ready~=ready then
|
if p.ready~=ready then
|
||||||
p.ready=ready
|
p.ready=ready
|
||||||
if not ready then NET.roomInfo.allReady=false end
|
if not ready then NET.allReady=false end
|
||||||
SFX.play('spin_0',.6)
|
SFX.play('spin_0',.6)
|
||||||
if i==1 then
|
if i==1 then
|
||||||
NET.unlock('ready')
|
NET.unlock('ready')
|
||||||
|
|||||||
@@ -182,11 +182,11 @@ function scene.socketRead(cmd,d)
|
|||||||
if not playing then
|
if not playing then
|
||||||
playing=true
|
playing=true
|
||||||
love.keyboard.setKeyRepeat(false)
|
love.keyboard.setKeyRepeat(false)
|
||||||
netPLY.resetState()
|
|
||||||
netPLY.mouseMove(0,0)
|
|
||||||
lastUpstreamTime=0
|
lastUpstreamTime=0
|
||||||
upstreamProgress=1
|
upstreamProgress=1
|
||||||
resetGameData('n',d.seed)
|
resetGameData('n',d.seed)
|
||||||
|
netPLY.mouseMove(0,0)
|
||||||
|
netPLY.resetState()
|
||||||
else
|
else
|
||||||
LOG.print("Redundant [Go]",'warn')
|
LOG.print("Redundant [Go]",'warn')
|
||||||
end
|
end
|
||||||
@@ -277,13 +277,13 @@ function scene.draw()
|
|||||||
|
|
||||||
--Ready & Set mark
|
--Ready & Set mark
|
||||||
setFont(50)
|
setFont(50)
|
||||||
if NET.roomInfo.allReady then
|
if NET.allReady then
|
||||||
gc.setColor(0,1,.5,.9)
|
gc.setColor(0,1,.5,.9)
|
||||||
mStr(text.ready,640,15)
|
mStr(text.ready,640,15)
|
||||||
elseif NET.roomInfo.connectingStream then
|
elseif NET.connectingStream then
|
||||||
gc.setColor(.1,1,.8,.9)
|
gc.setColor(.1,1,.8,.9)
|
||||||
mStr(text.connStream,640,15)
|
mStr(text.connStream,640,15)
|
||||||
elseif NET.roomInfo.waitingStream then
|
elseif NET.waitingStream then
|
||||||
gc.setColor(0,.8,1,.9)
|
gc.setColor(0,.8,1,.9)
|
||||||
mStr(text.waitStream,640,15)
|
mStr(text.waitStream,640,15)
|
||||||
end
|
end
|
||||||
@@ -291,11 +291,11 @@ function scene.draw()
|
|||||||
--Room info.
|
--Room info.
|
||||||
gc.setColor(1,1,1)
|
gc.setColor(1,1,1)
|
||||||
setFont(25)
|
setFont(25)
|
||||||
gc.printf(NET.roomInfo.name,0,685,1270,'right')
|
gc.printf(NET.roomState.roomInfo.name,0,685,1270,'right')
|
||||||
setFont(40)
|
setFont(40)
|
||||||
gc.print(netPLY.getCount().."/"..NET.roomInfo.capacity,70,655)
|
gc.print(netPLY.getCount().."/"..NET.roomState.capacity,70,655)
|
||||||
if NET.roomInfo.private then gc.draw(IMG.lock,30,668)end
|
if NET.roomState.private then gc.draw(IMG.lock,30,668)end
|
||||||
if NET.roomInfo.start then gc.setColor(0,1,0)gc.print(text.started,230,655)end
|
if NET.roomState.start then gc.setColor(0,1,0)gc.print(text.started,230,655)end
|
||||||
|
|
||||||
--Profile
|
--Profile
|
||||||
drawSelfProfile()
|
drawSelfProfile()
|
||||||
@@ -319,7 +319,7 @@ scene.widgetList={
|
|||||||
hideF=function()
|
hideF=function()
|
||||||
return
|
return
|
||||||
playing or
|
playing or
|
||||||
NET.roomInfo.start or
|
NET.roomState.start or
|
||||||
netPLY.getSelfReady()or
|
netPLY.getSelfReady()or
|
||||||
NET.getlock('ready')
|
NET.getlock('ready')
|
||||||
end},
|
end},
|
||||||
@@ -327,7 +327,7 @@ scene.widgetList={
|
|||||||
hideF=function()
|
hideF=function()
|
||||||
return
|
return
|
||||||
playing or
|
playing or
|
||||||
NET.roomInfo.start or
|
NET.roomState.start or
|
||||||
not netPLY.getSelfReady()or
|
not netPLY.getSelfReady()or
|
||||||
NET.getlock('ready')
|
NET.getlock('ready')
|
||||||
end},
|
end},
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ local scene={}
|
|||||||
|
|
||||||
function scene.sceneInit()
|
function scene.sceneInit()
|
||||||
BG.set()
|
BG.set()
|
||||||
NET.roomInfo.allReady=false
|
NET.allReady=false
|
||||||
NET.roomInfo.connectingStream=false
|
NET.connectingStream=false
|
||||||
NET.roomInfo.waitingStream=false
|
NET.waitingStream=false
|
||||||
scrollPos=0
|
scrollPos=0
|
||||||
selected=1
|
selected=1
|
||||||
fetchRoom()
|
fetchRoom()
|
||||||
|
|||||||
Reference in New Issue
Block a user