2018-12-14 17:17:22 +00:00
|
|
|
require 'lib.strict'
|
|
|
|
|
2018-12-14 19:51:03 +00:00
|
|
|
Class = require 'lib.classic'
|
|
|
|
_ = require 'lib.moses'
|
|
|
|
Serpent = require 'lib.serpent'
|
2018-12-16 02:14:48 +00:00
|
|
|
Terebi = require 'lib.terebi'
|
2018-12-14 17:17:22 +00:00
|
|
|
|
2018-12-14 19:51:03 +00:00
|
|
|
lf = love.filesystem
|
2018-12-16 02:14:48 +00:00
|
|
|
lg = love.graphics
|
2018-12-14 17:17:22 +00:00
|
|
|
|
2018-12-15 04:22:03 +00:00
|
|
|
local LOG_LEVEL = 3
|
2018-12-14 19:51:03 +00:00
|
|
|
local function _log(level, prefix, text, ...)
|
|
|
|
if LOG_LEVEL >= level then
|
|
|
|
print(prefix .. text, ...)
|
2018-12-14 17:17:22 +00:00
|
|
|
end
|
|
|
|
end
|
2018-12-14 19:51:03 +00:00
|
|
|
function logError(...) _log(1, 'ERROR: ', ...) end
|
|
|
|
function logWarning(...) _log(2, 'WARNING: ', ...) end
|
|
|
|
function logNotice(...) _log(3, 'NOTICE: ', ...) end
|
|
|
|
function logInfo(...) _log(4, 'INFO: ', ...) end
|
|
|
|
function logDebug(...) _log(5, 'DEBUG: ', ...) end
|
2018-12-14 17:17:22 +00:00
|
|
|
|
2018-12-14 21:57:56 +00:00
|
|
|
local TSC_FILES = {}
|
|
|
|
do
|
|
|
|
local ITEM_DATA = require 'database.items'
|
|
|
|
for k, v in pairs(ITEM_DATA) do
|
|
|
|
local filename = v.map .. '.tsc'
|
|
|
|
if _.contains(TSC_FILES, filename) == false then
|
|
|
|
table.insert(TSC_FILES, filename)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-14 17:17:22 +00:00
|
|
|
|
2018-12-16 02:14:48 +00:00
|
|
|
local background
|
|
|
|
local font
|
|
|
|
local screen
|
|
|
|
local status
|
|
|
|
|
|
|
|
function love.load()
|
|
|
|
Terebi.initializeLoveDefaults()
|
|
|
|
screen = Terebi.newScreen(320, 240, 2)
|
|
|
|
background = lg.newImage('assets/background.png')
|
|
|
|
font = lg.newFont('assets/monogram_extended.ttf', 16)
|
|
|
|
font:setFilter('nearest', 'nearest', 1)
|
|
|
|
status = "Drag and drop your Cave Story folder here."
|
|
|
|
end
|
|
|
|
|
2018-12-14 17:17:22 +00:00
|
|
|
function love.directorydropped(path)
|
2018-12-14 21:57:56 +00:00
|
|
|
-- Mount.
|
|
|
|
local mountPath = 'mounted-data'
|
|
|
|
assert(lf.mount(path, mountPath))
|
2018-12-16 02:14:48 +00:00
|
|
|
local dirStage = '/' .. mountPath
|
|
|
|
do
|
|
|
|
local items = lf.getDirectoryItems(dirStage)
|
|
|
|
local containsData = _.contains(items, 'data')
|
|
|
|
if containsData then
|
|
|
|
dirStage = dirStage .. '/data'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
do
|
|
|
|
local items = lf.getDirectoryItems(dirStage)
|
|
|
|
local containsStage = _.contains(items, 'Stage')
|
|
|
|
if containsStage then
|
|
|
|
dirStage = dirStage .. '/Stage'
|
|
|
|
else
|
|
|
|
status = "Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2018-12-14 17:17:22 +00:00
|
|
|
|
2018-12-16 02:14:48 +00:00
|
|
|
-- Offer tribute to RNGesus.
|
|
|
|
local seed = tostring(os.time())
|
|
|
|
math.randomseed(seed)
|
|
|
|
logNotice(('Offering seed "%s" to RNGesus'):format(seed))
|
|
|
|
|
|
|
|
-- Create TscFile objects.
|
2018-12-14 19:51:03 +00:00
|
|
|
local tscFiles = {}
|
|
|
|
for _, filename in ipairs(TSC_FILES) do
|
|
|
|
local path = dirStage .. '/' .. filename
|
|
|
|
local TscFile = require 'tsc_file'
|
|
|
|
tscFiles[filename] = TscFile(path)
|
|
|
|
end
|
|
|
|
|
2018-12-14 21:57:56 +00:00
|
|
|
-- Create ItemDeck.
|
2018-12-14 20:38:35 +00:00
|
|
|
local ItemDeck = require 'item_deck'
|
|
|
|
local itemDeck = ItemDeck()
|
|
|
|
|
2018-12-15 18:53:12 +00:00
|
|
|
-- Place random weapon in either First Cave or Hermit Gunsmith.
|
|
|
|
local firstArea = _.sample({'Cave.tsc', 'Pole.tsc'})
|
|
|
|
tscFiles[firstArea]:replaceItem(itemDeck:getWeapon())
|
2018-12-14 21:57:56 +00:00
|
|
|
|
|
|
|
-- Replace all items.
|
|
|
|
for _, tscFile in pairs(tscFiles) do
|
|
|
|
while tscFile:hasUnreplacedItems() do
|
|
|
|
tscFile:replaceItem(itemDeck:getAny())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-15 02:49:12 +00:00
|
|
|
local sourcePath = lf.getSourceBaseDirectory()
|
|
|
|
|
|
|
|
-- Create /data/Stage if it doesn't already exist.
|
|
|
|
local command = ('mkdir "%s"'):format(sourcePath .. '/data/Stage')
|
|
|
|
os.execute(command) -- HERE BE DRAGONS!!!
|
|
|
|
|
2018-12-14 21:57:56 +00:00
|
|
|
-- Write modified files.
|
|
|
|
for filename, tscFile in pairs(tscFiles) do
|
2018-12-15 02:49:12 +00:00
|
|
|
local path = sourcePath .. '/data/Stage/' .. filename
|
2018-12-14 21:57:56 +00:00
|
|
|
tscFile:writeTo(path)
|
|
|
|
end
|
2018-12-14 19:51:03 +00:00
|
|
|
|
2018-12-14 21:57:56 +00:00
|
|
|
-- Unmount.
|
2018-12-14 19:51:03 +00:00
|
|
|
assert(lf.unmount(path))
|
2018-12-15 21:12:22 +00:00
|
|
|
print("\n")
|
2018-12-16 02:14:48 +00:00
|
|
|
|
|
|
|
-- Update status
|
|
|
|
status = [[Randomized data successfully created!
|
|
|
|
|
|
|
|
Next overwrite the files in your copy of Cave Story with the versions in the newly created "data" folder. Don't forget to save a backup of the originals!
|
|
|
|
|
|
|
|
Then play and have a fun!]]
|
2018-12-14 17:17:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function love.keypressed(key)
|
|
|
|
if key == 'escape' then
|
|
|
|
love.event.push('quit')
|
|
|
|
end
|
|
|
|
end
|
2018-12-16 02:14:48 +00:00
|
|
|
|
|
|
|
local function _print(text, x, y, align)
|
|
|
|
align = align or 'center'
|
|
|
|
lg.setFont(font)
|
|
|
|
local limit = 320 - (x * 2)
|
|
|
|
lg.setColor(0, 0, 0)
|
|
|
|
lg.printf(text, x + 1, y + 1, limit, align)
|
|
|
|
lg.setColor(1, 1, 1)
|
|
|
|
lg.printf(text, x, y, limit, align)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _draw()
|
|
|
|
lg.draw(background, 0, 0)
|
|
|
|
_print('Cave Story Randomizer v0.1.0', 0, 10)
|
|
|
|
_print('by shru', 0, 22)
|
|
|
|
_print(status, 10, 65)
|
|
|
|
_print('shru.itch.io', 10, 220, 'left')
|
|
|
|
_print('@shruuu', 10, 220, 'right')
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.draw()
|
|
|
|
screen:draw(_draw)
|
|
|
|
end
|