From f83c67f96aaf66b60451e828d0e375a3dff02f9a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Aug 2020 09:59:47 +0200 Subject: [PATCH] feat: add save read/write --- sonic-radiance.love/game/init.lua | 3 ++- .../scenes/debug/menu/infopanel/gamedata.lua | 2 +- .../scenes/debug/menu/init.lua | 8 +++++++ .../scenes/debug/menu/menu.lua | 22 +++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index d47cd04..5e7d67b 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -35,6 +35,7 @@ Game.gui = require "game.modules.gui" function Game:new() self.slot = -1 + self.slotNumber = 3 self.gametime = 0 self.characters = Characters(self) @@ -95,7 +96,7 @@ function Game:getSaveFile(saveslot, absolute) end function Game:resetSaves() - for i=1, 3 do + for i=1, self.slotNumber do filepath = self:getSaveFile(i, true) if love.filesystem.exists("save" .. i .. ".save") then love.filesystem.remove( "save" .. i .. ".save" ) diff --git a/sonic-radiance.love/scenes/debug/menu/infopanel/gamedata.lua b/sonic-radiance.love/scenes/debug/menu/infopanel/gamedata.lua index 13f440b..69de07d 100644 --- a/sonic-radiance.love/scenes/debug/menu/infopanel/gamedata.lua +++ b/sonic-radiance.love/scenes/debug/menu/infopanel/gamedata.lua @@ -7,7 +7,7 @@ end function GamePanel:drawContent(x, y) local debugString = "# Save system data" .. "\n" - debugString = debugString .. "Current slot: " .. game.slot .. " / 3" .. "\n" + debugString = debugString .. "Current slot: " .. game.slot .. " / " .. game.slotNumber .. "\n" debugString = debugString .. "Gametime: " .. game:getTimeString() .. "\n" love.graphics.print(debugString, x, y) diff --git a/sonic-radiance.love/scenes/debug/menu/init.lua b/sonic-radiance.love/scenes/debug/menu/init.lua index d48bf94..f395090 100644 --- a/sonic-radiance.love/scenes/debug/menu/init.lua +++ b/sonic-radiance.love/scenes/debug/menu/init.lua @@ -43,8 +43,16 @@ function DebugMenu:buildSaveMenu() self:addCharacterMenu(name, data) end + self:addSubMenu("load", "save", "Load Saves") + for i=1, game.slotNumber do + menu.LoadWidget(self, "load", i) + end + menu.SaveWidget(self, "save") + + menu.commons.SubMenuWidget(self, "save", "BaseMenu", "Back") menu.commons.SubMenuWidget(self, "characters", "save", "Back") + menu.commons.SubMenuWidget(self, "load", "save", "Back") end function DebugMenu:addCharacterMenu(name, data) diff --git a/sonic-radiance.love/scenes/debug/menu/menu.lua b/sonic-radiance.love/scenes/debug/menu/menu.lua index 630ff18..5c1266b 100644 --- a/sonic-radiance.love/scenes/debug/menu/menu.lua +++ b/sonic-radiance.love/scenes/debug/menu/menu.lua @@ -3,6 +3,8 @@ local menu = {} menu.commons = commons menu.ExitWidget = commons.DebugWidget:extend() menu.ShowBackgroundWidget = commons.DebugWidget:extend() +menu.SaveWidget = commons.DebugWidget:extend() +menu.LoadWidget = commons.DebugWidget:extend() -- ExitWidget function menu.ExitWidget:new(scene, menuName) @@ -22,4 +24,24 @@ function menu.ShowBackgroundWidget:action() self.scene.menusystem:deactivate() end +-- Save game +function menu.SaveWidget:new(scene, menuName) + menu.ShowBackgroundWidget.super.new(self, scene, menuName, "Save game") +end + +function menu.SaveWidget:action() + game:write() +end + +-- Save game +function menu.LoadWidget:new(scene, menuName, slot) + menu.ShowBackgroundWidget.super.new(self, scene, menuName, "Load file " .. slot) + self.slot = slot +end + +function menu.LoadWidget:action() + game:read(self.slot) +end + + return menu