From cb2edb55fba76a7947b56b8c27b5f5c4ade3e36d Mon Sep 17 00:00:00 2001 From: duncathan Date: Thu, 27 Feb 2020 23:54:37 -0600 Subject: [PATCH] makes settings persist between instances --- src/main.lua | 3 ++- src/randomizer.lua | 9 +++++++++ src/settings.lua | 4 ++++ src/ui/draw.lua | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main.lua b/src/main.lua index f1f0b72..9ec3029 100644 --- a/src/main.lua +++ b/src/main.lua @@ -22,8 +22,9 @@ Settings = settings() local csdirectory function love.load() - Screen:setup() Settings:init() + Screen:setup() + if Settings.settings.csdirectory ~= "" then Screen:setStatus("Cave Story folder found!") Randomizer:setPath(Settings.settings.csdirectory) diff --git a/src/randomizer.lua b/src/randomizer.lua index dd3f2b4..35cf103 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -61,6 +61,9 @@ function C:randomize() self:_writePlaintext(tscFiles) self:_writeLog() self:_unmountDirectory(csdirectory) + + self:_updateSettings() + return self:_getStatusMessage(seed) end @@ -254,6 +257,12 @@ function C:_unmountDirectory(path) assert(lf.unmount(path)) end +function C:_updateSettings() + Settings.settings.puppy = self.puppy + Settings.settings.obj = self.obj + Settings:update() +end + function C:_getStatusMessage(seed) local warnings, errors = countLogWarningsAndErrors() local line1 diff --git a/src/settings.lua b/src/settings.lua index 3c86b31..80a6ae2 100644 --- a/src/settings.lua +++ b/src/settings.lua @@ -10,6 +10,8 @@ end function C:setDefaults() self.settings.csdirectory = nil + self.settings.puppy = false + self.settings.obj = "" self:update() end @@ -21,6 +23,8 @@ function C:serialize() local line = "return {" line = line .. ("csdirectory = [[%s]],\r\n"):format(self.settings.csdirectory or "") + line = line .. ("puppy = %s,\r\n"):format(self.settings.puppy) + line = line .. ("obj = \"%s\",\r\n"):format(self.settings.obj) line = line .. "}" return line diff --git a/src/ui/draw.lua b/src/ui/draw.lua index d8928d0..a5413d1 100644 --- a/src/ui/draw.lua +++ b/src/ui/draw.lua @@ -12,6 +12,30 @@ layout:setTheme(require 'lib.luigi.theme.dark') settings:setTheme(require 'lib.luigi.theme.dark') function C:setup() + settings.puppy.value = Settings.settings.puppy + local obj = Settings.settings.obj + if obj == "objBadEnd" then + settings.bad.value = true + settings.norm.value = false + settings.boss.value = false + settings.best.value = false + elseif obj == "objNormalEnd" then + settings.bad.value = false + settings.norm.value = true + settings.boss.value = false + settings.best.value = false + elseif obj == "objAllBosses" then + settings.bad.value = false + settings.norm.value = false + settings.boss.value = true + settings.best.value = false + else + settings.bad.value = false + settings.norm.value = false + settings.boss.value = false + settings.best.value = true + end + background = lg.newImage('assets/background.png') self:draw() layout:show()