diff --git a/parts/gametoolfunc.lua b/parts/gametoolfunc.lua index a825495a..5e7350a5 100644 --- a/parts/gametoolfunc.lua +++ b/parts/gametoolfunc.lua @@ -655,7 +655,7 @@ function pumpRecording(str,L) local list,curFrm if L then list=L - curFrm=L[#L-1] + curFrm=L[#L-1]or 0 else list={} curFrm=0 diff --git a/parts/player/init.lua b/parts/player/init.lua index 7af95625..8cbff88a 100644 --- a/parts/player/init.lua +++ b/parts/player/init.lua @@ -346,6 +346,9 @@ end function PLY.newRemotePlayer(id,mini) local P=newEmptyPlayer(id,mini) P.type="remote" + P.update=PLY.update.remote_alive + P.stream={} + P.streamProgress=1 loadGameEnv(P) applyGameEnv(P) diff --git a/parts/player/update.lua b/parts/player/update.lua index 53f8a170..f8e47a4a 100644 --- a/parts/player/update.lua +++ b/parts/player/update.lua @@ -105,8 +105,7 @@ local function updateTasks(P) end end -local update={} -function update.alive(P,dt) +local function update_alive(P,dt) if P.timing then local S=P.stat S.time=S.time+dt @@ -327,6 +326,10 @@ function update.alive(P,dt) updateFXs(P,dt) updateTasks(P) end + +local update={ + alive=update_alive, +} function update.dead(P,dt) if P.keyRec then local S=P.stat @@ -355,4 +358,24 @@ function update.dead(P,dt) updateFXs(P,dt) updateTasks(P) end +function update.remote_alive(P,dt) + ::readNext:: + local pos=P.streamProgress + local tar=P.stream[pos] + if tar then + if P.stat.frame==tar then + local key=P.stream[pos+1] + if key>0 then--Press key + P:pressKey(key) + elseif key<0 then--Release key + P:releaseKey(-key) + else--Receiving garbage + --TODO: + end + P.streamProgress=pos+2 + goto readNext + end + update_alive(P,dt) + end +end return update \ No newline at end of file