feat: add save read/write
This commit is contained in:
parent
e9c7026dcb
commit
f83c67f96a
4 changed files with 33 additions and 2 deletions
|
@ -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" )
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue