implements sharecodes

This commit is contained in:
duncathan 2020-03-01 04:03:00 -06:00
parent b4e08a2d07
commit 98ef3ca075
2 changed files with 54 additions and 26 deletions

View file

@ -315,16 +315,17 @@ end
function C:_updateSharecode(seed) function C:_updateSharecode(seed)
local settings = 0 -- 0b00000000 local settings = 0 -- 0b00000000
-- 0bXXXSSPOO
-- P: single bit used for puppysanity -- P: single bit used for puppysanity
-- O: two bits used for objective -- O: three bits used for objective
-- S: two bits used for spawn location -- S: three bits used for spawn location
-- X: unused -- B: single bit used for sequence breaks
-- 0bBSSSOOOP
-- bitshift intervals -- bitshift intervals
local obj = 0 local obj = 1
local pup = 2 local pup = 0
local spn = 3 local spn = 4
local brk = 7
if self.obj == "objBadEnd" then if self.obj == "objBadEnd" then
settings = bit.bor(settings, bit.blshift(1, obj)) settings = bit.bor(settings, bit.blshift(1, obj))
@ -343,11 +344,24 @@ function C:_updateSharecode(seed)
settings = bit.bor(settings, bit.blshift(2, spn)) settings = bit.bor(settings, bit.blshift(2, spn))
end end
local seq = 0
if self.worldGraph.seqbreak then
settings = bit.bor(settings, bit.blshift(1, brk))
if self.worldGraph.dboosts.cthulhu.enabled then seq = bit.bor(seq, 1) end
if self.worldGraph.dboosts.chaco.enabled then seq = bit.bor(seq, 2) end
if self.worldGraph.dboosts.paxChaco.enabled then seq = bit.bor(seq, 4) end
if self.worldGraph.dboosts.flightlessHut.enabled then seq = bit.bor(seq, 8) end
if self.worldGraph.dboosts.camp.enabled then seq = bit.bor(seq, 16) end
if self.worldGraph.dboosts.sisters.enabled then seq = bit.bor(seq, 32) end
if self.worldGraph.dboosts.plantation.enabled then seq = bit.bor(seq, 64) end
if self.worldGraph.dboosts.rocket.enabled then seq = bit.bor(seq, 128) end
end
if #seed < 20 then if #seed < 20 then
seed = seed .. (" "):rep(20-#seed) seed = seed .. (" "):rep(20-#seed)
end end
local packed = love.data.pack("data", "sB", seed, settings) local packed = love.data.pack("data", "sBB", seed, settings, seq)
self.sharecode = love.data.encode("string", "base64", packed) self.sharecode = love.data.encode("string", "base64", packed)
logNotice(("Sharecode: %s"):format(self.sharecode)) logNotice(("Sharecode: %s"):format(self.sharecode))

View file

@ -24,7 +24,7 @@ function C:setup()
self:loadObjective(Settings.settings.obj) self:loadObjective(Settings.settings.obj)
self:loadMyChar(Settings.settings.mychar) self:loadMyChar(Settings.settings.mychar)
self:loadSpawn(Settings.settings.spawn) self:loadSpawn(Settings.settings.spawn)
self:loadSeqSettings(Settings.settings.dboosts) self:loadSeqSettings(Settings.settings.seqbreaks, Settings.settings.dboosts)
background = lg.newImage('assets/background.png') background = lg.newImage('assets/background.png')
self:draw() self:draw()
@ -86,15 +86,18 @@ function C:loadSpawn(spawn)
settings.spawn.value = "override" settings.spawn.value = "override"
end end
function C:loadSeqSettings(seq) function C:loadSeqSettings(breaks, seq)
sequence.cthulhu.value = seq.cthulhu if breaks then settings.seqbreak.value = breaks end
sequence.chaco.value = seq.chaco if breaks or breaks == nil then
sequence.paxChaco.value = seq.paxChaco sequence.cthulhu.value = seq.cthulhu
sequence.flightlessHut.value = seq.flightlessHut sequence.chaco.value = seq.chaco
sequence.camp.value = seq.camp sequence.paxChaco.value = seq.paxChaco
sequence.sisters.value = seq.sisters sequence.flightlessHut.value = seq.flightlessHut
sequence.plantation.value = seq.plantation sequence.camp.value = seq.camp
sequence.rocket.value = seq.rocket sequence.sisters.value = seq.sisters
sequence.plantation.value = seq.plantation
sequence.rocket.value = seq.rocket
end
end end
layout.version.text = 'Cave Story Randomizer [Open Mode] v' .. VERSION layout.version.text = 'Cave Story Randomizer [Open Mode] v' .. VERSION
@ -151,11 +154,11 @@ settings.seqButton:onPress(function()
end) end)
sequence.allOn:onPress(function() sequence.allOn:onPress(function()
Screen:loadSeqSettings(_.map(Settings.settings.dboosts, function(k,v) return true end)) Screen:loadSeqSettings(nil, _.map(Settings.settings.dboosts, function(k,v) return true end))
end) end)
sequence.allOff:onPress(function() sequence.allOff:onPress(function()
Screen:loadSeqSettings(_.map(Settings.settings.dboosts, function(k,v) return false end)) Screen:loadSeqSettings(nil, _.map(Settings.settings.dboosts, function(k,v) return false end))
end) end)
sequence.close:onPress(function() sequence.close:onPress(function()
@ -178,18 +181,29 @@ settings.customseed:onChange(function()
end) end)
settings.importshare:onPress(function() settings.importshare:onPress(function()
local success, seed, sharesettings = pcall(function() local success, seed, sharesettings, seq = pcall(function()
local packed = love.data.decode("data", "base64", settings.sharecode.value) local packed = love.data.decode("data", "base64", settings.sharecode.value)
local seed, settings = love.data.unpack("sB", packed) local seed, settings, seq = love.data.unpack("sBB", packed)
return seed, settings assert(#seed == 20)
return seed, settings, seq
end) end)
if success then if success then
settings.importshare.text = "Sharecode Imported" settings.importshare.text = "Sharecode Imported"
Screen:loadPuppy(bit.band(sharesettings, 4) ~= 0) -- settings & (0b00000001 << 2) Screen:loadPuppy(bit.band(sharesettings, 1) ~= 0) -- settings & 0b00000001
Screen:loadObjective(bit.band(sharesettings, 3)) -- settings & 0b00000011 Screen:loadObjective(bit.brshift(bit.band(sharesettings, 14), 1)) -- (settings & 0b00001110) >> 1
Screen:loadSpawn(bit.brshift(bit.band(sharesettings, 24), 3)) -- (settings & 0b00011000) >> 3 Screen:loadSpawn(bit.brshift(bit.band(sharesettings, 112), 4)) -- (settings & 0b01110000) >> 4
Screen:loadSeed(seed:gsub("^%s*(.-)%s*$", "%1")) -- trim any leading or trailing whitespace Screen:loadSeed(seed:gsub("^%s*(.-)%s*$", "%1")) -- trim any leading or trailing whitespace
Screen:loadSeqSettings(bit.band(sharesettings, 128) ~= 0, { -- (settings & 0b10000000)
cthulhu = bit.band(seq, 1) ~= 0,
chaco = bit.band(seq, 2) ~= 0,
paxChaco = bit.band(seq, 4) ~= 0,
flightlessHut = bit.band(seq, 8) ~= 0,
camp = bit.band(seq, 16) ~= 0,
sisters = bit.band(seq, 32) ~= 0,
plantation = bit.band(seq, 64) ~= 0,
rocket = bit.band(seq, 128) ~= 0
})
else else
settings.importshare.text = "Invalid Sharecode!" settings.importshare.text = "Invalid Sharecode!"
end end