Print warning/error count in status, write log to data dir.

This commit is contained in:
shru 2018-12-19 16:39:40 -05:00
parent db1ee6cf3e
commit 5724188da4
5 changed files with 48 additions and 14 deletions

View file

@ -4,9 +4,6 @@ Cave Story Randomizer
Todo Todo
---- ----
- Print Warning/Error Count
- Supress Hell Music Error
- Write log
- Support Cave Story+ - Support Cave Story+
- Missiles should only replace items which are not part of cutscenes. - 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. - Trade Sequence Step B: Require random obtainable weapon, instead of always polar star and fireball.

View file

@ -82,7 +82,7 @@ function lifeCapsule(t)
}, },
command = ("<ML+000%d"):format(t.hp), command = ("<ML+000%d"):format(t.hp),
displayCmd = "<GIT1006", displayCmd = "<GIT1006",
music = "<CMU0016", music = t.music or "<CMU0016",
erase = ("Max health increased by %d!<NOD"):format(t.hp), erase = ("Max health increased by %d!<NOD"):format(t.hp),
} }
end end
@ -304,6 +304,7 @@ local data = {
lHell = lifeCapsule({ lHell = lifeCapsule({
hp = 5, hp = 5,
map = "Hell1", map = "Hell1",
music = "",
label = "0400" label = "0400"
}), }),

View file

@ -12,17 +12,32 @@ lg = love.graphics
U = require 'util' U = require 'util'
local LOG_LEVEL = 3 local LOG_LEVEL, _logCounts, _logLines = 3, nil, nil
local function _log(level, prefix, text, ...) local function _log(level, prefix, text, ...)
if LOG_LEVEL >= level then if LOG_LEVEL >= level then
print(prefix .. text, ...) local text = prefix .. text
print(text, ...)
table.insert(_logLines, text)
end end
_logCounts[level] = _logCounts[level] + 1
end end
function logError(...) _log(1, 'ERROR: ', ...) end function logError(...) _log(1, 'ERROR: ', ...) end
function logWarning(...) _log(2, 'WARNING: ', ...) end function logWarning(...) _log(2, 'WARNING: ', ...) end
function logNotice(...) _log(3, 'NOTICE: ', ...) end function logNotice(...) _log(3, 'NOTICE: ', ...) end
function logInfo(...) _log(4, 'INFO: ', ...) end function logInfo(...) _log(4, 'INFO: ', ...) end
function logDebug(...) _log(5, 'DEBUG: ', ...) 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 randomizer = require 'randomizer'()
local background local background

View file

@ -21,6 +21,7 @@ local WEAPONS_WHICH_CAN_NOT_BREAK_BLOCKS = {
} }
function C:randomize(path) function C:randomize(path)
resetLog()
local success, dirStage = self:_mountDirectory(path) local success, dirStage = self:_mountDirectory(path)
if not success then if not success then
return "Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?" 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 if canNotBreakBlocks then
self:_copyModifiedFirstCave() self:_copyModifiedFirstCave()
end end
self:_writeLog()
self:_unmountDirectory(path) self:_unmountDirectory(path)
return [[Randomized data successfully created! return self:_getStatusMessage()
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!]]
end end
function C:_mountDirectory(path) function C:_mountDirectory(path)
@ -125,9 +123,31 @@ function C:_copyModifiedFirstCave()
U.writeFile(cavePxmPath, data) U.writeFile(cavePxmPath, data)
end end
function C:_unmountDirectory(path) function C:_writeLog()
assert(lf.unmount(path)) local path = lf.getSourceBaseDirectory() .. '/data/log.txt'
local data = getLogText()
U.writeFile(path, data)
print("\n") print("\n")
end 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 return C

View file

@ -103,8 +103,9 @@ function C:_replaceAttribute(original, replacement, attribute)
end end
until true end until true end
local logMethod = (attribute == 'command') and logError or logWarning
local template = 'Unable to replace original "%s" for [%s] %s.' 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 end
function C:_stringReplace(text, needle, replacement) function C:_stringReplace(text, needle, replacement)