升级本地和服务器提供的房间数据格式(警告:和旧版本不兼容),修复“游戏中”标记会被带到别的房间
This commit is contained in:
@@ -16,12 +16,12 @@ local NET={
|
||||
private=false,
|
||||
-- count=false,
|
||||
capacity=false,
|
||||
allReady=false,
|
||||
connectingStream=false,
|
||||
waitingStream=false,
|
||||
start=false,
|
||||
},
|
||||
allReady=false,
|
||||
connectingStream=false,
|
||||
waitingStream=false,
|
||||
serverGaming=false,
|
||||
streamRoomID=false,
|
||||
|
||||
UserCount="_",
|
||||
@@ -130,7 +130,7 @@ function NET.wsconn_play()
|
||||
end
|
||||
function NET.wsconn_stream()
|
||||
if NET.lock('wsc_stream',5)then
|
||||
NET.serverGaming=true
|
||||
NET.roomInfo.start=true
|
||||
WS.connect('stream','/stream',JSON.encode{
|
||||
uid=USER.uid,
|
||||
accessToken=NET.accessToken,
|
||||
@@ -145,7 +145,7 @@ function NET.wsclose_app()WS.close('app')end
|
||||
function NET.wsclose_user()WS.close('user')end
|
||||
function NET.wsclose_play()WS.close('play')end
|
||||
function NET.wsclose_stream()
|
||||
NET.serverGaming=false
|
||||
NET.roomInfo.start=false
|
||||
WS.close('stream')
|
||||
end
|
||||
|
||||
@@ -223,10 +223,15 @@ function NET.createRoom(roomName,capacity,roomType,password)
|
||||
WS.send('play',JSON.encode{
|
||||
action=1,
|
||||
data={
|
||||
name=roomName,
|
||||
capacity=capacity,
|
||||
roomData={type=roomType},
|
||||
password=password,
|
||||
roomInfo={
|
||||
name=roomName,
|
||||
type=roomType,
|
||||
version=VERSION.code,
|
||||
},
|
||||
roomData={_=0},
|
||||
|
||||
config=dumpBasicConfig(),
|
||||
}
|
||||
})
|
||||
@@ -235,8 +240,8 @@ end
|
||||
function NET.enterRoom(room,password)
|
||||
if NET.lock('enterRoom',1.26)then
|
||||
SFX.play('reach',.6)
|
||||
NET.roomInfo.name=room.name
|
||||
NET.roomInfo.type=room.type
|
||||
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
|
||||
@@ -267,7 +272,7 @@ function NET.changeConfig()
|
||||
WS.send('play','{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}')
|
||||
end
|
||||
function NET.signal_ready(ready)
|
||||
if NET.lock('ready',3)and not NET.serverGaming then
|
||||
if NET.lock('ready',3)and not NET.roomInfo.start then
|
||||
WS.send('play','{"action":6,"data":{"ready":'..tostring(ready)..'}}')
|
||||
end
|
||||
end
|
||||
@@ -428,7 +433,7 @@ function NET.updateWS_play()
|
||||
}
|
||||
end
|
||||
end
|
||||
--TODO: d.roomData (json)
|
||||
--TODO: d.roomInfo,d.roomData (json)
|
||||
loadGame('netBattle',true,true)
|
||||
else
|
||||
--Load other players
|
||||
@@ -440,7 +445,7 @@ function NET.updateWS_play()
|
||||
config=d.config,
|
||||
}
|
||||
if SCN.socketRead then SCN.socketRead('join',d)end
|
||||
NET.allReady=false
|
||||
NET.roomInfo.allReady=false
|
||||
end
|
||||
elseif res.action==3 then--Player leave
|
||||
if not d.uid then
|
||||
@@ -462,11 +467,11 @@ function NET.updateWS_play()
|
||||
netPLY.setReady(d.uid,d.ready)
|
||||
elseif res.action==7 then--All Ready
|
||||
SFX.play('reach',.6)
|
||||
NET.allReady=true
|
||||
NET.roomInfo.allReady=true
|
||||
elseif res.action==8 then--Set
|
||||
NET.streamRoomID=d.rid
|
||||
NET.allReady=false
|
||||
NET.connectingStream=true
|
||||
NET.roomInfo.allReady=false
|
||||
NET.roomInfo.connectingStream=true
|
||||
NET.wsconn_stream()
|
||||
elseif res.action==9 then--Game finished
|
||||
NET.wsclose_stream()
|
||||
@@ -499,12 +504,12 @@ function NET.updateWS_stream()
|
||||
local d=res.data
|
||||
if res.type=='Connect'then
|
||||
NET.unlock('wsc_stream')
|
||||
NET.connectingStream=false
|
||||
NET.waitingStream=true
|
||||
NET.roomInfo.connectingStream=false
|
||||
NET.roomInfo.waitingStream=true
|
||||
netPLY.setConnect(USER.uid)
|
||||
netPLY.freshStreamConn(res.data.connected)
|
||||
elseif res.action==0 then--Game start
|
||||
NET.waitingStream=false
|
||||
NET.roomInfo.waitingStream=false
|
||||
NET.roomInfo.start=true
|
||||
if SCN.socketRead then SCN.socketRead('go',d)end
|
||||
elseif res.action==1 then--Game finished
|
||||
|
||||
@@ -108,7 +108,7 @@ function netPLY.setReady(uid,ready)
|
||||
if p.uid==uid then
|
||||
if p.ready~=ready then
|
||||
p.ready=ready
|
||||
if not ready then NET.allReady=false end
|
||||
if not ready then NET.roomInfo.allReady=false end
|
||||
SFX.play('spin_0',.6)
|
||||
if i==1 then
|
||||
NET.unlock('ready')
|
||||
|
||||
@@ -273,13 +273,13 @@ function scene.draw()
|
||||
|
||||
--Ready & Set mark
|
||||
setFont(50)
|
||||
if NET.allReady then
|
||||
if NET.roomInfo.allReady then
|
||||
gc.setColor(0,1,.5,.9)
|
||||
mStr(text.ready,640,15)
|
||||
elseif NET.connectingStream then
|
||||
elseif NET.roomInfo.connectingStream then
|
||||
gc.setColor(.1,1,.8,.9)
|
||||
mStr(text.connStream,640,15)
|
||||
elseif NET.waitingStream then
|
||||
elseif NET.roomInfo.waitingStream then
|
||||
gc.setColor(0,.8,1,.9)
|
||||
mStr(text.waitStream,640,15)
|
||||
end
|
||||
@@ -315,7 +315,7 @@ scene.widgetList={
|
||||
hideF=function()
|
||||
return
|
||||
playing or
|
||||
NET.serverGaming or
|
||||
NET.roomInfo.start or
|
||||
netPLY.getSelfReady()or
|
||||
NET.getlock('ready')
|
||||
end},
|
||||
@@ -323,7 +323,7 @@ scene.widgetList={
|
||||
hideF=function()
|
||||
return
|
||||
playing or
|
||||
NET.serverGaming or
|
||||
NET.roomInfo.start or
|
||||
not netPLY.getSelfReady()or
|
||||
NET.getlock('ready')
|
||||
end},
|
||||
|
||||
@@ -8,6 +8,18 @@ local scrollPos,selected
|
||||
local fetchTimer
|
||||
local lastCreateRoomTime=0
|
||||
|
||||
--[[room={
|
||||
rid="qwe",
|
||||
roomInfo={
|
||||
name="MrZ's room",
|
||||
type="classic",
|
||||
version=1409,
|
||||
},
|
||||
private=false,
|
||||
start=false,
|
||||
count=4,
|
||||
capacity=5,
|
||||
}]]
|
||||
local function fetchRoom()
|
||||
fetchTimer=5
|
||||
NET.fetchRoom()
|
||||
@@ -17,9 +29,9 @@ local scene={}
|
||||
|
||||
function scene.sceneInit()
|
||||
BG.set()
|
||||
NET.allReady=false
|
||||
NET.connectingStream=false
|
||||
NET.waitingStream=false
|
||||
NET.roomInfo.allReady=false
|
||||
NET.roomInfo.connectingStream=false
|
||||
NET.roomInfo.waitingStream=false
|
||||
scrollPos=0
|
||||
selected=1
|
||||
fetchRoom()
|
||||
@@ -74,11 +86,10 @@ function scene.keyDown(k)
|
||||
end
|
||||
elseif k=="return"then
|
||||
if NET.getlock('fetchRoom')or not NET.roomList[selected]then return end
|
||||
if NET.roomList[selected].private then
|
||||
LOG.print("Can't enter private room now",'message')
|
||||
return
|
||||
end
|
||||
NET.enterRoom(NET.roomList[selected])--,password
|
||||
local R=NET.roomList[selected]
|
||||
if R.roomInfo.version~=VERSION.code then LOG.print("Version doesn't match",'message')return end
|
||||
if R.private then LOG.print("Can't enter private room now",'message')return end
|
||||
NET.enterRoom(R)--,password
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -137,6 +148,10 @@ function scene.draw()
|
||||
gc.rectangle('line',50,110,1060,400)
|
||||
local roomCount=#NET.roomList
|
||||
if roomCount>0 then
|
||||
if roomCount>10 then
|
||||
local len=400*10/roomCount
|
||||
gc.rectangle('fill',1097,110+(400-len)*scrollPos/(roomCount-10),12,len)
|
||||
end
|
||||
setFont(35)
|
||||
gc.push('transform')
|
||||
gc.stencil(roomListStencil,'replace',1)
|
||||
@@ -149,27 +164,27 @@ function scene.draw()
|
||||
gc.setColor(1,1,1,.3)
|
||||
gc.rectangle('fill',50,70+40*i,1060,40)
|
||||
end
|
||||
if R.start then
|
||||
gc.setColor(0,1,0)
|
||||
gc.print(text.started,660,66+40*i)
|
||||
gc.setColor(1,1,1)
|
||||
if R.private then gc.draw(IMG.lock,60,75+40*i)end
|
||||
gc.printf(R.roomInfo.type,440,66+40*i,500,'right')
|
||||
gc.print(R.count.."/"..R.capacity,980,66+40*i)
|
||||
if R.roomInfo.version~=VERSION.code then
|
||||
gc.setColor(1,.2,0)
|
||||
gc.print("V"..R.roomInfo.version,600,66+40*i)
|
||||
end
|
||||
|
||||
gc.setColor(.9,.9,1)
|
||||
gc.print(pos+i,95,66+40*i)
|
||||
gc.setColor(1,1,.7)
|
||||
gc.print(R.name,250,66+40*i)
|
||||
gc.setColor(1,1,1)
|
||||
gc.printf(R.type,430,66+40*i,500,'right')
|
||||
gc.print(R.count.."/"..R.capacity,980,66+40*i)
|
||||
if R.private then
|
||||
gc.draw(IMG.lock,59,75+40*i)
|
||||
|
||||
if R.start then
|
||||
gc.setColor(0,.4,.05)
|
||||
else
|
||||
gc.setColor(1,1,.7)
|
||||
end
|
||||
gc.print(R.roomInfo.name,250,66+40*i)
|
||||
end
|
||||
gc.setStencilTest()
|
||||
gc.pop()
|
||||
if roomCount>10 then
|
||||
local len=400*10/roomCount
|
||||
gc.rectangle('fill',1218,110+(400-len)*scrollPos/(roomCount-10),12,len)
|
||||
end
|
||||
end
|
||||
|
||||
--Profile
|
||||
|
||||
Reference in New Issue
Block a user