2022-02-17 22:39:31 +00:00
|
|
|
Demo = {}
|
|
|
|
DemoPlayback = false
|
|
|
|
DemoRecording = false
|
|
|
|
DemoAction = nil -- Table of actions
|
|
|
|
CurrentDemoFrame = nil
|
|
|
|
|
|
|
|
function Demo:Draw()
|
|
|
|
if DemoRecording then
|
|
|
|
love.graphics.setColor(1,0,0,1)
|
|
|
|
elseif DemoPlayback then
|
|
|
|
love.graphics.setColor(0,0,1,1)
|
|
|
|
end
|
|
|
|
love.graphics.rectangle("line",0,0,game.width ,game.height)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Demo:PlaybackStart()
|
|
|
|
DemoPlayback = true
|
|
|
|
CurrentDemoFrame = 0
|
2022-02-17 23:23:04 +00:00
|
|
|
dofile("demos/play_demo.lua")
|
2022-02-17 22:39:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Demo:PlaybackEnd()
|
|
|
|
DemoPlayback = false
|
|
|
|
DemoAction = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function Demo:RecordAction(action)
|
|
|
|
if DemoRecording
|
|
|
|
and action ~= nil
|
|
|
|
then
|
|
|
|
DemoFile:write("\""..action.."\",")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Demo:RecordStart()
|
|
|
|
-- Make demo stuff
|
2022-02-17 23:23:04 +00:00
|
|
|
os.execute( "mkdir \"./demos\"" )
|
|
|
|
DemoFile = io.open("demos/play_demo.lua", "w+")
|
2022-02-17 22:39:31 +00:00
|
|
|
--DemoFile = io.open("demo/mothbackDemo_"..os.date("%Y-%m-%d_%H-%M-%S")..".lua", "w+")
|
|
|
|
DemoFile:write("main_Player.pos.x = "..main_Player.pos.x.."\n")
|
|
|
|
DemoFile:write("main_Player.pos.y = "..main_Player.pos.y.."\n")
|
|
|
|
DemoFile:write("DemoAction = {\n")
|
|
|
|
DemoRecording = true
|
|
|
|
CurrentDemoFrame = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
function Demo:RecordEnd()
|
|
|
|
DemoFile:write("}\n}")
|
|
|
|
DemoFile:close()
|
|
|
|
DemoFile = nil
|
|
|
|
DemoRecording = false
|
|
|
|
end
|
|
|
|
|
|
|
|
function Demo:Step()
|
|
|
|
if DemoRecording then
|
|
|
|
if CurrentDemoFrame == 1 then
|
|
|
|
DemoFile:write("\t{")
|
|
|
|
else
|
|
|
|
DemoFile:write("},\n\t{")
|
|
|
|
end
|
|
|
|
elseif DemoPlayback then
|
|
|
|
if DemoAction[CurrentDemoFrame + 1] == nil then Demo:PlaybackEnd() end
|
|
|
|
end
|
|
|
|
CurrentDemoFrame = CurrentDemoFrame + 1
|
|
|
|
end
|