diff --git a/README.md b/README.md index 41f1ac1..f255dc4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ Cave Story Randomizer Todo ---- -- Provide modified Cave.pxm. (When Bubbline or Fireball) - Print Warning/Error Count - Supress Hell Music Error - Write log diff --git a/src/database/Cave.pxm b/src/database/Cave.pxm new file mode 100644 index 0000000..b275867 Binary files /dev/null and b/src/database/Cave.pxm differ diff --git a/src/database/items.lua b/src/database/items.lua index cd5b54a..87dcc7f 100644 --- a/src/database/items.lua +++ b/src/database/items.lua @@ -103,7 +103,7 @@ function missiles(t) } end -return { +local data = { ------------- -- WEAPONS -- ------------- @@ -326,7 +326,7 @@ return { map = "EggR2", label = "0302", }), - wSuperMissileLauncher = { + mSuperMissileLauncher = { name = "Super Missile Launcher", map = "MazeS", getText = { @@ -350,6 +350,12 @@ return { -- concealing a chest containing this massive expansion of 24 Misisles. } +for k, t in pairs(data) do + t.key = k +end + +return data + --[[ -- Weapons diff --git a/src/main.lua b/src/main.lua index 4f179c0..b6eaa58 100644 --- a/src/main.lua +++ b/src/main.lua @@ -10,6 +10,8 @@ Terebi = require 'lib.terebi' lf = love.filesystem lg = love.graphics +U = require 'util' + local LOG_LEVEL = 3 local function _log(level, prefix, text, ...) if LOG_LEVEL >= level then diff --git a/src/randomizer.lua b/src/randomizer.lua index b5d8e87..4065293 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -14,6 +14,12 @@ do end end +local WEAPONS_WHICH_CAN_NOT_BREAK_BLOCKS = { + 'wBubbline', + 'wFireball', + 'wSnake', +} + function C:randomize(path) local success, dirStage = self:_mountDirectory(path) if not success then @@ -21,8 +27,11 @@ function C:randomize(path) end self:_seedRngesus() local tscFiles = self:_createTscFiles(dirStage) - self:_shuffleItems(tscFiles) + local canNotBreakBlocks = self:_shuffleItems(tscFiles) self:_writeModifiedData(tscFiles) + if canNotBreakBlocks then + self:_copyModifiedFirstCave() + end self:_unmountDirectory(path) return [[Randomized data successfully created! @@ -76,7 +85,8 @@ function C:_shuffleItems(tscFiles) {'Cave.tsc', 'lFirstCave'}, {'Pole.tsc', 'wPolarStar'}, })) - tscFiles[firstArea]:replaceSpecificItem(firstItemKey, itemDeck:getWeapon()) + local firstWeapon = itemDeck:getWeapon() + tscFiles[firstArea]:replaceSpecificItem(firstItemKey, firstWeapon) -- Replace all weapon trades with random weapons tscFiles['Curly.tsc']:replaceSpecificItem('wMachineGun', itemDeck:getWeapon()) @@ -90,6 +100,8 @@ function C:_shuffleItems(tscFiles) tscFile:replaceItem(itemDeck:getAny()) end end + + return _.contains(WEAPONS_WHICH_CAN_NOT_BREAK_BLOCKS, firstWeapon.key) end function C:_writeModifiedData(tscFiles) @@ -106,6 +118,13 @@ function C:_writeModifiedData(tscFiles) end end +function C:_copyModifiedFirstCave() + local cavePxmPath = lf.getSourceBaseDirectory() .. '/data/Stage/Cave.pxm' + local data = lf.read('database/Cave.pxm') + assert(data) + U.writeFile(cavePxmPath, data) +end + function C:_unmountDirectory(path) assert(lf.unmount(path)) print("\n") diff --git a/src/tsc_file.lua b/src/tsc_file.lua index 6586446..3d97d3e 100644 --- a/src/tsc_file.lua +++ b/src/tsc_file.lua @@ -1,10 +1,5 @@ local C = Class:extend() --- https://www.lua.org/manual/5.1/manual.html#5.7 --- w+: Update mode, all previous data is erased; --- b: Binary mode, forces Windows to save with Unix endings. -MODE_WRITE_ERASE_EXISTING = 'w+b' - local ITEM_DATA = require 'database.items' function C:new(path) @@ -27,7 +22,6 @@ function C:new(path) break -- continue end local item = _.clone(v) - item.key = k table.insert(self._unreplaced, item) until true end self._unreplaced = _.shuffle(self._unreplaced) @@ -130,13 +124,8 @@ end function C:writeTo(path) logInfo('writing TSC to: ' .. path) - - local file, err = io.open(path, MODE_WRITE_ERASE_EXISTING) - assert(err == nil, err) local encoded = self:_codec(self._text, 'encode') - file:write(encoded) - file:flush() - file:close() + U.writeFile(path, encoded) end function C:_codec(text, mode) diff --git a/src/util.lua b/src/util.lua new file mode 100644 index 0000000..03ff064 --- /dev/null +++ b/src/util.lua @@ -0,0 +1,18 @@ +local U = {} + +-- https://www.lua.org/manual/5.1/manual.html#5.7 +-- w+: Update mode, all previous data is erased; +-- b: Binary mode, forces Windows to save with Unix endings. +MODE_WRITE_ERASE_EXISTING = 'w+b' + +function U.writeFile(path, data) + logDebug('writing file: ' .. path) + + local file, err = io.open(path, MODE_WRITE_ERASE_EXISTING) + assert(err == nil, err) + file:write(data) + file:flush() + file:close() +end + +return U