55 lines
1.2 KiB
Lua
55 lines
1.2 KiB
Lua
--Record demos.
|
|
local love = love
|
|
local recorder = {}
|
|
recorder.isLoaded = false
|
|
local ddxs, ddys
|
|
local i = 0
|
|
|
|
function recorder.Reset()
|
|
i = 0
|
|
for k, _ in ipairs( recorder ) do recorder[k] = nil end
|
|
end
|
|
|
|
function recorder.Update( ddx, ddy )
|
|
i = i + 1
|
|
recorder[i] = love.data.pack( "string", "!16<dd", ddx, ddy )
|
|
end
|
|
|
|
--[[function recorder.Update( ddx, ddy )
|
|
local byte = 0
|
|
if ddx > 0.5 then byte = byte + 1 end
|
|
if ddy > 0.5 then byte = byte + 2 end
|
|
if ddx < -0.5 then byte = byte + 4 end
|
|
if ddy < -0.5 then byte = byte + 8 end
|
|
|
|
i = i + 1
|
|
recorder[i] = string.char( byte + 48 )
|
|
end]]
|
|
|
|
function recorder.Load( filename )
|
|
ddxs, ddys = {}, {}
|
|
local s = love.filesystem.read( filename )
|
|
if not s then return end
|
|
local k, j = 1, 1
|
|
local n = s:len()
|
|
while k < n do
|
|
ddxs[j], ddys[j], k = love.data.unpack( "!16<dd", s, k)
|
|
j = j + 1
|
|
end
|
|
recorder.isLoaded = true
|
|
i = 0
|
|
|
|
return true
|
|
end
|
|
|
|
function recorder.NextTick( )
|
|
i = i + 1
|
|
return ddxs[i], ddys[i]
|
|
end
|
|
|
|
function recorder.Save( )
|
|
if not love.filesystem.getInfo( "demos" ) then love.filesystem.createDirectory( "demos" ) end
|
|
return assert( love.filesystem.write( "demos/"..os.time()..".yod" , table.concat( recorder ) ) )
|
|
end
|
|
|
|
return recorder |