Compare commits

..

2 Commits

Author SHA1 Message Date
Brandon McGriff
f5873c97bc Remove debugging prints in save.lua 2021-09-12 14:36:21 -07:00
Brandon McGriff
fabdad056e Fix save data handling when save data directory contains non-ASCII characters 2021-09-12 14:32:21 -07:00
2 changed files with 12 additions and 18 deletions

1
.gitignore vendored
View File

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

View File

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