框架跟进
推进中途加入房间的观战相关
This commit is contained in:
Submodule Zframework updated: 632e95d48d...6581acd9e8
8
main.lua
8
main.lua
@@ -60,11 +60,11 @@ BGM.setMaxSources(5)
|
|||||||
VOC.setDiversion(.62)
|
VOC.setDiversion(.62)
|
||||||
|
|
||||||
WIDGET.setOnChange(function()
|
WIDGET.setOnChange(function()
|
||||||
if SCN.stack[#SCN.stack]~='custom_field' then
|
if SCN.current~='custom_field' then
|
||||||
local colorList=THEME.getThemeColor()
|
local colorList=THEME.getThemeColor()
|
||||||
if not colorList then return end
|
if not colorList then return end
|
||||||
local rnd=math.random
|
local rnd=math.random
|
||||||
for _,W in next,SCN.scenes[SCN.stack[#SCN.stack]].widgetList do
|
for _,W in next,SCN.scenes[SCN.current].widgetList do
|
||||||
if W.color then
|
if W.color then
|
||||||
W.color=colorList[rnd(#colorList)]
|
W.color=colorList[rnd(#colorList)]
|
||||||
end
|
end
|
||||||
@@ -218,10 +218,10 @@ do-- Z.setOnFocus
|
|||||||
TASK.new(task_autoSoundOn)
|
TASK.new(task_autoSoundOn)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if SCN.stack[#SCN.stack]=='game' and SETTING.autoPause then
|
if SCN.current=='game' and SETTING.autoPause then
|
||||||
pauseGame()
|
pauseGame()
|
||||||
end
|
end
|
||||||
if SETTING.autoMute and SCN.stack[#SCN.stack]~='music' then
|
if SETTING.autoMute and SCN.current~='music' then
|
||||||
TASK.removeTask_code(task_autoSoundOn)
|
TASK.removeTask_code(task_autoSoundOn)
|
||||||
TASK.new(task_autoSoundOff)
|
TASK.new(task_autoSoundOff)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ local WS=WS
|
|||||||
local NET={
|
local NET={
|
||||||
uid=false,
|
uid=false,
|
||||||
uid_sid={},
|
uid_sid={},
|
||||||
|
storedStream={},
|
||||||
|
|
||||||
roomState={-- A copy of room structure on server
|
roomState={-- A copy of room structure on server
|
||||||
info={
|
info={
|
||||||
@@ -18,7 +19,7 @@ local NET={
|
|||||||
},
|
},
|
||||||
capacity=false,
|
capacity=false,
|
||||||
private=false,
|
private=false,
|
||||||
state='Playing',
|
state='Standby',
|
||||||
},
|
},
|
||||||
|
|
||||||
spectate=false,-- If player is spectating
|
spectate=false,-- If player is spectating
|
||||||
@@ -439,7 +440,7 @@ end
|
|||||||
|
|
||||||
--Remove player when leave
|
--Remove player when leave
|
||||||
local function _playerLeaveRoom(uid)
|
local function _playerLeaveRoom(uid)
|
||||||
if SCN.stack[#SCN.stack]=='net_game' then
|
if SCN.current=='net_game' then
|
||||||
for i=1,#PLAYERS do if PLAYERS[i].uid==uid then table.remove(PLAYERS,i) break end end
|
for i=1,#PLAYERS do if PLAYERS[i].uid==uid then table.remove(PLAYERS,i) break end end
|
||||||
for i=1,#PLY_ALIVE do if PLY_ALIVE[i].uid==uid then table.remove(PLY_ALIVE,i) break end end
|
for i=1,#PLY_ALIVE do if PLY_ALIVE[i].uid==uid then table.remove(PLY_ALIVE,i) break end end
|
||||||
if uid==USER.uid then
|
if uid==USER.uid then
|
||||||
@@ -585,7 +586,7 @@ function NET.wsCallBack.global_getOnlineCount(body)
|
|||||||
NET.onlineCount=tonumber(body.data) or "_"
|
NET.onlineCount=tonumber(body.data) or "_"
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.room_chat(body)
|
function NET.wsCallBack.room_chat(body)
|
||||||
if SCN.stack[#SCN.stack]=='net_game' then
|
if SCN.current=='net_game' then
|
||||||
TASK.unlock('receiveMessage')
|
TASK.unlock('receiveMessage')
|
||||||
TASK.lock('receiveMessage',1)
|
TASK.lock('receiveMessage',1)
|
||||||
NET.textBox:push{
|
NET.textBox:push{
|
||||||
@@ -623,6 +624,8 @@ function NET.wsCallBack.room_enter(body)
|
|||||||
|
|
||||||
NET.roomState=body.data
|
NET.roomState=body.data
|
||||||
NETPLY.clear()
|
NETPLY.clear()
|
||||||
|
destroyPlayers()
|
||||||
|
TABLE.cut(NET.storedStream)
|
||||||
loadGame('netBattle',true,true)
|
loadGame('netBattle',true,true)
|
||||||
for _,p in next,body.data.players do
|
for _,p in next,body.data.players do
|
||||||
NETPLY.add{
|
NETPLY.add{
|
||||||
@@ -634,7 +637,18 @@ function NET.wsCallBack.room_enter(body)
|
|||||||
config=p.config,
|
config=p.config,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
NET.freshRoomAllReady()
|
if NET.roomState.state=='Playing' then
|
||||||
|
for _,p in next,body.data.players do
|
||||||
|
table.insert(NET.storedStream,{
|
||||||
|
playerId=p.playerId,
|
||||||
|
data=p.history,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
NET.seed=body.data.seed
|
||||||
|
TASK.lock('netPlaying')
|
||||||
|
else
|
||||||
|
NET.freshRoomAllReady()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
local p=body.data
|
local p=body.data
|
||||||
NETPLY.add{
|
NETPLY.add{
|
||||||
@@ -670,18 +684,22 @@ function NET.wsCallBack.room_fetch(body)
|
|||||||
SCN.scenes.net_rooms.widgetList.roomList:setList(body.data)
|
SCN.scenes.net_rooms.widgetList.roomList:setList(body.data)
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.room_setPW()
|
function NET.wsCallBack.room_setPW()
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
MES.new(text.roomPasswordChanged)
|
MES.new(text.roomPasswordChanged)
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.room_remove()
|
function NET.wsCallBack.room_remove()
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
MES.new('info',text.roomRemoved)
|
MES.new('info',text.roomRemoved)
|
||||||
_playerLeaveRoom(USER.uid)
|
_playerLeaveRoom(USER.uid)
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_updateConf(body)
|
function NET.wsCallBack.player_updateConf(body)
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
if type(body.data)=='table' then
|
if type(body.data)=='table' then
|
||||||
NETPLY.map[body.data.playerId].config=body.data.config
|
NETPLY.map[body.data.playerId].config=body.data.config
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_finish(body)
|
function NET.wsCallBack.player_finish(body)
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
for _,P in next,PLY_ALIVE do
|
for _,P in next,PLY_ALIVE do
|
||||||
if P.uid==body.data.playerId then
|
if P.uid==body.data.playerId then
|
||||||
P.loseTimer=26
|
P.loseTimer=26
|
||||||
@@ -691,9 +709,11 @@ function NET.wsCallBack.player_finish(body)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_joinGroup(body)
|
function NET.wsCallBack.player_joinGroup(body)
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
NETPLY.map[body.data.playerId].group=body.data.group
|
NETPLY.map[body.data.playerId].group=body.data.group
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setHost(body)
|
function NET.wsCallBack.player_setHost(body)
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
if body.data.role=='Admin' then
|
if body.data.role=='Admin' then
|
||||||
MES.new('info',text.becomeHost:repD(_getFullName(body.data.playerId)))
|
MES.new('info',text.becomeHost:repD(_getFullName(body.data.playerId)))
|
||||||
end
|
end
|
||||||
@@ -702,17 +722,21 @@ end
|
|||||||
function NET.wsCallBack.player_setState(body)-- not used
|
function NET.wsCallBack.player_setState(body)-- not used
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_stream(body)
|
function NET.wsCallBack.player_stream(body)
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
_pumpStream(body.data)
|
_pumpStream(body.data)
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setPlayMode(body)
|
function NET.wsCallBack.player_setPlayMode(body)
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
NETPLY.map[body.data.playerId].playMode=body.data.type
|
NETPLY.map[body.data.playerId].playMode=body.data.type
|
||||||
NET.freshRoomAllReady()
|
NET.freshRoomAllReady()
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setReadyMode(body)
|
function NET.wsCallBack.player_setReadyMode(body)
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
NETPLY.map[body.data.playerId].readyMode=body.data.isReady and 'Ready' or 'Standby'
|
NETPLY.map[body.data.playerId].readyMode=body.data.isReady and 'Ready' or 'Standby'
|
||||||
NET.freshRoomAllReady()
|
NET.freshRoomAllReady()
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.match_finish()
|
function NET.wsCallBack.match_finish()
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
for _,P in next,PLAYERS do
|
for _,P in next,PLAYERS do
|
||||||
NETPLY.setStat(P.uid,P.stat)
|
NETPLY.setStat(P.uid,P.stat)
|
||||||
end
|
end
|
||||||
@@ -724,6 +748,7 @@ end
|
|||||||
function NET.wsCallBack.match_ready()-- not used
|
function NET.wsCallBack.match_ready()-- not used
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.match_start(body)
|
function NET.wsCallBack.match_start(body)
|
||||||
|
if SCN.current~='net_game' then return end
|
||||||
TASK.lock('netPlaying')
|
TASK.lock('netPlaying')
|
||||||
NET.seed=body.data and body.data.seed
|
NET.seed=body.data and body.data.seed
|
||||||
if not NET.seed then
|
if not NET.seed then
|
||||||
@@ -804,7 +829,7 @@ function NET.ws_update()
|
|||||||
elseif msg then
|
elseif msg then
|
||||||
msg=JSON.decode(msg)
|
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(("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
|
if msg.errno~=0 then
|
||||||
parseError(msg.message~=nil and msg.message or msg)
|
parseError(msg.message~=nil and msg.message or msg)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -2192,7 +2192,7 @@ local function task_autoPause()
|
|||||||
while true do
|
while true do
|
||||||
yield()
|
yield()
|
||||||
time=time+1
|
time=time+1
|
||||||
if SCN.stack[#SCN.stack]~='game' or PLAYERS[1].frameRun<180 then
|
if SCN.current~='game' or PLAYERS[1].frameRun<180 then
|
||||||
return
|
return
|
||||||
elseif time==120 then
|
elseif time==120 then
|
||||||
pauseGame()
|
pauseGame()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ local scene={}
|
|||||||
|
|
||||||
function scene.sceneInit()
|
function scene.sceneInit()
|
||||||
BGcolor=math.random()>.026 and{.3,.5,.9} or{.62,.3,.926}
|
BGcolor=math.random()>.026 and{.3,.5,.9} or{.62,.3,.926}
|
||||||
sysAndScn=SYSTEM.."-"..VERSION.string.." scene:"..Z.getErr('#').scene
|
sysAndScn=SYSTEM.."-"..VERSION.string.." scene:"..Z.getErr('#').scene
|
||||||
errorText=LOADED and text.errorMsg or "An error has occurred while the game was loading.\nAn error log has been created so you can send it to the author."
|
errorText=LOADED and text.errorMsg or "An error has occurred while the game was loading.\nAn error log has been created so you can send it to the author."
|
||||||
errorShot,errorInfo=Z.getErr('#').shot,Z.getErr('#').mes
|
errorShot,errorInfo=Z.getErr('#').shot,Z.getErr('#').mes
|
||||||
NET.ws_close()
|
NET.ws_close()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function scene.sceneInit()
|
|||||||
if THEME.cur=='halloween' then
|
if THEME.cur=='halloween' then
|
||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
TEST.yieldT(.26)
|
TEST.yieldT(.26)
|
||||||
while SCN.stack[#SCN.stack]=='main' do
|
while SCN.current=='main' do
|
||||||
flash=.355
|
flash=.355
|
||||||
SFX.play('clear_'..math.random(4,6),1,math.random()*2-1,-9-math.random()*3)
|
SFX.play('clear_'..math.random(4,6),1,math.random()*2-1,-9-math.random()*3)
|
||||||
TEST.yieldT(.626+math.random()*6.26)
|
TEST.yieldT(.626+math.random()*6.26)
|
||||||
|
|||||||
@@ -247,8 +247,9 @@ function scene.update(dt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
NETPLY.update(dt)
|
if not TASK.getLock('netPlaying') then
|
||||||
if TASK.getLock('netPlaying') and not playing then
|
NETPLY.update(dt)
|
||||||
|
else
|
||||||
playing=true
|
playing=true
|
||||||
TASK.lock('netPlaying')
|
TASK.lock('netPlaying')
|
||||||
lastUpstreamTime=0
|
lastUpstreamTime=0
|
||||||
|
|||||||
Reference in New Issue
Block a user