From cec5cc5199abcbea13286481dd2a87070cfa35b1 Mon Sep 17 00:00:00 2001 From: duncathan Date: Wed, 11 Sep 2019 20:51:48 -0600 Subject: [PATCH] adds CS folder persistence and a menu for selecting seeds --- src/main.lua | 22 +++++++++++++++++++--- src/randomizer.lua | 15 ++++++++++----- src/ui/draw.lua | 23 ++++++++++++++++++++--- src/ui/main.lua | 8 +++++--- src/ui/settings.lua | 14 ++++++++++++++ src/ui/style.lua | 36 ++++++++++++++++++++++++++++++++++-- 6 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 src/ui/settings.lua diff --git a/src/main.lua b/src/main.lua index 16ac23c..0e06caf 100644 --- a/src/main.lua +++ b/src/main.lua @@ -29,15 +29,31 @@ function love.load() else Screen:setStatus("Drag and drop your Cave Story folder here.") end + Screen:draw() +end + +local function recursiveWrite(path, name) + local filesTable = lf.getDirectoryItems(path) + lf.createDirectory(name) + for i,v in ipairs(filesTable) do + local file = path..'/'..v + if lf.isFile(file) then + local n + lf.write(name..'/'..v, lf.read(file)) + elseif lf.isDirectory(file) then + recursiveWrite(file, name..'/'..v) + end + end end function love.directorydropped(path) local success = Randomizer:_mountDirectory(path) - Randomizer:_unmountDirectory(path) + --Randomizer:_unmountDirectory(path) if success then - Settings.settings.csdirectory = path + recursiveWrite('mounted-data', 'csdata') + Settings.settings.csdirectory = 'csdata' Settings:update() - Randomizer:setPath(path) + Randomizer:setPath('csdata') Screen:setStatus("Cave Story folder updated!") else Screen:setStatus("Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?") diff --git a/src/randomizer.lua b/src/randomizer.lua index 12b6268..46cdb40 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -32,6 +32,7 @@ function C:new() self._isCaveStoryPlus = false self.itemDeck = Items() self.worldGraph = WorldGraph(self.itemDeck) + self.customseed = nil end function C:setPath(path) @@ -50,7 +51,7 @@ function C:randomize() return "Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?" end - self:_seedRngesus() + local seed = self:_seedRngesus() local tscFiles = self:_createTscFiles(dirStage) -- self:_writePlaintext(tscFiles) self:_shuffleItems(tscFiles) @@ -58,7 +59,7 @@ function C:randomize() self:_writePlaintext(tscFiles) self:_writeLog() self:_unmountDirectory(csdirectory) - return self:_getStatusMessage() + return self:_getStatusMessage(seed) end function C:_mountDirectory(path) @@ -92,6 +93,8 @@ function C:_mountDirectory(path) end function C:_seedRngesus() + local seed = self.customseed or tostring(os.time()) + --[[ local seed = io.open(lf.getSourceBaseDirectory() .. "/seed.txt") if seed == nil then logNotice('Seed from file doesnt exists, generate a new') @@ -107,8 +110,10 @@ function C:_seedRngesus() logWarning('Seed is too short, generate a new') seed = tostring(os.time()) end + ]] love.math.setRandomSeed(seed) logNotice(('Offering seed "%s" to RNGesus' ):format(seed)) + return seed end function C:_createTscFiles(dirStage) @@ -229,11 +234,11 @@ function C:_unmountDirectory(path) assert(lf.unmount(path)) end -function C:_getStatusMessage() +function C:_getStatusMessage(seed) local warnings, errors = countLogWarningsAndErrors() local line1 if warnings == 0 and errors == 0 then - line1 = "Randomized data successfully created!" + line1 = ("Randomized data successfully created!\nSeed: %d"):format(seed) elseif warnings ~= 0 and errors == 0 then line1 = ("Randomized data was created with %d warning(s)."):format(warnings) else @@ -241,7 +246,7 @@ function C:_getStatusMessage() end local line2 = "Next overwrite the files in your copy of Cave Story with the versions in the newly created \"data\" folder. Don't forget to save a backup of the originals!" local line3 = "Then play and have a fun!" - local status = ("%s\n\n%s\n\n%s"):format(line1, line2, line3) + local status = ("%s\n%s\n\n%s"):format(line1, line2, line3) return status end diff --git a/src/ui/draw.lua b/src/ui/draw.lua index 9884fc2..32ce620 100644 --- a/src/ui/draw.lua +++ b/src/ui/draw.lua @@ -5,12 +5,16 @@ local background local C = Class:extend() local layout = Luigi(require 'ui.main') ---local settings = Luigi(require 'ui.settings') +local settings = Luigi(require 'ui.settings') layout:setStyle(require 'ui.style') ---settings:setStyle(require 'ui.style') +settings:setStyle(require 'ui.style') +layout:setTheme(require 'lib.luigi.theme.dark') +settings:setTheme(require 'lib.luigi.theme.dark') function C:setup() background = lg.newImage('assets/background.png') + self:draw() + layout:show() end layout.version.text = 'Cave Story Randomizer [Open Mode] v' .. VERSION @@ -21,6 +25,9 @@ layout.footer.text = 'Original randomizer:\r\nshru.itch.io/cave-story-randomizer layout.go:onPress(function() if Randomizer:ready() then + if settings.seedselect.value and settings.customseed.value ~= "" then + Randomizer.customseed = settings.customseed.value + end C:setStatus(Randomizer:randomize()) Randomizer:new() else @@ -28,9 +35,19 @@ layout.go:onPress(function() end end) +layout.settings:onPress(function() + settings:show() + layout:hide() +end) + +settings.closeButton:onPress(function() + settings:hide() + layout:show() +end) + function C:draw() lg.draw(background, 0, 0) - layout:show() + --layout:show() end function C:setStatus(text) diff --git a/src/ui/main.lua b/src/ui/main.lua index 1b87d4f..92717d5 100644 --- a/src/ui/main.lua +++ b/src/ui/main.lua @@ -4,7 +4,7 @@ return { id = 'window', type = 'panel', id = 'header', height = 100, - style = 'panel', + style = 'transpanel', align = 'top center', { height = 10 }, { id = 'version', text = "" }, @@ -16,7 +16,7 @@ return { id = 'window', type = 'panel', id = 'status', height = 260, - style = 'panel', + style = 'transpanel', align = 'top center', margin = 24, wrap = true, @@ -27,6 +27,7 @@ return { id = 'window', { width = false }, { type = 'button', + style = 'button', id = 'settings', text = 'Settings', width = 100, @@ -34,6 +35,7 @@ return { id = 'window', }, { type = 'button', + style = 'button', id = 'go', text = 'Randomize', width = 100, @@ -48,7 +50,7 @@ return { id = 'window', type = 'panel', id = 'footer', height = 80, - style = 'panel', + style = 'transpanel', align = 'centre left', } } diff --git a/src/ui/settings.lua b/src/ui/settings.lua new file mode 100644 index 0000000..1cac569 --- /dev/null +++ b/src/ui/settings.lua @@ -0,0 +1,14 @@ +return { style = 'dialog', + { style = 'dialogHead', text = 'Settings' }, + { style = 'dialogBody', padding = 24, + { type = 'label', text = 'Seed' }, + { + { type = 'radio', group = 'seed', text = 'Use random seed', value = true }, + { flow = 'y', { type = 'radio', group = 'seed', text = 'Use custom seed', id = 'seedselect'}, { type = 'text', id = 'customseed', width = 150 }, {height = false} } + }, + }, + { style = 'dialogFoot', + {}, + { style = 'dialogButton', id = 'closeButton', text = 'Close' } + } +} \ No newline at end of file diff --git a/src/ui/style.lua b/src/ui/style.lua index 5cd9288..e73486e 100644 --- a/src/ui/style.lua +++ b/src/ui/style.lua @@ -1,11 +1,43 @@ return { - panel = { + transpanel = { background = {0,0,0,0}, font = 'assets/monogram_extended.ttf', size = 32, color = {255,255,255}, }, button = { - align = 'centre middle' + align = 'center middle', + size = 16, + font = 'assets/monogram_extended.ttf' + }, + -- dialog styles + dialog = { + type = 'submenu', + width = 600, + height = 400, + }, + dialogHead = { + align = 'middle center', + height = 36, + size = 16, + type = 'panel', + }, + dialogBody = { + align = 'left middle', + font = 'assets/monogram_extended.ttf', + size = 24, + padding = 4, + wrap = true, + }, + dialogFoot = { + flow = 'x', + height = 'auto', + type = 'panel', + }, + dialogButton = { + type = 'button', + font = 'assets/monogram_extended.ttf', + size = 16, + width = 100, } } \ No newline at end of file