diff --git a/src/randomizer.lua b/src/randomizer.lua index 464a408..3ae5727 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -151,8 +151,6 @@ function C:_shuffleItems(tscFiles) -- place the bomb on MALCO for bad end if self.obj == "objBadEnd" then self.worldGraph:getMALCO()[1]:setItem(self.itemDeck:getByKey("bomb")) - else - logWarning(self.obj) end diff --git a/src/ui/draw.lua b/src/ui/draw.lua index 1ef40f4..1f5bfbe 100644 --- a/src/ui/draw.lua +++ b/src/ui/draw.lua @@ -44,7 +44,11 @@ function C:loadSettings(puppy, obj, seed) settings.best.value = true end - settings.customseed.value = seed or "" + if seed ~= nil then + settings.customseed.value = seed or "" + settings.seedselect.value = true + settings.seedrandom.value = false + end end layout.version.text = 'Cave Story Randomizer [Open Mode] v' .. VERSION @@ -55,10 +59,10 @@ layout.footer.text = 'Original randomizer:\r\nshru.itch.io/cave-story-randomizer layout.go:onPress(function() Randomizer:new() - + if Randomizer:ready() then if settings.seedselect.value and settings.customseed.value ~= "" then - Randomizer.customseed = settings.customseed.value + Randomizer.customseed = settings.customseed.value:gsub("^%s*(.-)%s*$", "%1") -- trim any leading/trailing whitespace end if settings.bad.value then @@ -88,6 +92,7 @@ end) settings.closeButton:onPress(function() settings:hide() layout:show() + settings.sharecode.value = "" end) layout.sharecode:onPress(function() @@ -104,6 +109,28 @@ settings.customseed:onChange(function() settings.seedcount.text = ("%s/20"):format(#settings.customseed.value) end) +settings.importshare:onPress(function() + local success, seed, sharesettings = pcall(function() + local packed = love.data.decode("data", "base64", settings.sharecode.value) + local seed, settings = love.data.unpack("sB", packed) + return seed, settings + end) + + if success then + settings.importshare.text = "Sharecode Imported" + local pup = bit.band(sharesettings, 4) ~= 0 + local obj = bit.band(sharesettings, 3) + seed = seed:gsub("^%s*(.-)%s*$", "%1") -- trim any leading or trailing whitespace + Screen:loadSettings(pup, obj, seed) + else + settings.importshare.text = "Invalid Sharecode!" + end +end) + +settings.sharecode:onChange(function() + settings.importshare.text = "Import Sharecode" +end) + function C:draw() lg.draw(background, 0, 0) --layout:show() diff --git a/src/ui/settings.lua b/src/ui/settings.lua index 41444ef..bacce45 100644 --- a/src/ui/settings.lua +++ b/src/ui/settings.lua @@ -1,23 +1,30 @@ return { style = 'dialog', { style = 'dialogHead', text = 'Settings' }, - { style = 'dialogBody', padding = 24, flow = 'x', - { - { type = 'label', text = 'Seed' }, + { style = 'dialogBody', padding = 24, + { flow = 'x', minheight = 260, { - { 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 = 200}, flow = 'x', { type = 'label', id = 'seedcount' }}, {height = false} } + { type = 'label', text = 'Seed', minheight = 32 }, + { + { type = 'radio', group = 'seed', text = 'Use random seed', value = true, id = 'seedrandom', minheight = 27 }, + { flow = 'y', { type = 'radio', group = 'seed', text = 'Use custom seed', id = 'seedselect', minheight = 27 }, {{ type = 'text', id = 'customseed', width = 200, minheight = 32}, flow = 'x', { type = 'label', id = 'seedcount' }} } + }, + { type = 'label', text = 'Randomization Options', minheight = 32 }, + { type = 'check', value = false, id = 'puppy', text = "Puppysanity", minheight = 27 }, + { height = 64 }, + }, + { + { type = 'label', text = 'Objective', minheight = 32 }, + { type = 'radio', group = 'objective', text = 'Bad ending', id = 'bad', minheight = 27 }, + { type = 'radio', group = 'objective', text = 'Normal ending', id = 'norm', minheight = 27 }, + { type = 'radio', group = 'objective', text = 'Best ending', id = 'best', value = true, minheight = 27 }, + { type = 'radio', group = 'objective', text = 'All bosses', id = 'boss', minheight = 27 }, }, - { type = 'label', text = 'Randomization Options' }, - { type = 'check', value = false, id = 'puppy', text = "Puppysanity"}, - { height = false }, }, { - { type = 'label', text = 'Objective' }, - { type = 'radio', group = 'objective', text = 'Bad ending', id = 'bad' }, - { type = 'radio', group = 'objective', text = 'Normal ending', id = 'norm'}, - { type = 'radio', group = 'objective', text = 'Best ending', id = 'best', value = true }, - { type = 'radio', group = 'objective', text = 'All bosses', id = 'boss' }, - }, + flow = 'x', + { type = 'text', id = 'sharecode', width = 350 }, + { type = 'button', style = 'dialogButton', text = "Import Sharecode", id = 'importshare', width = 180 } + } }, { style = 'dialogFoot', {},