From dbf14c59a31b93f44b0bfc6e640d44e7fd6ba2a9 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 18 Apr 2021 15:38:19 +0200 Subject: [PATCH] feat: add internal mechanism to delete saves --- sonic-radiance.love/game/init.lua | 55 +++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index be22b3b..4bd9292 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -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()