implements UI and settings for sequence breaks

This commit is contained in:
duncathan 2020-03-01 03:32:16 -06:00
parent 021bac9307
commit b4e08a2d07
7 changed files with 143 additions and 25 deletions

Binary file not shown.

View file

@ -16,9 +16,9 @@ require 'lib.bit'
local random = require 'randomizer'
local settings = require 'settings'
Settings = settings()
Randomizer = random()
Screen = require 'ui.draw'
Settings = settings()
local csdirectory

View file

@ -37,7 +37,6 @@ function C:new()
self.obj = ""
self.sharecode = ""
self.mychar = ""
self.seqbreak = false
end
function C:setPath(path)
@ -309,6 +308,8 @@ function C:_updateSettings()
Settings.settings.obj = self.obj
Settings.settings.mychar = self.mychar
Settings.settings.spawn = self.worldGraph.spawn
Settings.settings.seqbreaks = self.worldGraph.seqbreak
Settings.settings.dboosts = _.map(self.worldGraph.dboosts, function(k,v) return v.enabled end)
Settings:update()
end

View file

@ -3,17 +3,36 @@ local C = Class:extend()
function C:init()
self.settings = {}
if lf.getInfo('settings.txt') == nil then
self:setDefaults()
self.settings = self:getDefaults()
else
self.settings = lf.load('settings.txt')()
-- add any missing entries if new settings have been added
for k,v in pairs(self:getDefaults()) do
self.settings[k] = self.settings[k] or v
end
end
self.settings = lf.load('settings.txt')()
self:update()
end
function C:setDefaults()
self.settings.csdirectory = nil
self.settings.puppy = false
self.settings.obj = "objBestEnd"
self.settings.spawn = "Start Point"
self:update()
function C:getDefaults()
return {
csdirectory = "",
puppy = false,
obj = "objBestEnd",
mychar = "assets/myChar/Quote.bmp",
spawn = "Start Point",
seqbreaks = false,
dboosts = {
cthulhu = true,
chaco = true,
paxChaco = true,
flightlessHut = true,
camp = true,
sisters = true,
plantation = true,
rocket = true
}
}
end
function C:update()
@ -21,6 +40,14 @@ function C:update()
end
function C:serialize()
local function dboosts()
local line = "{"
for k,v in pairs(self.settings.dboosts) do
line = line .. ("%s = %s,"):format(k,v)
end
return line .. "}"
end
local line = "return {\r\n "
line = line .. ("csdirectory = [[%s]],\r\n "):format(self.settings.csdirectory or "")
@ -28,9 +55,11 @@ function C:serialize()
line = line .. ("obj = %q,\r\n "):format(self.settings.obj or "")
line = line .. ("mychar = %q,\r\n "):format(self.settings.mychar or "")
line = line .. ("spawn = %q,\r\n "):format(self.settings.spawn or "")
local dboost = dboosts()
line = line .. ("seqbreaks = %s,\r\n "):format(self.settings.seqbreaks)
line = line .. ("dboosts = %s,\r\n "):format(dboost)
line = line .. "\r\n}"
return line
return line .. "\r\n}"
end
function C:getSettings()

View file

@ -6,22 +6,36 @@ local C = Class:extend()
local layout = Luigi(require 'ui.main')
local settings = Luigi(require 'ui.settings')
layout:setStyle(require 'ui.style')
settings:setStyle(require 'ui.style')
layout:setTheme(require 'lib.luigi.theme.dark')
settings:setTheme(require 'lib.luigi.theme.dark')
local sequence = Luigi(require 'ui.sequence')
local style = require 'ui.style'
local theme = require 'lib.luigi.theme.dark'
layout:setStyle(style)
settings:setStyle(style)
sequence:setStyle(style)
layout:setTheme(theme)
settings:setTheme(theme)
sequence:setTheme(theme)
function C:setup()
self:loadSettings(Settings.settings.puppy, Settings.settings.obj, nil, Settings.settings.mychar, Settings.settings.spawn)
self:loadPuppy(Settings.settings.puppy)
self:loadObjective(Settings.settings.obj)
self:loadMyChar(Settings.settings.mychar)
self:loadSpawn(Settings.settings.spawn)
self:loadSeqSettings(Settings.settings.dboosts)
background = lg.newImage('assets/background.png')
self:draw()
layout:show()
end
function C:loadSettings(puppy, obj, seed, mychar, spawn)
function C:loadPuppy(puppy)
settings.puppy.value = puppy
end
function C:loadObjective(obj)
if obj == "objBadEnd" or obj == 1 then
settings.objective.index = 1
elseif obj == "objNormalEnd" or obj == 2 then
@ -32,13 +46,17 @@ function C:loadSettings(puppy, obj, seed, mychar, spawn)
settings.objective.index = 3
end
settings.objective.value = "override"
end
function C:loadSeed(seed)
if seed ~= nil then
settings.customseed.value = seed or ""
settings.seedselect.value = true
settings.seedrandom.value = false
end
end
function C:loadMyChar(mychar)
if mychar == "assets/myChar/Quote.bmp" then
settings.mychar.index = 1
elseif mychar == "assets/myChar/Curly.bmp" then
@ -55,7 +73,9 @@ function C:loadSettings(puppy, obj, seed, mychar, spawn)
settings.mychar.index = 7
end
settings.mychar.value = "override"
end
function C:loadSpawn(spawn)
if spawn == "Start Point" or spawn == 0 then
settings.spawn.index = 1
elseif spawn == "Arthur's House" or spawn == 1 then
@ -66,6 +86,17 @@ function C:loadSettings(puppy, obj, seed, mychar, spawn)
settings.spawn.value = "override"
end
function C:loadSeqSettings(seq)
sequence.cthulhu.value = seq.cthulhu
sequence.chaco.value = seq.chaco
sequence.paxChaco.value = seq.paxChaco
sequence.flightlessHut.value = seq.flightlessHut
sequence.camp.value = seq.camp
sequence.sisters.value = seq.sisters
sequence.plantation.value = seq.plantation
sequence.rocket.value = seq.rocket
end
layout.version.text = 'Cave Story Randomizer [Open Mode] v' .. VERSION
layout.author.text = 'by shru and duncathan'
layout.twitter.text = '(@shruuu and @duncathan_salt)'
@ -85,6 +116,16 @@ layout.go:onPress(function()
Randomizer.mychar = settings.mychar.value
Randomizer.worldGraph.spawn = settings.spawn.value
Randomizer.worldGraph.seqbreak = settings.seqbreak.value
Randomizer.worldGraph.dboosts.cthulhu.enabled = sequence.cthulhu.value
Randomizer.worldGraph.dboosts.chaco.enabled = sequence.chaco.value
Randomizer.worldGraph.dboosts.paxChaco.enabled = sequence.paxChaco.value
Randomizer.worldGraph.dboosts.flightlessHut.enabled = sequence.flightlessHut.value
Randomizer.worldGraph.dboosts.camp.enabled = sequence.camp.value
Randomizer.worldGraph.dboosts.sisters.enabled = sequence.sisters.value
Randomizer.worldGraph.dboosts.plantation.enabled = sequence.plantation.value
Randomizer.worldGraph.dboosts.rocket.enabled = sequence.rocket.value
C:setStatus(Randomizer:randomize())
layout.sharecode.text = "Copy Sharecode"
@ -104,6 +145,24 @@ settings.closeButton:onPress(function()
settings.sharecode.value = ""
end)
settings.seqButton:onPress(function()
sequence:show()
settings:hide()
end)
sequence.allOn:onPress(function()
Screen:loadSeqSettings(_.map(Settings.settings.dboosts, function(k,v) return true end))
end)
sequence.allOff:onPress(function()
Screen:loadSeqSettings(_.map(Settings.settings.dboosts, function(k,v) return false end))
end)
sequence.close:onPress(function()
sequence:hide()
settings:show()
end)
layout.sharecode:onPress(function()
if Randomizer.sharecode ~= "" then
love.system.setClipboardText(Randomizer.sharecode)
@ -127,11 +186,10 @@ settings.importshare:onPress(function()
if success then
settings.importshare.text = "Sharecode Imported"
local pup = bit.band(sharesettings, 4) ~= 0
local obj = bit.band(sharesettings, 3)
local spn = bit.brshift(bit.band(sharesettings, 24), 3)
seed = seed:gsub("^%s*(.-)%s*$", "%1") -- trim any leading or trailing whitespace
Screen:loadSettings(pup, obj, seed, nil, spn)
Screen:loadPuppy(bit.band(sharesettings, 4) ~= 0) -- settings & (0b00000001 << 2)
Screen:loadObjective(bit.band(sharesettings, 3)) -- settings & 0b00000011
Screen:loadSpawn(bit.brshift(bit.band(sharesettings, 24), 3)) -- (settings & 0b00011000) >> 3
Screen:loadSeed(seed:gsub("^%s*(.-)%s*$", "%1")) -- trim any leading or trailing whitespace
else
settings.importshare.text = "Invalid Sharecode!"
end

19
src/ui/sequence.lua Normal file
View file

@ -0,0 +1,19 @@
return { style = 'dialog',
{ style = 'dialogHead', text = 'Sequence Break Settings'},
{ style = 'dialogBody', padding = 24,
{ type = 'check', value = true, id = 'cthulhu', text = "Cthulhu's Abode (requires 3HP)", minheight = 27 },
{ type = 'check', value = true, id = 'chaco', text = "Chaco Skip (requires 5HP)", minheight = 27 },
{ type = 'check', value = true, id = 'paxChaco', text = "Chaco Skip without a weapon (requires 10HP)", minheight = 27 },
{ type = 'check', value = true, id = 'flightlessHut', text = "Flightless Grasstown Hut (requires 3HP)", minheight = 27 },
{ type = 'check', value = true, id = 'camp', text = "Flightless Camp Chest (requires 9HP)", minheight = 27 },
{ type = 'check', value = true, id = 'sisters', text = "Sisters Skip (requires flight)", minheight = 27 },
{ type = 'check', value = true, id = 'plantation', text = "Flightless Plantation Chest (requires 15HP)", minheight = 27 },
{ type = 'check', value = true, id = 'rocket', text = "Flightless Rocket Skip (requires 3HP, MG, and 2.0)", minheight = 27 },
},
{ style = 'dialogFoot',
{},
{ style = 'dialogButton', id = 'allOn', text = 'All On' },
{ style = 'dialogButton', id = 'allOff', text = 'All Off' },
{ style = 'dialogButton', id = 'close', text = 'Close' }
}
}

View file

@ -6,11 +6,22 @@ return { style = 'dialog',
{ 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' }} }
{ flow = 'y', { type = 'radio', group = 'seed', text = 'Use custom seed', id = 'seedselect', minheight = 27 },
{
flow = 'x',
{ type = 'text', id = 'customseed', width = 200, minheight = 32},
{ type = 'label', id = 'seedcount' }
}
}
},
{ type = 'label', text = 'Randomization Options', minheight = 32 },
{ type = 'check', value = false, id = 'puppy', text = "Puppysanity", minheight = 27 },
{ height = 64 },
{ flow = 'x',
{ type = 'check', value = false, id = 'seqbreak', text = "Sequence breaks", minheight = 32, width = 170},
{ type = 'button', style = 'dialogButton', text = "Modify", id = 'seqButton', width = 70, align = 'center' },
{ width = false }
},
{ height = 'auto' },
},
{
{ type = 'label', text = 'Objective', minheight = 32 },