mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 03:39:03 -06:00
Fix save data handling when save data directory contains non-ASCII characters
This commit is contained in:
parent
0e82a8758c
commit
fabdad056e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
*.sav
|
*.sav
|
||||||
*.love
|
*.love
|
||||||
|
*.zip
|
||||||
dist/*.zip
|
dist/*.zip
|
||||||
dist/**/cambridge.exe
|
dist/**/cambridge.exe
|
||||||
dist/**/libs
|
dist/**/libs
|
||||||
|
@ -1,23 +1,18 @@
|
|||||||
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)
|
print("Load from file")
|
||||||
|
local file_data = love.filesystem.read(filename)
|
||||||
|
if file_data == nil then
|
||||||
|
return {} -- new object
|
||||||
|
end
|
||||||
|
print(file_data)
|
||||||
|
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 +46,25 @@ function initConfig()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function saveConfig()
|
function saveConfig()
|
||||||
binser.writeFile(
|
print("Save config")
|
||||||
love.filesystem.getSaveDirectory() .. '/config.sav', config
|
local file_data = binser.serialize(config)
|
||||||
|
print(file_data)
|
||||||
|
local success, message = love.filesystem.write(
|
||||||
|
'config.sav', file_data
|
||||||
)
|
)
|
||||||
|
if not success then
|
||||||
|
print(message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function saveHighscores()
|
function saveHighscores()
|
||||||
binser.writeFile(
|
print("Save highscores")
|
||||||
love.filesystem.getSaveDirectory() .. '/highscores.sav', highscores
|
local file_data = binser.serialize(highscores)
|
||||||
|
print(file_data)
|
||||||
|
local success, message = love.filesystem.write(
|
||||||
|
'highscores.sav', file_data
|
||||||
)
|
)
|
||||||
|
if not success then
|
||||||
|
print(message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user