cambridge/load/save.lua

57 lines
1.4 KiB
Lua
Raw Permalink Normal View History

2019-05-22 22:57:34 -05:00
local binser = require 'libs.binser'
function loadSave()
config = loadFromFile('config.sav')
highscores = loadFromFile('highscores.sav')
2019-05-22 22:57:34 -05:00
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)
2019-05-22 22:57:34 -05:00
if save_data == nil then
return {} -- new object
end
return save_data[1]
end
2021-03-11 08:24:19 -06:00
function initConfig()
if not config.das then config.das = 10 end
if not config.arr then config.arr = 2 end
if not config.dcd then config.dcd = 0 end
if not config.sfx_volume then config.sfx_volume = 0.5 end
if not config.bgm_volume then config.bgm_volume = 0.5 end
if config.fullscreen == nil then config.fullscreen = false end
if config.secret == nil then config.secret = false end
2019-05-22 22:57:34 -05:00
2021-03-11 08:24:19 -06:00
if not config.gamesettings then config.gamesettings = {} end
for _, option in ipairs(GameConfigScene.options) do
if not config.gamesettings[option[1]] then
config.gamesettings[option[1]] = 1
end
end
if not config.input then
2021-05-20 22:25:24 -05:00
scene = InputConfigScene()
2021-03-11 08:24:19 -06:00
else
if config.current_mode then current_mode = config.current_mode end
if config.current_ruleset then current_ruleset = config.current_ruleset end
scene = TitleScene()
2021-03-11 08:24:19 -06:00
end
end
2019-05-22 22:57:34 -05:00
function saveConfig()
2021-09-12 16:36:21 -05:00
love.filesystem.write(
'config.sav', binser.serialize(config)
)
2019-05-22 22:57:34 -05:00
end
function saveHighscores()
2021-09-12 16:36:21 -05:00
love.filesystem.write(
'highscores.sav', binser.serialize(highscores)
)
2019-05-22 22:57:34 -05:00
end