mirror of
https://github.com/cave-story-randomizer/cave-story-randomizer
synced 2024-12-23 05:37:10 +00:00
Print warning/error count in status, write log to data dir.
This commit is contained in:
parent
db1ee6cf3e
commit
5724188da4
|
@ -4,9 +4,6 @@ Cave Story Randomizer
|
|||
Todo
|
||||
----
|
||||
|
||||
- Print Warning/Error Count
|
||||
- Supress Hell Music Error
|
||||
- Write log
|
||||
- Support Cave Story+
|
||||
- Missiles should only replace items which are not part of cutscenes.
|
||||
- Trade Sequence Step B: Require random obtainable weapon, instead of always polar star and fireball.
|
||||
|
|
|
@ -82,7 +82,7 @@ function lifeCapsule(t)
|
|||
},
|
||||
command = ("<ML+000%d"):format(t.hp),
|
||||
displayCmd = "<GIT1006",
|
||||
music = "<CMU0016",
|
||||
music = t.music or "<CMU0016",
|
||||
erase = ("Max health increased by %d!<NOD"):format(t.hp),
|
||||
}
|
||||
end
|
||||
|
@ -304,6 +304,7 @@ local data = {
|
|||
lHell = lifeCapsule({
|
||||
hp = 5,
|
||||
map = "Hell1",
|
||||
music = "",
|
||||
label = "0400"
|
||||
}),
|
||||
|
||||
|
|
19
src/main.lua
19
src/main.lua
|
@ -12,17 +12,32 @@ lg = love.graphics
|
|||
|
||||
U = require 'util'
|
||||
|
||||
local LOG_LEVEL = 3
|
||||
local LOG_LEVEL, _logCounts, _logLines = 3, nil, nil
|
||||
local function _log(level, prefix, text, ...)
|
||||
|
||||
if LOG_LEVEL >= level then
|
||||
print(prefix .. text, ...)
|
||||
local text = prefix .. text
|
||||
print(text, ...)
|
||||
table.insert(_logLines, text)
|
||||
end
|
||||
_logCounts[level] = _logCounts[level] + 1
|
||||
end
|
||||
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
|
||||
function countLogWarningsAndErrors()
|
||||
return _logCounts[2], _logCounts[1]
|
||||
end
|
||||
function getLogText()
|
||||
return table.concat(_logLines, "\n")
|
||||
end
|
||||
function resetLog()
|
||||
_logCounts = {0, 0, 0, 0, 0}
|
||||
_logLines = {}
|
||||
end
|
||||
resetLog()
|
||||
|
||||
local randomizer = require 'randomizer'()
|
||||
local background
|
||||
|
|
|
@ -21,6 +21,7 @@ local WEAPONS_WHICH_CAN_NOT_BREAK_BLOCKS = {
|
|||
}
|
||||
|
||||
function C:randomize(path)
|
||||
resetLog()
|
||||
local success, dirStage = self:_mountDirectory(path)
|
||||
if not success then
|
||||
return "Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?"
|
||||
|
@ -32,12 +33,9 @@ function C:randomize(path)
|
|||
if canNotBreakBlocks then
|
||||
self:_copyModifiedFirstCave()
|
||||
end
|
||||
self:_writeLog()
|
||||
self:_unmountDirectory(path)
|
||||
return [[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!]]
|
||||
return self:_getStatusMessage()
|
||||
end
|
||||
|
||||
function C:_mountDirectory(path)
|
||||
|
@ -125,9 +123,31 @@ function C:_copyModifiedFirstCave()
|
|||
U.writeFile(cavePxmPath, data)
|
||||
end
|
||||
|
||||
function C:_unmountDirectory(path)
|
||||
assert(lf.unmount(path))
|
||||
function C:_writeLog()
|
||||
local path = lf.getSourceBaseDirectory() .. '/data/log.txt'
|
||||
local data = getLogText()
|
||||
U.writeFile(path, data)
|
||||
print("\n")
|
||||
end
|
||||
|
||||
function C:_unmountDirectory(path)
|
||||
assert(lf.unmount(path))
|
||||
end
|
||||
|
||||
function C:_getStatusMessage()
|
||||
local warnings, errors = countLogWarningsAndErrors()
|
||||
local line1
|
||||
if warnings == 0 and errors == 0 then
|
||||
line1 = "Randomized data successfully created!"
|
||||
elseif warnings ~= 0 and errors == 0 then
|
||||
line1 = ("Randomized data was created with %d warning(s)."):format(warnings)
|
||||
else
|
||||
return ("Encountered %d error(s) and %d warning(s) when randomizing data!"):format(errors, warnings)
|
||||
end
|
||||
local line2 = "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!"
|
||||
local line3 = "Then play and have a fun!"
|
||||
local status = ("%s\n\n%s\n\n%s"):format(line1, line2, line3)
|
||||
return status
|
||||
end
|
||||
|
||||
return C
|
||||
|
|
|
@ -103,8 +103,9 @@ function C:_replaceAttribute(original, replacement, attribute)
|
|||
end
|
||||
until true end
|
||||
|
||||
local logMethod = (attribute == 'command') and logError or logWarning
|
||||
local template = 'Unable to replace original "%s" for [%s] %s.'
|
||||
logWarning(template:format(attribute, original.map, original.name))
|
||||
logMethod(template:format(attribute, original.map, original.name))
|
||||
end
|
||||
|
||||
function C:_stringReplace(text, needle, replacement)
|
||||
|
|
Loading…
Reference in a new issue