大改联网的lock子模块,大改对战的玩家数据结构,重做联网对战准备界面
This commit is contained in:
@@ -12,7 +12,7 @@ return{
|
|||||||
local N=2
|
local N=2
|
||||||
for i=1,#PLY_NET do
|
for i=1,#PLY_NET do
|
||||||
if PLY_NET[i].uid==USER.uid then
|
if PLY_NET[i].uid==USER.uid then
|
||||||
PLAYERS[1].subID=PLY_NET[1].sid
|
PLAYERS[1].sid=PLY_NET[1].sid
|
||||||
else
|
else
|
||||||
PLY.newRemotePlayer(N,false,PLY_NET[i])
|
PLY.newRemotePlayer(N,false,PLY_NET[i])
|
||||||
N=N+1
|
N=N+1
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local WS=WS
|
|
||||||
local data=love.data
|
local data=love.data
|
||||||
local ins,rem=table.insert,table.remove
|
local ins,rem=table.insert,table.remove
|
||||||
|
local WS,TIME=WS,TIME
|
||||||
local NET={
|
local NET={
|
||||||
login=false,
|
login=false,
|
||||||
allow_online=false,
|
allow_online=false,
|
||||||
@@ -19,20 +19,26 @@ local mesType={
|
|||||||
}
|
}
|
||||||
|
|
||||||
--Lock & Unlock submodule
|
--Lock & Unlock submodule
|
||||||
local locks={}
|
local locks do
|
||||||
local function _lock(name,T)
|
local rawset=rawset
|
||||||
if locks[name]and TIME()<locks[name]then
|
locks=setmetatable({},{
|
||||||
return false
|
__index=function(self,k)rawset(self,k,-1e99)return -1e99 end,
|
||||||
else
|
__newindex=function(self,k)rawset(self,k,-1e99)end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
function NET.lock(name,T)
|
||||||
|
if TIME()>=locks[name]then
|
||||||
locks[name]=TIME()+(T or 1e99)
|
locks[name]=TIME()+(T or 1e99)
|
||||||
return true
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function _unlock(name)
|
function NET.unlock(name)
|
||||||
locks[name]=false
|
locks[name]=-1e99
|
||||||
end
|
end
|
||||||
function NET.getLock(name)
|
function NET.getlock(name)
|
||||||
return locks[name]
|
return TIME()<locks[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
--Parse json message
|
--Parse json message
|
||||||
@@ -70,7 +76,7 @@ function NET.wsconn_app()
|
|||||||
WS.connect("app","/app")
|
WS.connect("app","/app")
|
||||||
end
|
end
|
||||||
function NET.wsconn_user_pswd(email,password)
|
function NET.wsconn_user_pswd(email,password)
|
||||||
if _lock("wsc_user",5)then
|
if NET.lock("wsc_user",5)then
|
||||||
WS.connect("user","/user",JSON.encode{
|
WS.connect("user","/user",JSON.encode{
|
||||||
email=email,
|
email=email,
|
||||||
password=password,
|
password=password,
|
||||||
@@ -78,7 +84,7 @@ function NET.wsconn_user_pswd(email,password)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.wsconn_user_token(uid,authToken)
|
function NET.wsconn_user_token(uid,authToken)
|
||||||
if _lock("wsc_user",5)then
|
if NET.lock("wsc_user",5)then
|
||||||
WS.connect("user","/user",JSON.encode{
|
WS.connect("user","/user",JSON.encode{
|
||||||
uid=uid,
|
uid=uid,
|
||||||
authToken=authToken,
|
authToken=authToken,
|
||||||
@@ -86,7 +92,7 @@ function NET.wsconn_user_token(uid,authToken)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.wsconn_play()
|
function NET.wsconn_play()
|
||||||
if _lock("wsc_play",5)then
|
if NET.lock("wsc_play",5)then
|
||||||
WS.connect("play","/play",JSON.encode{
|
WS.connect("play","/play",JSON.encode{
|
||||||
uid=USER.uid,
|
uid=USER.uid,
|
||||||
accessToken=NET.accessToken,
|
accessToken=NET.accessToken,
|
||||||
@@ -94,7 +100,7 @@ function NET.wsconn_play()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.wsconn_stream()
|
function NET.wsconn_stream()
|
||||||
if _lock("wsc_stream",5)then
|
if NET.lock("wsc_stream",5)then
|
||||||
WS.connect("stream","/stream",JSON.encode{
|
WS.connect("stream","/stream",JSON.encode{
|
||||||
uid=USER.uid,
|
uid=USER.uid,
|
||||||
accessToken=NET.accessToken,
|
accessToken=NET.accessToken,
|
||||||
@@ -116,7 +122,7 @@ function NET.pong(wsName,message)
|
|||||||
WS.send(wsName,message,"pong")
|
WS.send(wsName,message,"pong")
|
||||||
end
|
end
|
||||||
function NET.getAccessToken()
|
function NET.getAccessToken()
|
||||||
if _lock("accessToken",3)then
|
if NET.lock("accessToken",3)then
|
||||||
WS.send("user",JSON.encode{action=0})
|
WS.send("user",JSON.encode{action=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -154,7 +160,7 @@ end
|
|||||||
|
|
||||||
--Room
|
--Room
|
||||||
function NET.fetchRoom()
|
function NET.fetchRoom()
|
||||||
if _lock("fetchRoom",3)then
|
if NET.lock("fetchRoom",3)then
|
||||||
WS.send("play",JSON.encode{
|
WS.send("play",JSON.encode{
|
||||||
action=0,
|
action=0,
|
||||||
data={
|
data={
|
||||||
@@ -166,7 +172,7 @@ function NET.fetchRoom()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.createRoom()
|
function NET.createRoom()
|
||||||
if _lock("enterRoom",3)then
|
if NET.lock("enterRoom",3)then
|
||||||
WS.send("play",JSON.encode{
|
WS.send("play",JSON.encode{
|
||||||
action=1,
|
action=1,
|
||||||
data={
|
data={
|
||||||
@@ -179,7 +185,7 @@ function NET.createRoom()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.enterRoom(roomID,password)
|
function NET.enterRoom(roomID,password)
|
||||||
if _lock("enterRoom",3)then
|
if NET.lock("enterRoom",3)then
|
||||||
NET.rid=roomID
|
NET.rid=roomID
|
||||||
WS.send("play",JSON.encode{
|
WS.send("play",JSON.encode{
|
||||||
action=2,
|
action=2,
|
||||||
@@ -197,12 +203,12 @@ function NET.checkPlayDisconn()
|
|||||||
return WS.status("play")~="running"
|
return WS.status("play")~="running"
|
||||||
end
|
end
|
||||||
function NET.signal_ready(ready)
|
function NET.signal_ready(ready)
|
||||||
if _lock("ready",3)then
|
if NET.lock("ready",3)then
|
||||||
WS.send("play",'{"action":6,"data":{"ready":'..tostring(ready)..'}}')
|
WS.send("play",'{"action":6,"data":{"ready":'..tostring(ready)..'}}')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.signal_quit()
|
function NET.signal_quit()
|
||||||
if _lock("quit",3)then
|
if NET.lock("quit",3)then
|
||||||
WS.send("play",'{"action":3}')
|
WS.send("play",'{"action":3}')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -287,12 +293,12 @@ function NET.updateWS_user()
|
|||||||
|
|
||||||
--Get self infos
|
--Get self infos
|
||||||
NET.getUserInfo(USER.uid)
|
NET.getUserInfo(USER.uid)
|
||||||
_unlock("wsc_user")
|
NET.unlock("wsc_user")
|
||||||
elseif res.action==0 then--Get accessToken
|
elseif res.action==0 then--Get accessToken
|
||||||
NET.accessToken=res.accessToken
|
NET.accessToken=res.accessToken
|
||||||
LOG.print(text.accessSuccessed)
|
LOG.print(text.accessSuccessed)
|
||||||
NET.wsconn_play()
|
NET.wsconn_play()
|
||||||
_unlock("accessToken")
|
NET.unlock("accessToken")
|
||||||
elseif res.action==1 then--Get userInfo
|
elseif res.action==1 then--Get userInfo
|
||||||
NET.storeUserInfo(res)
|
NET.storeUserInfo(res)
|
||||||
end
|
end
|
||||||
@@ -323,26 +329,19 @@ function NET.updateWS_play()
|
|||||||
local d=res.data
|
local d=res.data
|
||||||
if res.type=="Connect"then
|
if res.type=="Connect"then
|
||||||
SCN.go("net_menu")
|
SCN.go("net_menu")
|
||||||
_unlock("wsc_play")
|
NET.unlock("wsc_play")
|
||||||
elseif res.action==0 then--Fetch rooms
|
elseif res.action==0 then--Fetch rooms
|
||||||
NET.roomList=res.roomList
|
NET.roomList=res.roomList
|
||||||
_unlock("fetchRoom")
|
NET.unlock("fetchRoom")
|
||||||
elseif res.action==1 then--Create room (not used)
|
elseif res.action==1 then--Create room (not used)
|
||||||
--?
|
--?
|
||||||
elseif res.action==2 then--Player join
|
elseif res.action==2 then--Player join
|
||||||
if res.type=="Self"then
|
if res.type=="Self"then
|
||||||
--Create room
|
--Create room
|
||||||
TABLE.clear(PLY_NET)
|
TABLE.clear(PLY_NET)
|
||||||
ins(PLY_NET,{
|
|
||||||
uid=USER.uid,
|
|
||||||
username=USER.username,
|
|
||||||
sid=d.sid,
|
|
||||||
ready=d.ready,
|
|
||||||
conf=dumpBasicConfig(),
|
|
||||||
})
|
|
||||||
if d.players then
|
if d.players then
|
||||||
for _,p in next,d.players do
|
for _,p in next,d.players do
|
||||||
ins(PLY_NET,{
|
ins(PLY_NET,p.uid==USER.uid and 1 or #PLY_NET+1,{
|
||||||
uid=p.uid,
|
uid=p.uid,
|
||||||
username=p.username,
|
username=p.username,
|
||||||
sid=p.sid,
|
sid=p.sid,
|
||||||
@@ -352,7 +351,7 @@ function NET.updateWS_play()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
loadGame("netBattle",true,true)
|
loadGame("netBattle",true,true)
|
||||||
_unlock("enterRoom")
|
NET.unlock("enterRoom")
|
||||||
else
|
else
|
||||||
--Load other players
|
--Load other players
|
||||||
ins(PLY_NET,{
|
ins(PLY_NET,{
|
||||||
@@ -368,22 +367,22 @@ function NET.updateWS_play()
|
|||||||
if not d.uid then
|
if not d.uid then
|
||||||
NET.wsclose_stream()
|
NET.wsclose_stream()
|
||||||
SCN.back()
|
SCN.back()
|
||||||
_unlock("quit")
|
NET.unlock("quit")
|
||||||
else
|
else
|
||||||
for i=1,#PLY_NET do
|
for i=1,#PLY_NET do
|
||||||
if PLY_NET[i].uid==d.uid then
|
if PLY_NET[i].sid==d.sid then
|
||||||
rem(PLY_NET,i)
|
rem(PLY_NET,i)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=1,#PLAYERS do
|
for i=1,#PLAYERS do
|
||||||
if PLAYERS[i].userID==d.uid then
|
if PLAYERS[i].sid==d.sid then
|
||||||
rem(PLAYERS,i)
|
rem(PLAYERS,i)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=1,#PLY_ALIVE do
|
for i=1,#PLY_ALIVE do
|
||||||
if PLY_ALIVE[i].userID==d.uid then
|
if PLY_ALIVE[i].sid==d.sid then
|
||||||
rem(PLY_ALIVE,i)
|
rem(PLY_ALIVE,i)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -404,23 +403,16 @@ function NET.updateWS_play()
|
|||||||
resetGameData("qn")
|
resetGameData("qn")
|
||||||
end
|
end
|
||||||
elseif res.action==6 then--One ready
|
elseif res.action==6 then--One ready
|
||||||
if d.uid==USER.uid then
|
for i=1,#PLY_NET do
|
||||||
if PLAYERS[1].ready~=d.ready then
|
if PLY_NET[i].uid==d.uid then
|
||||||
PLAYERS[1].ready=d.ready
|
if PLY_NET[i].ready~=d.ready then
|
||||||
SFX.play("reach",.6)
|
PLY_NET[i].ready=d.ready
|
||||||
end
|
|
||||||
_unlock("ready")
|
|
||||||
else
|
|
||||||
for i=1,#PLAYERS do
|
|
||||||
if PLAYERS[i].userID==d.uid then
|
|
||||||
if PLAYERS[i].ready~=d.ready then
|
|
||||||
PLAYERS[i].ready=d.ready
|
|
||||||
SFX.play("reach",.6)
|
SFX.play("reach",.6)
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
NET.unlock("ready")
|
||||||
elseif res.action==7 then--Ready
|
elseif res.action==7 then--Ready
|
||||||
--?
|
--?
|
||||||
elseif res.action==8 then--Set
|
elseif res.action==8 then--Set
|
||||||
@@ -456,7 +448,7 @@ function NET.updateWS_stream()
|
|||||||
local res=_parse(message)
|
local res=_parse(message)
|
||||||
if res then
|
if res then
|
||||||
if res.type=="Connect"then
|
if res.type=="Connect"then
|
||||||
_unlock("wsc_stream")
|
NET.unlock("wsc_stream")
|
||||||
elseif res.action==0 then--Game start
|
elseif res.action==0 then--Game start
|
||||||
SCN.socketRead("Go",res.data)
|
SCN.socketRead("Go",res.data)
|
||||||
elseif res.action==1 then--Game finished
|
elseif res.action==1 then--Game finished
|
||||||
|
|||||||
@@ -707,7 +707,7 @@ function draw.norm_remote(P)
|
|||||||
--Draw username
|
--Draw username
|
||||||
setFont(30)
|
setFont(30)
|
||||||
gc_setColor(1,1,1)
|
gc_setColor(1,1,1)
|
||||||
mStr(P.userName,150,-60)
|
mStr(P.username,150,-60)
|
||||||
|
|
||||||
--Fill field
|
--Fill field
|
||||||
gc_setColor(0,0,0,.6)
|
gc_setColor(0,0,0,.6)
|
||||||
|
|||||||
@@ -134,10 +134,9 @@ local function newEmptyPlayer(id,mini)
|
|||||||
P.atker,P.atking,P.lastRecv={}
|
P.atker,P.atking,P.lastRecv={}
|
||||||
|
|
||||||
--Network-related
|
--Network-related
|
||||||
P.userName="_"
|
P.username="_"
|
||||||
P.userID=-1
|
P.uid=-1
|
||||||
P.subID=-1
|
P.sid=-1
|
||||||
P.ready=false
|
|
||||||
|
|
||||||
P.dropDelay,P.lockDelay=0,0
|
P.dropDelay,P.lockDelay=0,0
|
||||||
P.showTime=false
|
P.showTime=false
|
||||||
@@ -240,7 +239,7 @@ local function loadRemoteEnv(P,confStr)--Load gameEnv
|
|||||||
conf=JSON.decode(conf)
|
conf=JSON.decode(conf)
|
||||||
else
|
else
|
||||||
conf={}
|
conf={}
|
||||||
LOG.print("Bad conf from "..P.userName.."#"..P.userID)
|
LOG.print("Bad conf from "..P.username.."#"..P.uid)
|
||||||
end
|
end
|
||||||
|
|
||||||
P.gameEnv={}--Current game setting environment
|
P.gameEnv={}--Current game setting environment
|
||||||
@@ -383,10 +382,9 @@ function PLY.newRemotePlayer(id,mini,data)
|
|||||||
P.streamProgress=1
|
P.streamProgress=1
|
||||||
|
|
||||||
data.p=P
|
data.p=P
|
||||||
P.userID=data.uid
|
P.uid=data.uid
|
||||||
P.userName=data.username
|
P.username=data.username
|
||||||
P.subID=data.sid
|
P.sid=data.sid
|
||||||
P.ready=data.ready
|
|
||||||
loadRemoteEnv(P,data.conf)
|
loadRemoteEnv(P,data.conf)
|
||||||
|
|
||||||
applyGameEnv(P)
|
applyGameEnv(P)
|
||||||
@@ -408,8 +406,8 @@ function PLY.newPlayer(id,mini)
|
|||||||
P.type="human"
|
P.type="human"
|
||||||
P.sound=true
|
P.sound=true
|
||||||
|
|
||||||
P.userID=USER.uid
|
P.uid=USER.uid
|
||||||
P.subID=-1
|
P.sid=-1
|
||||||
|
|
||||||
loadGameEnv(P)
|
loadGameEnv(P)
|
||||||
applyGameEnv(P)
|
applyGameEnv(P)
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ function Player:setConf(confStr)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
LOG.print("Bad conf from "..self.userName.."#"..self.userID)
|
LOG.print("Bad conf from "..self.username.."#"..self.uid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ function Player:attack(R,send,time,line,fromStream)
|
|||||||
if self.type=="human"then--Local player attack others
|
if self.type=="human"then--Local player attack others
|
||||||
ins(GAME.rep,GAME.frame)
|
ins(GAME.rep,GAME.frame)
|
||||||
ins(GAME.rep,
|
ins(GAME.rep,
|
||||||
R.subID+
|
R.sid+
|
||||||
send*0x100+
|
send*0x100+
|
||||||
time*0x10000+
|
time*0x10000+
|
||||||
line*0x100000000+
|
line*0x100000000+
|
||||||
@@ -350,7 +350,7 @@ function Player:attack(R,send,time,line,fromStream)
|
|||||||
if fromStream and R.type=="human"then--Local player receiving lines
|
if fromStream and R.type=="human"then--Local player receiving lines
|
||||||
ins(GAME.rep,GAME.frame)
|
ins(GAME.rep,GAME.frame)
|
||||||
ins(GAME.rep,
|
ins(GAME.rep,
|
||||||
self.subID+
|
self.sid+
|
||||||
send*0x100+
|
send*0x100+
|
||||||
time*0x10000+
|
time*0x10000+
|
||||||
line*0x100000000+
|
line*0x100000000+
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ function update.remote_alive(P,dt)
|
|||||||
local line=int(event/0x100000000)%0x10000
|
local line=int(event/0x100000000)%0x10000
|
||||||
local L=PLY_ALIVE
|
local L=PLY_ALIVE
|
||||||
for i=1,#L do
|
for i=1,#L do
|
||||||
if L[i].subID==sid then
|
if L[i].sid==sid then
|
||||||
P:attack(L[i],amount,time,line,true)
|
P:attack(L[i],amount,time,line,true)
|
||||||
if SETTING.atkFX>0 then
|
if SETTING.atkFX>0 then
|
||||||
P:createBeam(L[i],amount,P.cur.color)
|
P:createBeam(L[i],amount,P.cur.color)
|
||||||
@@ -408,7 +408,7 @@ function update.remote_alive(P,dt)
|
|||||||
local L=PLY_ALIVE
|
local L=PLY_ALIVE
|
||||||
local sid=event%0x100
|
local sid=event%0x100
|
||||||
for i=1,#L do
|
for i=1,#L do
|
||||||
if L[i].subID==sid then
|
if L[i].sid==sid then
|
||||||
P:receive(
|
P:receive(
|
||||||
L[i],
|
L[i],
|
||||||
int(event/0x100)%0x100,--amount
|
int(event/0x100)%0x100,--amount
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ function scene.sceneInit()
|
|||||||
textBox.hide=true
|
textBox.hide=true
|
||||||
textBox:clear()
|
textBox:clear()
|
||||||
|
|
||||||
resetGameData("n")
|
|
||||||
noTouch=not SETTING.VKSwitch
|
noTouch=not SETTING.VKSwitch
|
||||||
playing=false
|
playing=false
|
||||||
lastUpstreamTime=0
|
lastUpstreamTime=0
|
||||||
@@ -36,7 +35,7 @@ function scene.sceneInit()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function scene.touchDown(x,y)
|
function scene.touchDown(x,y)
|
||||||
if noTouch then return end
|
if noTouch or not playing then return end
|
||||||
|
|
||||||
local t=onVirtualkey(x,y)
|
local t=onVirtualkey(x,y)
|
||||||
if t then
|
if t then
|
||||||
@@ -45,7 +44,7 @@ function scene.touchDown(x,y)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.touchUp(x,y)
|
function scene.touchUp(x,y)
|
||||||
if noTouch then return end
|
if noTouch or not playing then return end
|
||||||
|
|
||||||
local t=onVirtualkey(x,y)
|
local t=onVirtualkey(x,y)
|
||||||
if t then
|
if t then
|
||||||
@@ -53,7 +52,7 @@ function scene.touchUp(x,y)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.touchMove()
|
function scene.touchMove()
|
||||||
if noTouch or touchMoveLastFrame then return end
|
if noTouch or touchMoveLastFrame or not playing then return end
|
||||||
touchMoveLastFrame=true
|
touchMoveLastFrame=true
|
||||||
|
|
||||||
local L=tc.getTouches()
|
local L=tc.getTouches()
|
||||||
@@ -93,9 +92,7 @@ function scene.keyDown(key)
|
|||||||
VK[k].pressTime=10
|
VK[k].pressTime=10
|
||||||
end
|
end
|
||||||
elseif key=="space"then
|
elseif key=="space"then
|
||||||
if not NET.getLock("ready")then
|
NET.signal_ready(not PLY_NET[1].ready)
|
||||||
NET.signal_ready(not PLAYERS[1].ready)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.keyUp(key)
|
function scene.keyUp(key)
|
||||||
@@ -142,9 +139,6 @@ function scene.socketRead(cmd,d)
|
|||||||
COLOR.Y,text.joinRoom,
|
COLOR.Y,text.joinRoom,
|
||||||
}
|
}
|
||||||
SFX.play("click")
|
SFX.play("click")
|
||||||
if not playing then
|
|
||||||
resetGameData("qn")
|
|
||||||
end
|
|
||||||
elseif cmd=="Leave"then
|
elseif cmd=="Leave"then
|
||||||
textBox:push{
|
textBox:push{
|
||||||
COLOR.lR,d.username,
|
COLOR.lR,d.username,
|
||||||
@@ -163,6 +157,9 @@ function scene.socketRead(cmd,d)
|
|||||||
elseif cmd=="Go"then
|
elseif cmd=="Go"then
|
||||||
if not playing then
|
if not playing then
|
||||||
playing=true
|
playing=true
|
||||||
|
for i=1,#PLY_NET do
|
||||||
|
PLY_NET[i].ready=false
|
||||||
|
end
|
||||||
lastUpstreamTime=0
|
lastUpstreamTime=0
|
||||||
upstreamProgress=1
|
upstreamProgress=1
|
||||||
resetGameData("n",d.seed)
|
resetGameData("n",d.seed)
|
||||||
@@ -171,7 +168,6 @@ function scene.socketRead(cmd,d)
|
|||||||
end
|
end
|
||||||
elseif cmd=="Finish"then
|
elseif cmd=="Finish"then
|
||||||
playing=false
|
playing=false
|
||||||
resetGameData("n")
|
|
||||||
local winnerUID
|
local winnerUID
|
||||||
for _,p in next,d.result do
|
for _,p in next,d.result do
|
||||||
if p.place==1 then
|
if p.place==1 then
|
||||||
@@ -189,12 +185,12 @@ function scene.socketRead(cmd,d)
|
|||||||
elseif cmd=="Stream"then
|
elseif cmd=="Stream"then
|
||||||
if d.uid~=USER.uid and playing then
|
if d.uid~=USER.uid and playing then
|
||||||
for _,P in next,PLAYERS do
|
for _,P in next,PLAYERS do
|
||||||
if P.userID==d.uid then
|
if P.uid==d.uid then
|
||||||
local res,stream=pcall(love.data.decode,"string","base64",d.stream)
|
local res,stream=pcall(love.data.decode,"string","base64",d.stream)
|
||||||
if res then
|
if res then
|
||||||
pumpRecording(stream,P.stream)
|
pumpRecording(stream,P.stream)
|
||||||
else
|
else
|
||||||
LOG.print("Bad stream from "..P.userName.."#"..P.userID)
|
LOG.print("Bad stream from "..P.username.."#"..P.uid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -237,6 +233,7 @@ function scene.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function scene.draw()
|
function scene.draw()
|
||||||
|
if playing then
|
||||||
drawFWM()
|
drawFWM()
|
||||||
|
|
||||||
--Players
|
--Players
|
||||||
@@ -249,7 +246,24 @@ function scene.draw()
|
|||||||
|
|
||||||
--Warning
|
--Warning
|
||||||
drawWarning()
|
drawWarning()
|
||||||
|
else
|
||||||
|
setFont(40)
|
||||||
|
for i=1,#PLY_NET do
|
||||||
|
local p=PLY_NET[i]
|
||||||
|
|
||||||
|
if p.ready then
|
||||||
|
gc.setColor(.4,1,.4)
|
||||||
|
else
|
||||||
|
gc.setColor(1,1,1)
|
||||||
|
end
|
||||||
|
gc.rectangle("fill",50,60+50*i+14,30,30)
|
||||||
|
|
||||||
|
gc.setColor(.5,.5,.5)
|
||||||
|
gc.print("#"..p.uid,90,60+50*i)
|
||||||
|
gc.setColor(1,1,1)
|
||||||
|
gc.print(p.username,230,60+50*i)
|
||||||
|
end
|
||||||
|
end
|
||||||
--New message
|
--New message
|
||||||
if textBox.new and textBox.hide then
|
if textBox.new and textBox.hide then
|
||||||
setFont(30)
|
setFont(30)
|
||||||
@@ -259,11 +273,11 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
textBox,
|
textBox,
|
||||||
WIDGET.newKey{name="ready",x=640,y=440,w=200,h=80,color="yellow",font=40,code=pressKey"space",hide=function()
|
WIDGET.newKey{name="ready",x=900,y=560,w=400,h=100,color="yellow",font=40,code=pressKey"space",hide=function()
|
||||||
return
|
return
|
||||||
playing or
|
playing or
|
||||||
not textBox.hide or
|
not textBox.hide or
|
||||||
NET.getLock("ready")
|
NET.getlock("ready")
|
||||||
end},
|
end},
|
||||||
WIDGET.newKey{name="hideChat",fText="...",x=380,y=35,w=60,font=35,code=pressKey"\\"},
|
WIDGET.newKey{name="hideChat",fText="...",x=380,y=35,w=60,font=35,code=pressKey"\\"},
|
||||||
WIDGET.newKey{name="quit",fText="X",x=900,y=35,w=60,font=40,code=pressKey"escape"},
|
WIDGET.newKey{name="quit",fText="X",x=900,y=35,w=60,font=40,code=pressKey"escape"},
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ function scene.keyDown(k)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif k=="return"then
|
elseif k=="return"then
|
||||||
if NET.getLock("fetchRoom")then return end
|
if NET.getlock("fetchRoom")then return end
|
||||||
if NET.roomList[selected].private then
|
if NET.roomList[selected].private then
|
||||||
LOG.print("Can't enter private room now")
|
LOG.print("Can't enter private room now")
|
||||||
return
|
return
|
||||||
@@ -63,7 +63,7 @@ function scene.keyDown(k)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function scene.update(dt)
|
function scene.update(dt)
|
||||||
if not NET.getLock("fetchRoom")then
|
if not NET.getlock("fetchRoom")then
|
||||||
fetchTimer=fetchTimer-dt
|
fetchTimer=fetchTimer-dt
|
||||||
if fetchTimer<=0 then
|
if fetchTimer<=0 then
|
||||||
fetchRoom()
|
fetchRoom()
|
||||||
@@ -103,8 +103,8 @@ end
|
|||||||
|
|
||||||
local function hide_noRoom()return #NET.roomList==0 end
|
local function hide_noRoom()return #NET.roomList==0 end
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
WIDGET.newText{name="refreshing",x=640,y=255,font=45,hide=function()return not NET.getLock("fetchRoom")end},
|
WIDGET.newText{name="refreshing",x=640,y=255,font=45,hide=function()return not NET.getlock("fetchRoom")end},
|
||||||
WIDGET.newText{name="noRoom", x=640,y=260,font=40,hide=function()return #NET.roomList>0 or NET.getLock("fetchRoom")end},
|
WIDGET.newText{name="noRoom", x=640,y=260,font=40,hide=function()return #NET.roomList>0 or NET.getlock("fetchRoom")end},
|
||||||
WIDGET.newKey{name="refresh", x=240,y=620,w=140,h=140,font=35,code=fetchRoom, hide=function()return fetchTimer>3.26 end},
|
WIDGET.newKey{name="refresh", x=240,y=620,w=140,h=140,font=35,code=fetchRoom, hide=function()return fetchTimer>3.26 end},
|
||||||
WIDGET.newKey{name="new", x=440,y=620,w=140,h=140,font=25,code=pressKey"n"},
|
WIDGET.newKey{name="new", x=440,y=620,w=140,h=140,font=25,code=pressKey"n"},
|
||||||
WIDGET.newKey{name="join", x=640,y=620,w=140,h=140,font=40,code=pressKey"return", hide=hide_noRoom},
|
WIDGET.newKey{name="join", x=640,y=620,w=140,h=140,font=40,code=pressKey"return", hide=hide_noRoom},
|
||||||
|
|||||||
Reference in New Issue
Block a user