feat: add internal mechanism to delete saves

This commit is contained in:
Kazhnuz 2021-04-18 15:38:19 +02:00
parent 37d685a7ea
commit dbf14c59a3

View file

@ -40,24 +40,8 @@ Game.gui = require "game.modules.gui"
function Game:new()
self.slot = -1
self.slotNumber = 3
self.gametime = 0
self.characters = Characters(self)
self.ennemies = Ennemies(self)
self.skills = Skills(self)
self.loot = Loot(self)
self.cbs = CBSCore(self)
self:initPosition()
self.flags = {}
self.destroyedGizmo = {}
self.variables = {}
self.completion = 0
self.mapName = ""
self.actions = startdata.actions
self.version = "0.0.0"
self:resetData()
end
function Game:initPosition()
@ -151,6 +135,31 @@ function Game:addtoMetadata()
self:writeMetadata(metadata)
end
function Game:resetData()
self.gametime = 0
self.characters = Characters(self)
self.ennemies = Ennemies(self)
self.skills = Skills(self)
self.loot = Loot(self)
self.cbs = CBSCore(self)
self:initPosition()
self.flags = {}
self.destroyedGizmo = {}
self.variables = {}
self.completion = 0
self.mapName = ""
self.actions = startdata.actions
end
function Game:removeFromMetadata()
local metadata = self:getMetadata()
metadata[self.slot].exist = false
self:writeMetadata(metadata)
end
function Game:read(save_id)
self.slot = save_id
if (self.slot > 0) then
@ -159,10 +168,22 @@ function Game:read(save_id)
local loadedDatas = binser.readFile(filepath)
self:setData(loadedDatas[1])
else
self:resetData()
end
end
end
function Game:deleteCurrentSave()
if (self.slot > 0) then
local filepath = self:getSaveFile(self.slot, false)
local success = love.filesystem.remove(filepath)
print(success)
self:removeFromMetadata()
end
end
function Game:write()
if (self.slot > 0) then
local data = self:getData()