NETPLY模块删掉一堆方法,先外部直接改数据,玩家会根据状态更换样式
游戏开始/结束时自主同步正确的服务端玩家状态
This commit is contained in:
@@ -37,7 +37,7 @@ function NET.connectLost()
|
|||||||
while SCN.stack[#SCN.stack-1]~='main' and #SCN.stack>0 do SCN.pop() end
|
while SCN.stack[#SCN.stack-1]~='main' and #SCN.stack>0 do SCN.pop() end
|
||||||
SCN.back()
|
SCN.back()
|
||||||
end
|
end
|
||||||
function NET.freshRoomState()
|
function NET.freshRoomAllReady()
|
||||||
local playCount,readyCount=0,0
|
local playCount,readyCount=0,0
|
||||||
for j=1,#NETPLY.list do
|
for j=1,#NETPLY.list do
|
||||||
if NETPLY.list[j].playMode=='Gamer' then playCount=playCount+1 end
|
if NETPLY.list[j].playMode=='Gamer' then playCount=playCount+1 end
|
||||||
@@ -549,8 +549,8 @@ end
|
|||||||
function NET.player_joinGroup(gid)
|
function NET.player_joinGroup(gid)
|
||||||
wsSend(actMap.player_joinGroup,gid)
|
wsSend(actMap.player_joinGroup,gid)
|
||||||
end
|
end
|
||||||
function NET.player_setReadyMode(mode)
|
function NET.player_setReady(isReady)
|
||||||
wsSend(actMap.player_setReadyMode,mode)
|
wsSend(actMap.player_setReadyMode,isReady)
|
||||||
end
|
end
|
||||||
function NET.player_setHost(pid)
|
function NET.player_setHost(pid)
|
||||||
wsSend(actMap.player_setHost,{
|
wsSend(actMap.player_setHost,{
|
||||||
@@ -660,7 +660,7 @@ function NET.wsCallBack.room_remove()
|
|||||||
_playerLeaveRoom(USER.uid)
|
_playerLeaveRoom(USER.uid)
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_updateConf(body)
|
function NET.wsCallBack.player_updateConf(body)
|
||||||
NETPLY.setConf(body.data.playerId,body.data.config)
|
NETPLY.map[body.data.playerId].config=body.data.config
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_finish(body)-- TODO
|
function NET.wsCallBack.player_finish(body)-- TODO
|
||||||
end
|
end
|
||||||
@@ -674,10 +674,12 @@ function NET.wsCallBack.player_stream(body)
|
|||||||
_pumpStream(body.data)
|
_pumpStream(body.data)
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setPlayMode(body)
|
function NET.wsCallBack.player_setPlayMode(body)
|
||||||
NETPLY.setPlayMode(body.data.playerId,body.data.type)
|
NETPLY.map[body.data.playerId].playMode=body.data.type
|
||||||
|
NET.freshRoomAllReady()
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setReadyMode(body)
|
function NET.wsCallBack.player_setReadyMode(body)
|
||||||
NETPLY.setReadyMode(body.data.playerId,body.data.isReady and 'Ready' or 'Standby')
|
NETPLY.map[body.data.playerId].readyMode=body.data.isReady and 'Ready' or 'Standby'
|
||||||
|
NET.freshRoomAllReady()
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.match_finish()
|
function NET.wsCallBack.match_finish()
|
||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
@@ -687,8 +689,14 @@ function NET.wsCallBack.match_finish()
|
|||||||
end
|
end
|
||||||
function NET.wsCallBack.match_ready()-- TODO
|
function NET.wsCallBack.match_ready()-- TODO
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.match_start()
|
function NET.wsCallBack.match_start(body)
|
||||||
TASK.lock('netPlaying')
|
TASK.lock('netPlaying')
|
||||||
|
if body.data then
|
||||||
|
NET.seed=body.data
|
||||||
|
else
|
||||||
|
NET.seed=0
|
||||||
|
MES.new("error",'No seed received')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function NET.ws_connect()
|
function NET.ws_connect()
|
||||||
|
|||||||
@@ -131,26 +131,6 @@ function NETPLY.remove(uid)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function NETPLY.getCount() return #PLYlist end
|
|
||||||
function NETPLY.getSelfPlayMode() return PLYmap[USER.uid].playMode end
|
|
||||||
function NETPLY.getSelfReadyMode() return PLYmap[USER.uid].readyMode end
|
|
||||||
|
|
||||||
function NETPLY.setPlayerObj(ply,p) ply.p=p end
|
|
||||||
function NETPLY.setConf(uid,config) PLYmap[uid].config=config end
|
|
||||||
function NETPLY.setPlayMode(uid,mode)
|
|
||||||
local p=PLYmap[uid]
|
|
||||||
if p and p.playMode~=mode then
|
|
||||||
p.playMode=mode
|
|
||||||
NET.freshRoomState()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function NETPLY.setReadyMode(uid,mode)
|
|
||||||
local p=PLYmap[uid]
|
|
||||||
if p and p.readyMode~=mode then
|
|
||||||
p.readyMode=mode
|
|
||||||
NET.freshRoomState()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function NETPLY.setPlace(uid,place) PLYmap[uid].place=place end
|
function NETPLY.setPlace(uid,place) PLYmap[uid].place=place end
|
||||||
function NETPLY.setStat(uid,S)
|
function NETPLY.setStat(uid,S)
|
||||||
PLYmap[uid].stat={
|
PLYmap[uid].stat={
|
||||||
@@ -200,7 +180,15 @@ function NETPLY.draw()
|
|||||||
gc_translate(p.x,p.y)
|
gc_translate(p.x,p.y)
|
||||||
-- Rectangle
|
-- Rectangle
|
||||||
if p.playMode=='Gamer' then
|
if p.playMode=='Gamer' then
|
||||||
gc_setColor(p.readyMode=='Standby' and COLOR.Z or COLOR.N)
|
if p.readyMode=='Standby' then
|
||||||
|
gc_setColor(COLOR.Z)
|
||||||
|
elseif p.readyMode=='Ready' then
|
||||||
|
gc_setColor(COLOR.N)
|
||||||
|
else
|
||||||
|
gc_setColor(.26,.62,.26,.26)
|
||||||
|
gc_rectangle('fill',0,0,p.w,p.h)
|
||||||
|
gc_setColor(COLOR.lG)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
gc_setColor(COLOR.dX)
|
gc_setColor(COLOR.dX)
|
||||||
gc_rectangle('fill',0,0,p.w,p.h)
|
gc_rectangle('fill',0,0,p.w,p.h)
|
||||||
|
|||||||
@@ -406,7 +406,6 @@ function PLY.newRemotePlayer(id,mini,p)
|
|||||||
P.draw=ply_draw.norm
|
P.draw=ply_draw.norm
|
||||||
P:startStreaming()
|
P:startStreaming()
|
||||||
|
|
||||||
NETPLY.setPlayerObj(p,P)
|
|
||||||
P.uid=p.uid
|
P.uid=p.uid
|
||||||
P.username=USERS.getUsername(p.uid)
|
P.username=USERS.getUsername(p.uid)
|
||||||
P.sid=NET.uid_sid[p.uid]
|
P.sid=NET.uid_sid[p.uid]
|
||||||
|
|||||||
@@ -27,15 +27,15 @@ local function _hideReadyUI()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function _setCancel()
|
local function _setCancel()
|
||||||
if NETPLY.getSelfPlayMode()=='Gamer' then
|
if NETPLY.map[USER.uid].playMode=='Gamer' then
|
||||||
NET.player_setReadyMode(false)
|
NET.player_setReady(false)
|
||||||
else
|
else
|
||||||
NET.player_setPlayMode('Gamer')
|
NET.player_setPlayMode('Gamer')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function _setReady()
|
local function _setReady()
|
||||||
NET.player_setPlayMode('Gamer')
|
NET.player_setPlayMode('Gamer')
|
||||||
NET.player_setReadyMode(true)
|
NET.player_setReady(true)
|
||||||
end
|
end
|
||||||
local function _setSpectate()
|
local function _setSpectate()
|
||||||
NET.player_setPlayMode('Spectator')
|
NET.player_setPlayMode('Spectator')
|
||||||
@@ -157,7 +157,7 @@ function scene.keyDown(key,isRep)
|
|||||||
end
|
end
|
||||||
elseif not _hideReadyUI() then
|
elseif not _hideReadyUI() then
|
||||||
if key=='space' then
|
if key=='space' then
|
||||||
if NETPLY.getSelfPlayMode()~='Gamer' then
|
if NETPLY.map[USER.uid].playMode~='Gamer' then
|
||||||
(kb.isDown('lctrl','rctrl','lalt','ralt') and _setSpectate or _setReady)()
|
(kb.isDown('lctrl','rctrl','lalt','ralt') and _setSpectate or _setReady)()
|
||||||
else
|
else
|
||||||
_setCancel()
|
_setCancel()
|
||||||
@@ -207,6 +207,10 @@ function scene.update(dt)
|
|||||||
if not TASK.getLock('netPlaying') then
|
if not TASK.getLock('netPlaying') then
|
||||||
playing=false
|
playing=false
|
||||||
BG.set()
|
BG.set()
|
||||||
|
for i=1,#NETPLY.list do
|
||||||
|
NETPLY.list[i].readyMode='Standby'
|
||||||
|
end
|
||||||
|
NET.freshRoomAllReady()
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
local P1=PLAYERS[1]
|
local P1=PLAYERS[1]
|
||||||
@@ -246,6 +250,9 @@ function scene.update(dt)
|
|||||||
upstreamProgress=1
|
upstreamProgress=1
|
||||||
resetGameData('n',NET.seed)
|
resetGameData('n',NET.seed)
|
||||||
NETPLY.mouseMove(0,0)
|
NETPLY.mouseMove(0,0)
|
||||||
|
for i=1,#NETPLY.list do
|
||||||
|
NETPLY.list[i].readyMode='Playing'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -284,7 +291,7 @@ function scene.draw()
|
|||||||
setFont(25)
|
setFont(25)
|
||||||
gc_printf(NET.roomState.info.name,0,685,1270,'right')
|
gc_printf(NET.roomState.info.name,0,685,1270,'right')
|
||||||
setFont(40)
|
setFont(40)
|
||||||
gc_print(NETPLY.getCount().."/"..NET.roomState.capacity,70,655)
|
gc_print(#NETPLY.list.."/"..NET.roomState.capacity,70,655)
|
||||||
if NET.roomState.private then
|
if NET.roomState.private then
|
||||||
gc_draw(IMG.lock,30,668)
|
gc_draw(IMG.lock,30,668)
|
||||||
end
|
end
|
||||||
@@ -308,8 +315,8 @@ function scene.draw()
|
|||||||
gc_print("M",430,10)
|
gc_print("M",430,10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function _hideF_ready() return _hideReadyUI() or (NETPLY.getSelfPlayMode()=='Spectator' or NETPLY.getSelfReadyMode()=='Ready') end
|
local function _hideF_ready() return _hideReadyUI() or (NETPLY.map[USER.uid].playMode=='Spectator' or NETPLY.map[USER.uid].readyMode=='Ready') end
|
||||||
local function _hideF_standby() return _hideReadyUI() or not (NETPLY.getSelfPlayMode()=='Spectator' or NETPLY.getSelfReadyMode()=='Ready') end
|
local function _hideF_standby() return _hideReadyUI() or not (NETPLY.map[USER.uid].playMode=='Spectator' or NETPLY.map[USER.uid].readyMode=='Ready') end
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
textBox,
|
textBox,
|
||||||
inputBox,
|
inputBox,
|
||||||
|
|||||||
Reference in New Issue
Block a user