联网对战测试推进22
This commit is contained in:
@@ -42,6 +42,16 @@ local function tick_httpREQ_autoLogin(task)
|
||||
if response.code==200 and res.message=="OK"then
|
||||
LOGIN=true
|
||||
LOG.print(text.loginSuccessed)
|
||||
httpRequest(
|
||||
TICK_httpREQ_getUserInfo,
|
||||
PATH.api..PATH.users,
|
||||
"GET",
|
||||
{["Content-Type"]="application/json"},
|
||||
json.encode{
|
||||
email=USER.email,
|
||||
auth_token=USER.auth_token,
|
||||
}
|
||||
)
|
||||
else
|
||||
LOGIN=false
|
||||
LOG.print(text.loginFailed..": "..text.httpCode..response.code.."-"..res.message,"warn")
|
||||
|
||||
@@ -9,13 +9,21 @@ local function tick_httpREQ_newLogin(task)
|
||||
LOGIN=true
|
||||
USER.email=res.email
|
||||
USER.auth_token=res.auth_token
|
||||
USER.name=res.name
|
||||
USER.id=res.id
|
||||
USER.motto=res.motto
|
||||
USER.avatar=res.avatar
|
||||
FILE.save(USER,"conf/user","q")
|
||||
LOG.print(text.loginSuccessed)
|
||||
|
||||
httpRequest(
|
||||
TICK_httpREQ_getUserInfo,
|
||||
PATH.api..PATH.users,
|
||||
"GET",
|
||||
{["Content-Type"]="application/json"},
|
||||
json.encode{
|
||||
email=USER.email,
|
||||
auth_token=USER.auth_token,
|
||||
}
|
||||
)
|
||||
|
||||
httpRequest(
|
||||
TICK_httpREQ_getAccessToken,
|
||||
PATH.api..PATH.access,
|
||||
|
||||
@@ -68,7 +68,7 @@ function scene.socketRead(mes)
|
||||
textBox:push{
|
||||
COLOR.lR,args[1],
|
||||
COLOR.dY,args[2].." ",
|
||||
COLOR.Y,text[cmd=="J"and"chatJoin"or"chatLeave"]
|
||||
COLOR.Y,text[cmd=="J"and"joinRoom"or"leaveRoom"]
|
||||
}
|
||||
remain=tonumber(args[3])
|
||||
elseif cmd=="T"then
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local data=love.data
|
||||
local gc=love.graphics
|
||||
local gc_setColor,gc_circle=gc.setColor,gc.circle
|
||||
local tc=love.touch
|
||||
@@ -26,8 +27,15 @@ end
|
||||
|
||||
local hideChatBox
|
||||
local textBox=WIDGET.newTextBox{name="texts",x=340,y=80,w=600,h=550,hide=function()return hideChatBox end}
|
||||
local function switchChat()
|
||||
hideChatBox=not hideChatBox
|
||||
end
|
||||
|
||||
|
||||
local playing
|
||||
local heartBeatTimer
|
||||
local lastUpstreamTime
|
||||
local upstreamProgress
|
||||
local lastBackTime=0
|
||||
local noTouch,noKey=false,false
|
||||
local touchMoveLastFrame=false
|
||||
@@ -38,16 +46,22 @@ function scene.sceneBack()
|
||||
wsWrite("Q")
|
||||
WSCONN=false
|
||||
LOG.print(text.wsDisconnected,"warn")
|
||||
love.keyboard.setKeyRepeat(true)
|
||||
end
|
||||
function scene.sceneInit()
|
||||
love.keyboard.setKeyRepeat(false)
|
||||
wsWrite("C"..dumpBasicConfig())
|
||||
TASK.new(TICK_wsRead)
|
||||
hideChatBox=true
|
||||
textBox:clear()
|
||||
|
||||
playerData={}
|
||||
resetGameData("n",playerData)
|
||||
noTouch=not SETTING.VKSwitch
|
||||
playing=false
|
||||
lastUpstreamTime=0
|
||||
upstreamProgress=1
|
||||
heartBeatTimer=0
|
||||
end
|
||||
|
||||
function scene.touchDown(_,x,y)
|
||||
@@ -120,6 +134,10 @@ function scene.keyDown(key)
|
||||
lastBackTime=TIME()
|
||||
LOG.print(text.sureQuit,COLOR.orange)
|
||||
end
|
||||
elseif key=="b"then
|
||||
wsWrite("B")
|
||||
elseif key=="\\"then
|
||||
switchChat()
|
||||
else
|
||||
if noKey then return end
|
||||
local k=keyMap.keyboard[key]
|
||||
@@ -170,17 +188,18 @@ end
|
||||
function scene.socketRead(mes)
|
||||
local cmd=mes:sub(1,1)
|
||||
local args=splitStr(mes:sub(2),":")
|
||||
LOG.print(cmd,table.concat(args, " ; "))-------DEBUG PRINT
|
||||
print(cmd.." "..table.concat(args, " ; "))-------DEBUG PRINT
|
||||
if cmd=="J"or cmd=="L"then
|
||||
textBox:push{
|
||||
COLOR.lR,args[1],
|
||||
COLOR.dY,args[2].." ",
|
||||
COLOR.Y,text[cmd=="J"and"chatJoin"or"chatLeave"]
|
||||
COLOR.Y,text[cmd=="J"and"joinRoom"or"leaveRoom"]
|
||||
}
|
||||
if cmd=="J"then
|
||||
ins(playerData,{name=args[1],id=args[2],conf=false})
|
||||
if not playing then
|
||||
resetGameData("n",playerData)
|
||||
if tostring(USER.id)~=args[2]then
|
||||
wsWrite("C"..dumpBasicConfig())
|
||||
ins(playerData,{name=args[1],id=args[2]})
|
||||
resetGameData("qn",playerData)
|
||||
end
|
||||
else
|
||||
for i=1,#playerData do
|
||||
@@ -197,8 +216,9 @@ function scene.socketRead(mes)
|
||||
end
|
||||
for i=1,#PLAYERS.alive do
|
||||
if PLAYERS.alive[i].userID==args[2]then
|
||||
rem(PLAYERS,i)
|
||||
break
|
||||
rem(PLAYERS.alive,i)
|
||||
initPlayerPosition(true)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -209,23 +229,36 @@ function scene.socketRead(mes)
|
||||
COLOR.sky,args[3]
|
||||
}
|
||||
elseif cmd=="C"then
|
||||
for i=1,#playerData do
|
||||
if playerData[i].id==args[1]then
|
||||
playerData[i].conf=args[2]
|
||||
return
|
||||
if tostring(USER.id)~=args[2]then
|
||||
local ENV=json.decode(data.decode("string","base64",args[3]))
|
||||
for i=1,#playerData do
|
||||
if playerData[i].id==args[2]then
|
||||
playerData[i].conf=ENV
|
||||
playerData[i].p:setConf(ENV)
|
||||
return
|
||||
end
|
||||
end
|
||||
ins(playerData,{name=args[1],id=args[2],conf=ENV})
|
||||
resetGameData("qn",playerData)
|
||||
end
|
||||
elseif cmd=="S"then
|
||||
for _,P in next,PLAYERS do
|
||||
if P.userID==args[1]then
|
||||
pumpRecording(args[2],P.stream)
|
||||
if args[1]~=tostring(USER.id)then
|
||||
for _,P in next,PLAYERS do
|
||||
if P.userID==args[1]then
|
||||
pumpRecording(data.decode("string","base64",args[2]),P.stream)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif cmd=="B"then
|
||||
playing=true
|
||||
resetGameData("n",playerData)
|
||||
if not playing then
|
||||
playing=true
|
||||
resetGameData("n",playerData,tonumber(args[1]))
|
||||
else
|
||||
LOG.print("Redundant signal: B(begin)",30,COLOR.green)
|
||||
end
|
||||
elseif cmd=="F"then
|
||||
playing=false
|
||||
LOG.print(text.gameover,30,COLOR.green)
|
||||
else
|
||||
LOG.print("Illegal message: ["..mes.."]",30,COLOR.green)
|
||||
end
|
||||
@@ -248,10 +281,27 @@ function scene.update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
if not playing then return end
|
||||
if not playing then
|
||||
heartBeatTimer=heartBeatTimer+dt
|
||||
if heartBeatTimer>42 then
|
||||
heartBeatTimer=0
|
||||
wsWrite("P")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
GAME.frame=GAME.frame+1
|
||||
|
||||
if GAME.frame-lastUpstreamTime>10 then
|
||||
local stream
|
||||
stream,upstreamProgress=dumpRecording(GAME.rep,upstreamProgress)
|
||||
if #stream>0 then
|
||||
wsWrite("S"..data.encode("string","base64",stream))
|
||||
end
|
||||
lastUpstreamTime=PLAYERS[1].alive and GAME.frame or 1e99
|
||||
end
|
||||
|
||||
--Counting,include pre-das,directy RETURN,or restart counting
|
||||
GAME.frame=GAME.frame+1
|
||||
if GAME.frame<180 then
|
||||
if GAME.frame==179 then
|
||||
gameStart()
|
||||
@@ -303,6 +353,9 @@ function scene.update(dt)
|
||||
elseif GAME.warnLVL>0 then
|
||||
GAME.warnLVL=max(GAME.warnLVL-.026,0)
|
||||
end
|
||||
if GAME.warnLVL>1.126 and GAME.frame%30==0 then
|
||||
SFX.fplay("warning",SETTING.sfx_warn)
|
||||
end
|
||||
end
|
||||
|
||||
function scene.draw()
|
||||
@@ -378,7 +431,7 @@ function scene.draw()
|
||||
end
|
||||
scene.widgetList={
|
||||
textBox,
|
||||
WIDGET.newKey{name="hideChat",fText="...",x=410,y=40,w=60,font=35,code=function()hideChatBox=not hideChatBox end},
|
||||
WIDGET.newKey{name="hideChat",fText="...",x=410,y=40,w=60,font=35,code=switchChat},
|
||||
WIDGET.newKey{name="quit",fText="X",x=870,y=40,w=60,font=40,code=pressKey"escape"},
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,30 @@ local function task_fetchRooms(task)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function task_createRooms(task)
|
||||
local time=0
|
||||
while true do
|
||||
coroutine.yield()
|
||||
local response,request_error=client.poll(task)
|
||||
if response then
|
||||
local res=json.decode(response.body)
|
||||
if response.code==200 and res.message=="OK"then
|
||||
LOG.print("OK")
|
||||
else
|
||||
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
||||
end
|
||||
return
|
||||
elseif request_error then
|
||||
LOG.print(text.roomsCreateFailed..": "..request_error,"warn")
|
||||
return
|
||||
end
|
||||
time=time+1
|
||||
if time>210 then
|
||||
LOG.print(text.roomsCreateFailed..": "..text.httpTimeout,"warn")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
local function task_enterRoom(task)
|
||||
local time=0
|
||||
while true do
|
||||
@@ -82,6 +106,19 @@ function scene.keyDown(k)
|
||||
if TIME()-lastfreshTime>1 then
|
||||
fresh()
|
||||
end
|
||||
elseif k=="n"then
|
||||
httpRequest(
|
||||
task_createRooms,
|
||||
PATH.api..PATH.rooms.."/classic",
|
||||
"POST",
|
||||
{["Content-Type"]="application/json"},
|
||||
json.encode{
|
||||
email=USER.email,
|
||||
access_token=USER.access_token,
|
||||
room_name="Test Room "..math.random(26,626),
|
||||
room_password=nil,
|
||||
}
|
||||
)
|
||||
elseif k=="escape"then
|
||||
SCN.back()
|
||||
elseif rooms and #rooms>0 then
|
||||
|
||||
@@ -2,6 +2,7 @@ local gc=love.graphics
|
||||
local gc_setColor,gc_circle=gc.setColor,gc.circle
|
||||
local tc=love.touch
|
||||
|
||||
local int=math.floor
|
||||
local max,sin=math.max,math.sin
|
||||
|
||||
local SCR=SCR
|
||||
@@ -181,14 +182,23 @@ function scene.update(dt)
|
||||
_=GAME.replaying
|
||||
local L=GAME.rep
|
||||
while GAME.frame==L[_]do
|
||||
local k=L[_+1]
|
||||
if k>0 then
|
||||
P1:pressKey(k)
|
||||
VK[k].isDown=true
|
||||
VK[k].pressTime=10
|
||||
else
|
||||
VK[-k].isDown=false
|
||||
P1:releaseKey(-k)
|
||||
local key=L[_+1]
|
||||
if key==0 then--Just wait
|
||||
elseif key<=32 then--Press key
|
||||
P1:pressKey(key)
|
||||
VK[key].isDown=true
|
||||
VK[key].pressTime=10
|
||||
elseif key<=64 then--Release key
|
||||
VK[key-32].isDown=false
|
||||
P1:releaseKey(key-32)
|
||||
elseif key>1023 then--Receiving garbage
|
||||
local sid=key%256
|
||||
local amount=int(key/256)%256
|
||||
local time=int(key/4194304)%16384
|
||||
local line=int(key/274877906944)%65536
|
||||
local color=int(key/70368744177664)%256
|
||||
P1:receive(sid,amount,time,line,color)
|
||||
--TODO
|
||||
end
|
||||
_=_+2
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user