mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 17:19:02 -06:00
Compare commits
No commits in common. "f5873c97bcc8ca5cb63405e45e982f7c677b0b82" and "0e82a8758c3ee27a5f59d486422837602b2cadfc" have entirely different histories.
f5873c97bc
...
0e82a8758c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
*.sav
|
||||
*.love
|
||||
*.zip
|
||||
dist/*.zip
|
||||
dist/**/cambridge.exe
|
||||
dist/**/libs
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user