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
*.love
*.zip
dist/*.zip
dist/**/cambridge.exe
dist/**/libs

View File

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