From bfd3ec036055f658fc767bf61a64143e10d02549 Mon Sep 17 00:00:00 2001 From: Trashbox Bobylev Date: Sun, 24 Mar 2019 23:16:13 +0700 Subject: [PATCH 1/9] Added ability to read seed from seed.txt in randomizer's home file --- src/randomizer.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/randomizer.lua b/src/randomizer.lua index ca9352a..59d2074 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -29,6 +29,7 @@ function C:randomize(path) if not success then return "Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?" end + self:_seedRngesus() local tscFiles = self:_createTscFiles(dirStage) -- self:_writePlaintext(tscFiles) @@ -71,8 +72,16 @@ function C:_mountDirectory(path) end function C:_seedRngesus() - local seed = tostring(os.time()) - math.randomseed(seed) + local seedfile, bytes= lf.read(lf.getSourceBaseDirectory() + "seed.txt", 9); + local seed = "" + if seedfile == nil then + logNotice('Okay, no seed file, generate new') + seed = tostring(os.time()) + math.randomseed(seed) + else + logNotice('Gathered seed from file') + seed = seedfile + end logNotice(('Offering seed "%s" to RNGesus'):format(seed)) end From dfa31bc999272688fa47704567bc73671e68f5d3 Mon Sep 17 00:00:00 2001 From: TrashboxBobylev Date: Sun, 24 Mar 2019 16:38:58 +0000 Subject: [PATCH 2/9] Update randomizer.lua --- src/randomizer.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/randomizer.lua b/src/randomizer.lua index 59d2074..866b50c 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -72,15 +72,15 @@ function C:_mountDirectory(path) end function C:_seedRngesus() - local seedfile, bytes= lf.read(lf.getSourceBaseDirectory() + "seed.txt", 9); + local seedfile, bytes= lf.read(lf.getSourceBaseDirectory() + "seed.txt",10); local seed = "" if seedfile == nil then - logNotice('Okay, no seed file, generate new') - seed = tostring(os.time()) - math.randomseed(seed) + logNotice('Okay, no seed file, generate new') + seed = tostring(os.time()) + math.randomseed(seed) else - logNotice('Gathered seed from file') - seed = seedfile + logNotice('Gathered seed from file') + seed = seedfile end logNotice(('Offering seed "%s" to RNGesus'):format(seed)) end From 9250d162c878bb957773d758ec885326f821f985 Mon Sep 17 00:00:00 2001 From: Trashbox Bobylev Date: Mon, 25 Mar 2019 10:20:51 +0700 Subject: [PATCH 3/9] Fixed weird situations with seed.txt --- src/randomizer.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/randomizer.lua b/src/randomizer.lua index 866b50c..56ce7cb 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -74,12 +74,13 @@ end function C:_seedRngesus() local seedfile, bytes= lf.read(lf.getSourceBaseDirectory() + "seed.txt",10); local seed = "" - if seedfile == nil then - logNotice('Okay, no seed file, generate new') + seedfile = tonumber(seedfile) + if seedfile == nil or bytes < 10 then + logWarning('Seed from file doesn' t exists or seems to be invalid, generate a new') seed = tostring(os.time()) math.randomseed(seed) else - logNotice('Gathered seed from file') + logNotice('Gathered the seed from file "seed.txt"') seed = seedfile end logNotice(('Offering seed "%s" to RNGesus'):format(seed)) From d88a81fc987eab926a6e88a812de89bc9fdb32db Mon Sep 17 00:00:00 2001 From: Trashbox Bobylev Date: Mon, 25 Mar 2019 10:23:12 +0700 Subject: [PATCH 4/9] Seed from file now really seed --- src/randomizer.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/randomizer.lua b/src/randomizer.lua index 56ce7cb..b68aae7 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -78,11 +78,11 @@ function C:_seedRngesus() if seedfile == nil or bytes < 10 then logWarning('Seed from file doesn' t exists or seems to be invalid, generate a new') seed = tostring(os.time()) - math.randomseed(seed) else logNotice('Gathered the seed from file "seed.txt"') seed = seedfile end + math.randomseed(seed) logNotice(('Offering seed "%s" to RNGesus'):format(seed)) end From 2687db83abe73840989afa6bc4c035771864f57d Mon Sep 17 00:00:00 2001 From: Trashbox Bobylev Date: Mon, 25 Mar 2019 16:26:40 +0700 Subject: [PATCH 5/9] Gathering seed from file rewrited to use native Lua IO --- src/randomizer.lua | 13 ++++++------- src/tsc_file.lua | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/randomizer.lua b/src/randomizer.lua index b68aae7..6525fe7 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -72,24 +72,23 @@ function C:_mountDirectory(path) end function C:_seedRngesus() - local seedfile, bytes= lf.read(lf.getSourceBaseDirectory() + "seed.txt",10); + local seed_from_file = io.open(lf.getSourceBaseDirectory() + "seed.txt"):read('*10') local seed = "" - seedfile = tonumber(seedfile) - if seedfile == nil or bytes < 10 then - logWarning('Seed from file doesn' t exists or seems to be invalid, generate a new') + if seed_from_file == nil or string.len(seed_from_file) < 10 then + logWarning('Seed from file doesnt exists or seems to be invalid, generate a new') seed = tostring(os.time()) else logNotice('Gathered the seed from file "seed.txt"') - seed = seedfile + seed = seed_from_file end math.randomseed(seed) - logNotice(('Offering seed "%s" to RNGesus'):format(seed)) + logNotice(('Offering seed "%s" to RNGesus' ):format(seed)) end function C:_createTscFiles(dirStage) local tscFiles = {} for _, filename in ipairs(TSC_FILES) do - local path = dirStage .. '/' .. filename .. '.tsc' + local path = dirStage .. '/' .. filename .. ".tsc" tscFiles[filename] = TscFile(path) tscFiles[filename].mapName = filename end diff --git a/src/tsc_file.lua b/src/tsc_file.lua index 6a56b89..7638a41 100644 --- a/src/tsc_file.lua +++ b/src/tsc_file.lua @@ -22,7 +22,7 @@ function C:new(path) -- Determine set of items which can be replaced later. --[[ - self._unreplaced = {} + self._unreplaced = {} self._mapName = path:match("^.+/(.+)$") for k, v in pairs(ITEM_DATA) do repeat if (v.map .. '.tsc') ~= self._mapName then @@ -32,7 +32,7 @@ function C:new(path) table.insert(self._unreplaced, item) until true end self._unreplaced = _.shuffle(self._unreplaced) - ]] + ]] end function C:hasUnreplacedItems() From 35da7227bcdb92ee52285a05604abd33499aba72 Mon Sep 17 00:00:00 2001 From: Trashbox Bobylev Date: Mon, 25 Mar 2019 16:29:33 +0700 Subject: [PATCH 6/9] Fixed strings --- src/randomizer.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/randomizer.lua b/src/randomizer.lua index 6525fe7..4408462 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -72,7 +72,7 @@ function C:_mountDirectory(path) end function C:_seedRngesus() - local seed_from_file = io.open(lf.getSourceBaseDirectory() + "seed.txt"):read('*10') + local seed_from_file = io.open(lf.getSourceBaseDirectory() .. "seed.txt"):read('*10') local seed = "" if seed_from_file == nil or string.len(seed_from_file) < 10 then logWarning('Seed from file doesnt exists or seems to be invalid, generate a new') From 3340f38737abff5ba21e5a6548d3ecf385ac4f32 Mon Sep 17 00:00:00 2001 From: Trashbox Bobylev Date: Mon, 25 Mar 2019 23:15:41 +0700 Subject: [PATCH 7/9] All situations is tested, custom seed functional is complete --- src/randomizer.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/randomizer.lua b/src/randomizer.lua index 4408462..fbc7373 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -72,14 +72,20 @@ function C:_mountDirectory(path) end function C:_seedRngesus() - local seed_from_file = io.open(lf.getSourceBaseDirectory() .. "seed.txt"):read('*10') - local seed = "" - if seed_from_file == nil or string.len(seed_from_file) < 10 then - logWarning('Seed from file doesnt exists or seems to be invalid, generate a new') + local seed = io.open(lf.getSourceBaseDirectory() .. "/seed.txt") + if seed == nil then + logNotice('Seed from file doesnt exists, generate a new') seed = tostring(os.time()) else - logNotice('Gathered the seed from file "seed.txt"') - seed = seed_from_file + logNotice('Gathering the seed from file "seed.txt"') + seed = seed:read('*n') + end + if seed == nil then + logWarning('Seed from file is invalid, generate a new') + seed = tostring(os.time()) + elseif string.len(seed) < 10 then + logWarning('Seed is too short, generate a new') + seed = tostring(os.time()) end math.randomseed(seed) logNotice(('Offering seed "%s" to RNGesus' ):format(seed)) From b97eb73d46962612e2abe544cdfd10265c7c12b4 Mon Sep 17 00:00:00 2001 From: duncathan Date: Wed, 27 Mar 2019 23:43:26 -0600 Subject: [PATCH 8/9] uses the proper random library --- src/randomizer.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/randomizer.lua b/src/randomizer.lua index ee46731..9d9a8d4 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -97,7 +97,7 @@ function C:_seedRngesus() logWarning('Seed is too short, generate a new') seed = tostring(os.time()) end - math.randomseed(seed) + love.math.setRandomSeed(seed) logNotice(('Offering seed "%s" to RNGesus' ):format(seed)) end From 7c8b316da765518f80d1b8a9fa8401522b0e5220 Mon Sep 17 00:00:00 2001 From: duncathan Date: Wed, 27 Mar 2019 23:45:22 -0600 Subject: [PATCH 9/9] fixes whitespace --- src/randomizer.lua | 8 ++++---- src/tsc_file.lua | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/randomizer.lua b/src/randomizer.lua index 9d9a8d4..96485f7 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -91,15 +91,15 @@ function C:_seedRngesus() seed = seed:read('*n') end if seed == nil then - logWarning('Seed from file is invalid, generate a new') + logWarning('Seed from file is invalid, generate a new') seed = tostring(os.time()) elseif string.len(seed) < 10 then - logWarning('Seed is too short, generate a new') - seed = tostring(os.time()) + 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)) - end +end function C:_createTscFiles(dirStage) local tscFiles = {} diff --git a/src/tsc_file.lua b/src/tsc_file.lua index 7638a41..6a56b89 100644 --- a/src/tsc_file.lua +++ b/src/tsc_file.lua @@ -22,7 +22,7 @@ function C:new(path) -- Determine set of items which can be replaced later. --[[ - self._unreplaced = {} + self._unreplaced = {} self._mapName = path:match("^.+/(.+)$") for k, v in pairs(ITEM_DATA) do repeat if (v.map .. '.tsc') ~= self._mapName then @@ -32,7 +32,7 @@ function C:new(path) table.insert(self._unreplaced, item) until true end self._unreplaced = _.shuffle(self._unreplaced) - ]] + ]] end function C:hasUnreplacedItems()