mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-21 21:39:03 -06:00
New replay file naming and *fast replay saving.
*fast because lower CPU and IO use. No longer O(n²).
This commit is contained in:
parent
23a8c400ba
commit
d7c83b0bc7
@ -139,21 +139,18 @@ function GameMode:saveReplay()
|
||||
if love.filesystem.getInfo("replays") == nil then
|
||||
love.filesystem.createDirectory("replays")
|
||||
end
|
||||
local replay_files = love.filesystem.getDirectoryItems("replays")
|
||||
-- Select replay filename that doesn't collide with an existing one
|
||||
local init_name = string.format("replays/%s.crp", os.date("%Y-%m-%d_%H-%M-%S"))
|
||||
local replay_name = init_name
|
||||
local replay_number = 0
|
||||
local collision = true
|
||||
while collision do
|
||||
collision = false
|
||||
while true do
|
||||
if love.filesystem.getInfo(replay_name, "file") then
|
||||
replay_number = replay_number + 1
|
||||
for key, file in pairs(replay_files) do
|
||||
if file == replay_number..".crp" then
|
||||
collision = true
|
||||
replay_name = string.format("%s (%d)", init_name, replay_number)
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
love.filesystem.write("replays/"..replay_number..".crp", binser.serialize(replay))
|
||||
love.filesystem.write(replay_name, binser.serialize(replay))
|
||||
end
|
||||
|
||||
function GameMode:addReplayInput(inputs)
|
||||
|
Loading…
Reference in New Issue
Block a user