Compare commits

..

No commits in common. "f5873c97bcc8ca5cb63405e45e982f7c677b0b82" and "0e82a8758c3ee27a5f59d486422837602b2cadfc" have entirely different histories.

2 changed files with 18 additions and 12 deletions

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
*.sav *.sav
*.love *.love
*.zip
dist/*.zip dist/*.zip
dist/**/cambridge.exe dist/**/cambridge.exe
dist/**/libs dist/**/libs

View File

@ -1,16 +1,23 @@
local binser = require 'libs.binser' local binser = require 'libs.binser'
function loadSave() function loadSave()
config = loadFromFile('config.sav') local info = love.filesystem.getInfo(
highscores = loadFromFile('highscores.sav') love.filesystem.getSaveDirectory(), "directory"
)
if not info then
love.filesystem.remove(love.filesystem.getSaveDirectory())
love.filesystem.createDirectory(love.filesystem.getSaveDirectory())
end
config = loadFromFile(
love.filesystem.getSaveDirectory() .. '/config.sav'
)
highscores = loadFromFile(
love.filesystem.getSaveDirectory() .. '/highscores.sav'
)
end end
function loadFromFile(filename) function loadFromFile(filename)
local file_data = love.filesystem.read(filename) local save_data, len = binser.readFile(filename)
if file_data == nil then
return {} -- new object
end
local save_data = binser.deserialize(file_data)
if save_data == nil then if save_data == nil then
return {} -- new object return {} -- new object
end end
@ -44,13 +51,13 @@ function initConfig()
end end
function saveConfig() function saveConfig()
love.filesystem.write( binser.writeFile(
'config.sav', binser.serialize(config) love.filesystem.getSaveDirectory() .. '/config.sav', config
) )
end end
function saveHighscores() function saveHighscores()
love.filesystem.write( binser.writeFile(
'highscores.sav', binser.serialize(highscores) love.filesystem.getSaveDirectory() .. '/highscores.sav', highscores
) )
end end