improves log generation - in future it will be easy to disable spoilers

This commit is contained in:
duncathan 2019-03-21 00:39:30 -06:00
parent c6efbb225b
commit 9f189ea869
4 changed files with 105 additions and 93 deletions

View file

@ -1,17 +1,17 @@
local Region = require 'database.region'
local Location = require 'database.location'
function has(items, attribute)
return count(items, attribute) > 0
function _has(items, attribute)
return _count(items, attribute) > 0
end
function count(items, attribute)
function _count(items, attribute)
return #_.filter(items, function(k,v) return _.contains(v.attributes, attribute) end)
end
local firstCave = Region:extend()
function firstCave:new(worldGraph)
firstCave.super.new(self, worldGraph, "firstCave")
firstCave.super.new(self, worldGraph, "First Cave")
self.locations = {
firstCapsule = Location("First Cave Life Capsule", "Cave", "0401", self),
gunsmithChest = Location("Hermit Gunsmith Chest", "Pole", "0202", self),
@ -19,13 +19,13 @@ function firstCave:new(worldGraph)
}
self.locations.gunsmith.requirements = function(self, items)
return has(items, "flight") and has(items, "polarStar") and has(items, "eventCore") and self.region.world.regions.mimigaVillage:canAccess(items)
return _has(items, "flight") and _has(items, "polarStar") and _has(items, "eventCore") and self.region.world.regions.mimigaVillage:canAccess(items)
end
end
local mimigaVillage = Region:extend()
function mimigaVillage:new(worldGraph)
mimigaVillage.super.new(self, worldGraph, "mimigaVillage")
mimigaVillage.super.new(self, worldGraph, "Mimiga Village")
self.locations = {
yamashita = Location("Yamashita Farm", "Plant", "0401", self),
reservoir = Location("Reservoir", "Pool", "0301", self),
@ -38,23 +38,23 @@ function mimigaVillage:new(worldGraph)
}
self.requirements = function(self, items)
if has(items, "weaponSN") and self.world.regions.firstCave:canAccess(items) then return true end
if _has(items, "weaponSN") and self.world.regions.firstCave:canAccess(items) then return true end
return false
end
self.locations.assembly.requirements = function(self, items) return has(items, "juice") end
self.locations.assembly.requirements = function(self, items) return _has(items, "juice") end
self.locations.mrLittle.requirements = function(self, items)
return has(items, "flight") and has(items, "locket") and self.region.world.regions.outerWall.locations.littleHouse:canAccess(items)
return _has(items, "flight") and _has(items, "locket") and self.region.world.regions.outerWall.locations.littleHouse:canAccess(items)
end
self.locations.grave.requirements = function(self, items) return has(items, "locket") end
self.locations.grave.requirements = function(self, items) return _has(items, "locket") end
self.locations.mushroomChest.requirements = function(self, items)
return has(items, "flight") and has(items, "locket") and has(items, "eventCurly")
return _has(items, "flight") and _has(items, "locket") and _has(items, "eventCurly")
end
self.locations.maPignon.requirements = function(self, items)
-- stupid mushroom is invincible to the blade and machinegun for some reason
if has(items, "flight") and has(items, "locket") and has(items, "mushroomBadge") then
if has(items, "polarStar") or has(items, "fireball") or has(items, "bubbler")
or has(items, "machineGun") or has(items, "snake") or has(items, "nemesis") then
if _has(items, "flight") and _has(items, "locket") and _has(items, "mushroomBadge") then
if _has(items, "polarStar") or _has(items, "fireball") or _has(items, "bubbler")
or _has(items, "machineGun") or _has(items, "snake") or _has(items, "nemesis") then
return true
end
end
@ -66,22 +66,22 @@ end
local arthur = Region:extend()
function arthur:new(worldGraph)
arthur.super.new(self, worldGraph, "arthur")
arthur.super.new(self, worldGraph, "Arthur's House")
self.locations = {
risenBooster = Location("Professor Booster", "Pens1", "0652", self)
}
self.requirements = function(self, items)
if has(items, "arthurKey") and self.world.regions.mimigaVillage:canAccess(items) then return true end
if _has(items, "arthurKey") and self.world.regions.mimigaVillage:canAccess(items) then return true end
return false
end
self.locations.risenBooster.requirements = function(self, items) return has(items, "eventCore") end
self.locations.risenBooster.requirements = function(self, items) return _has(items, "eventCore") end
end
local eggCorridor1 = Region:extend()
function eggCorridor1:new(worldGraph)
eggCorridor1.super.new(self, worldGraph, "eggCorridor1")
eggCorridor1.super.new(self, worldGraph, "Egg Corridor")
self.locations = {
basil = Location("Basil Spot", "Eggs", "0403", self),
cthulhu = Location("Cthulhu's Abode", "Eggs", "0404", self),
@ -92,13 +92,13 @@ function eggCorridor1:new(worldGraph)
self.requirements = function(self, items) return self.world.regions.arthur:canAccess(items) end
self.locations.eventSue.requirements = function(self, items) return has(items, "idCard") and has(items, "weaponBoss") end
self.locations.eventSue.requirements = function(self, items) return _has(items, "idCard") and _has(items, "weaponBoss") end
self.locations.eventSue:setItem(self.world.items:getByKey("eventSue"))
end
local grasstownWest = Region:extend()
function grasstownWest:new(worldGraph)
grasstownWest.super.new(self, worldGraph, "grasstownWest")
grasstownWest.super.new(self, worldGraph, "Grasstown (West)")
self.locations = {
keySpot = Location("West Grasstown Floor", "Weed", "0700", self),
jellyCapsule = Location("West Grasstown Ceiling", "Weed", "0701", self),
@ -113,15 +113,15 @@ function grasstownWest:new(worldGraph)
return false
end
self.locations.santa.requirements = function(self, items) return has(items, "santaKey") end
self.locations.charcoal.requirements = function(self, items) return has(items, "santaKey") and has(items, "juice") end
self.locations.chaco.requirements = function(self, items) return has(items, "santaKey") end
self.locations.kulala.requirements = function(self, items) return has(items, "santaKey") and has(items, "weapon") end
self.locations.santa.requirements = function(self, items) return _has(items, "santaKey") end
self.locations.charcoal.requirements = function(self, items) return _has(items, "santaKey") and _has(items, "juice") end
self.locations.chaco.requirements = function(self, items) return _has(items, "santaKey") end
self.locations.kulala.requirements = function(self, items) return _has(items, "santaKey") and _has(items, "weapon") end
end
local grasstownEast = Region:extend()
function grasstownEast:new(worldGraph)
grasstownEast.super.new(self, worldGraph, "grasstownEast")
grasstownEast.super.new(self, worldGraph, "Grasstown (East)")
self.locations = {
kazuma1 = Location("Kazuma (Rusty Key)", "Weed", "0800", self),
kazuma2 = Location("Kazuma (Gum Key)", "Weed", "0801", self),
@ -136,34 +136,34 @@ function grasstownEast:new(worldGraph)
self.requirements = function(self, items)
if not self.world.regions.arthur:canAccess(items) then return false end
if has(items, "flight") or has(items, "juice") then
if _has(items, "flight") or _has(items, "juice") then
if self.world.regions.grasstownWest:canAccess(items) then return true end
end
if has(items, "eventKazuma") and has(items, "weaponSN") and self.world.regions.plantation:canAccess(items) then return true end
if _has(items, "eventKazuma") and _has(items, "weaponSN") and self.world.regions.plantation:canAccess(items) then return true end
return false
end
self.locations.kazuma2.requirements = function(self, items) return has(items, "eventFans") end
self.locations.execution.requirements = function(self, items) return has(items, "weaponSN") end
self.locations.hutChest.requirements = function(self, items) return has(items, "eventFans") or has(items, "flight") end
self.locations.kazuma2.requirements = function(self, items) return _has(items, "eventFans") end
self.locations.execution.requirements = function(self, items) return _has(items, "weaponSN") end
self.locations.hutChest.requirements = function(self, items) return _has(items, "eventFans") or _has(items, "flight") end
self.locations.gumChest.requirements = function(self, items)
if has(items, "gumKey") and has(items, "weaponBoss") then
if has(items, "eventFans") or has(items, "flight") then return true end
if _has(items, "gumKey") and _has(items, "weaponBoss") then
if _has(items, "eventFans") or _has(items, "flight") then return true end
end
return false
end
self.locations.malco.requirements = function(self, items) return has(items, "eventFans") and has(items, "juice") and has(items, "charcoal") and has(items, "gum") end
self.locations.malco.requirements = function(self, items) return _has(items, "eventFans") and _has(items, "juice") and _has(items, "charcoal") and _has(items, "gum") end
self.locations.eventFans.requirements = function(self, items) return has(items, "rustyKey") and has(items, "weaponBoss") end
self.locations.eventFans.requirements = function(self, items) return _has(items, "rustyKey") and _has(items, "weaponBoss") end
self.locations.eventFans:setItem(self.world.items:getByKey("eventFans"))
self.locations.eventKazuma.requirements = function(self, items) return has(items, "bomb") end
self.locations.eventKazuma.requirements = function(self, items) return _has(items, "bomb") end
self.locations.eventKazuma:setItem(self.world.items:getByKey("eventKazuma"))
end
local upperSandZone = Region:extend()
function upperSandZone:new(worldGraph)
upperSandZone.super.new(self, worldGraph, "upperSandZone")
upperSandZone.super.new(self, worldGraph, "Sand Zone (Upper)")
self.locations = {
curly = Location("Curly Boss", "Curly", "0518", self),
panties = Location("Curly's Closet", "CurlyS", "0421", self),
@ -173,19 +173,19 @@ function upperSandZone:new(worldGraph)
}
self.requirements = function(self, items)
if has(items, "weaponSN") and self.world.regions.arthur:canAccess(items) then return true end
if _has(items, "weaponSN") and self.world.regions.arthur:canAccess(items) then return true end
return false
end
self.locations.curly.requirements = function(self, items) return has(items, "polarStar") end
self.locations.curly.requirements = function(self, items) return _has(items, "polarStar") end
self.locations.eventOmega.requirements = function(self, items) return has(items, "weaponBoss") end
self.locations.eventOmega.requirements = function(self, items) return _has(items, "weaponBoss") end
self.locations.eventOmega:setItem(self.world.items:getByKey("eventOmega"))
end
local lowerSandZone = Region:extend()
function lowerSandZone:new(worldGraph)
lowerSandZone.super.new(self, worldGraph, "lowerSandZone")
lowerSandZone.super.new(self, worldGraph, "Sand Zone (Lower)")
self.locations = {
chestPup = Location("Puppy (Chest)", "Sand", "0421", self),
darkPup = Location("Puppy (Dark)", "Dark", "0401", self),
@ -199,22 +199,22 @@ function lowerSandZone:new(worldGraph)
self.requirements = function(self, items)
if not self.world.regions.arthur:canAccess(items) then return false end
if has(items, "eventOmega") and self.world.regions.upperSandZone:canAccess(items) then return true end
if _has(items, "eventOmega") and self.world.regions.upperSandZone:canAccess(items) then return true end
return false
end
self.locations.jenka.requirements = function(self, items) return count(items, "puppy") == 5 end
self.locations.king.requirements = function(self, items) return has(items, "eventToroko") end
self.locations.jenka.requirements = function(self, items) return _count(items, "puppy") == 5 end
self.locations.king.requirements = function(self, items) return _has(items, "eventToroko") end
self.locations.eventToroko.requirements = function(self, items)
return count(items, "puppy") == 5 and has(items, "weaponBoss")
return _count(items, "puppy") == 5 and _has(items, "weaponBoss")
end
self.locations.eventToroko:setItem(self.world.items:getByKey("eventToroko"))
end
local labyrinthW = Region:extend()
function labyrinthW:new(worldGraph)
labyrinthW.super.new(self, worldGraph, "labyrinthW")
labyrinthW.super.new(self, worldGraph, "Labyrinth (West)")
self.locations = {
mazeCapsule = Location("Labyrinth Life Capsule", "MazeI", "0301", self),
turboChaba = Location("Chaba Chest (Machine Gun)", "MazeA", "0502", self),
@ -227,22 +227,22 @@ function labyrinthW:new(worldGraph)
self.requirements = function(self, items)
if not self.world.regions.arthur:canAccess(items) then return false end
if has(items, "eventToroko") and self.world.regions.lowerSandZone:canAccess(items) then return true end
if has(items, "flight") and self.world.regions.labyrinthB:canAccess(items) then return true end
if _has(items, "eventToroko") and self.world.regions.lowerSandZone:canAccess(items) then return true end
if _has(items, "flight") and self.world.regions.labyrinthB:canAccess(items) then return true end
return false
end
self.locations.mazeCapsule.requirements = function(self, items) return has(items, "weapon") end
self.locations.turboChaba.requirements = function(self, items) return has(items, "machineGun") end
self.locations.snakeChaba.requirements = function(self, items) return has(items, "fireball") end
self.locations.whimChaba.requirements = function(self, items) return count(items, "polarStar") == 2 end
self.locations.campChest.requirements = function(self, items) return has(items, "flight") end
self.locations.puuBlack.requirements = function(self, items) return has(items, "clinicKey") and has(items, "weaponBoss") end
self.locations.mazeCapsule.requirements = function(self, items) return _has(items, "weapon") end
self.locations.turboChaba.requirements = function(self, items) return _has(items, "machineGun") end
self.locations.snakeChaba.requirements = function(self, items) return _has(items, "fireball") end
self.locations.whimChaba.requirements = function(self, items) return _count(items, "polarStar") == 2 end
self.locations.campChest.requirements = function(self, items) return _has(items, "flight") end
self.locations.puuBlack.requirements = function(self, items) return _has(items, "clinicKey") and _has(items, "weaponBoss") end
end
local labyrinthB = Region:extend()
function labyrinthB:new(worldGraph)
labyrinthB.super.new(self, worldGraph, "labyrinthB")
labyrinthB.super.new(self, worldGraph, "Labyrinth B")
self.locations = {
fallenBooster = Location("Booster Chest", "MazeB", "0502", self)
}
@ -255,7 +255,7 @@ end
local boulder = Region:extend()
function boulder:new(worldGraph)
boulder.super.new(self, worldGraph, "boulder")
boulder.super.new(self, worldGraph, "Labyrinth (East)")
self.locations = { --include core locations since core access reqs are identical to boulder chamber
boulderChest = Location("Boulder Chest", "MazeS", "0202", self),
coreSpot = Location("Robot's Arm", "Almond", "0243", self),
@ -265,7 +265,7 @@ function boulder:new(worldGraph)
self.requirements = function(self, items)
if not self.world.regions.arthur:canAccess(items) then return false end
if has(items, "cureAll") and has(items, "weaponBoss") then
if _has(items, "cureAll") and _has(items, "weaponBoss") then
if self.world.regions.labyrinthW:canAccess(items) then return true end
end
return false
@ -281,14 +281,14 @@ function labyrinthM:new(worldGraph)
self.requirements = function(self, items)
if not self.world.regions.arthur:canAccess(items) then return false end
if self.world.regions.boulder:canAccess(items) then return true end
if has(items, "flight") and self.world.regions.labyrinthW:canAccess(items) then return true end
if _has(items, "flight") and self.world.regions.labyrinthW:canAccess(items) then return true end
return false
end
end
local waterway = Region:extend()
function waterway:new(worldGraph)
waterway.super.new(self, worldGraph, "waterway")
waterway.super.new(self, worldGraph, "Waterway")
self.locations = {
ironhead = Location("Ironhead Boss", "Pool", "0412", self),
@ -297,17 +297,17 @@ function waterway:new(worldGraph)
self.requirements = function(self, items)
if not self.world.regions.arthur:canAccess(items) then return false end
if has(items, "airTank") and has(items, "weaponBoss") and self.world.regions.labyrinthM:canAccess(items) then return true end
if _has(items, "airTank") and _has(items, "weaponBoss") and self.world.regions.labyrinthM:canAccess(items) then return true end
return false
end
self.locations.eventCurly.requirements = function(self, items) return has(items, "eventCore") and has(items, "towRope") end
self.locations.eventCurly.requirements = function(self, items) return _has(items, "eventCore") and _has(items, "towRope") end
self.locations.eventCurly:setItem(self.world.items:getByKey("eventCurly"))
end
local eggCorridor2 = Region:extend()
function eggCorridor2:new(worldGraph)
eggCorridor2.super.new(self, worldGraph, "eggCorridor2")
eggCorridor2.super.new(self, worldGraph, "Egg Corridor?")
self.locations = {
dragonChest = Location("Dragon Chest", "Eggs2", "0321", self),
@ -316,18 +316,18 @@ function eggCorridor2:new(worldGraph)
self.requirements = function(self, items)
if not self.world.regions.arthur:canAccess(items) then return false end
if has(items, "eventCore") then return true end
if has(items, "eventKazuma") and self.world.regions.outerWall:canAccess(items) then return true end
if _has(items, "eventCore") then return true end
if _has(items, "eventKazuma") and self.world.regions.outerWall:canAccess(items) then return true end
return false
end
self.locations.dragonChest.requirements = function(self, items) return has(items, "weapon") end
self.locations.sisters.requirements = function(self, items) return has(items, "weaponBoss") end
self.locations.dragonChest.requirements = function(self, items) return _has(items, "weapon") end
self.locations.sisters.requirements = function(self, items) return _has(items, "weaponBoss") end
end
local outerWall = Region:extend()
function outerWall:new(worldGraph)
outerWall.super.new(self, worldGraph, "outerWall")
outerWall.super.new(self, worldGraph, "Outer Wall")
self.locations = {
clock = Location("Clock Room", "Clock", "0300", self),
@ -336,17 +336,17 @@ function outerWall:new(worldGraph)
self.requirements = function(self, items)
if not self.world.regions.arthur:canAccess(items) then return false end
if has(items, "eventKazuma") and has(items, "flight") and self.world.regions.eggCorridor2:canAccess(items) then return true end
if has(items, "teleportKey") and self.world.regions.plantation:canAccess(items) then return true end
if _has(items, "eventKazuma") and _has(items, "flight") and self.world.regions.eggCorridor2:canAccess(items) then return true end
if _has(items, "teleportKey") and self.world.regions.plantation:canAccess(items) then return true end
return false
end
self.locations.littleHouse.requirements = function(self, items) return has(items, "flight") end
self.locations.littleHouse.requirements = function(self, items) return _has(items, "flight") end
end
local plantation = Region:extend()
function plantation:new(worldGraph)
plantation.super.new(self, worldGraph, "plantation")
plantation.super.new(self, worldGraph, "Plantation")
self.locations = {
kanpachi = Location("Kanpachi's Bucket", "Cent", "0268", self),
@ -363,40 +363,40 @@ function plantation:new(worldGraph)
self.requirements = function(self, items)
if not self.world.regions.arthur:canAccess(items) then return false end
if has(items, "teleportKey") then return true end
if _has(items, "teleportKey") then return true end
if self.world.regions.outerWall:canAccess(items) then return true end
return false
end
self.locations.jail1.requirements = function(self, items) return has(items, "letter") end
self.locations.momorin.requirements = function(self, items) return has(items, "letter") and has(items, "booster") end
self.locations.sprinkler.requirements = function(self, items) return has(items, "mask") end
self.locations.megane.requirements = function(self, items) return has(items, "brokenSprinkler") and has(items, "mask") end
self.locations.itoh.requirements = function(self, items) return has(items, "letter") end
self.locations.plantCeiling.requirements = function(self, items) return has(items, "flight") end
self.locations.plantPup.requirements = function(self, items) return has(items, "eventRocket") end
self.locations.curlyShroom.requirements = function(self, items) return has(items, "eventCurly") and has(items, "maPignon") end
self.locations.jail1.requirements = function(self, items) return _has(items, "letter") end
self.locations.momorin.requirements = function(self, items) return _has(items, "letter") and _has(items, "booster") end
self.locations.sprinkler.requirements = function(self, items) return _has(items, "mask") end
self.locations.megane.requirements = function(self, items) return _has(items, "brokenSprinkler") and _has(items, "mask") end
self.locations.itoh.requirements = function(self, items) return _has(items, "letter") end
self.locations.plantCeiling.requirements = function(self, items) return _has(items, "flight") end
self.locations.plantPup.requirements = function(self, items) return _has(items, "eventRocket") end
self.locations.curlyShroom.requirements = function(self, items) return _has(items, "eventCurly") and _has(items, "maPignon") end
self.locations.eventRocket.requirements = function(self, items)
return has(items, "letter") and has(items, "booster") and has(items, "controller") and has(items, "sprinkler")
return _has(items, "letter") and _has(items, "booster") and _has(items, "controller") and _has(items, "sprinkler")
end
self.locations.eventRocket:setItem(self.world.items:getByKey("eventRocket"))
end
local lastCave = Region:extend()
function lastCave:new(worldGraph)
lastCave.super.new(self, worldGraph, "lastCave")
lastCave.super.new(self, worldGraph, "Last Cave")
self.locations = {
redDemon = Location("Red Demon Boss", "Priso2", "0300", self)
}
self.requirements = function(self, items) return has(items, "eventRocket") and has(items, "weaponBoss") end
self.requirements = function(self, items) return _has(items, "eventRocket") and _has(items, "weaponBoss") end
end
local endgame = Region:extend()
function endgame:new(worldGraph)
endgame.super.new(self, worldGraph, "endgame")
endgame.super.new(self, worldGraph, "Sacred Grounds")
self.locations = {
hellB1 = Location("Hell B1 Spot", "Hell1", "0401", self),
@ -404,7 +404,7 @@ function endgame:new(worldGraph)
}
self.requirements = function(self, items)
return has(items, "eventSue") and has(items, "ironBond") and self.world.regions.lastCave:canAccess(items)
return _has(items, "eventSue") and _has(items, "ironBond") and self.world.regions.lastCave:canAccess(items)
end
end
@ -529,4 +529,18 @@ function worldGraph.locationsArray(locations)
return array
end
function worldGraph:logLocations()
for k,r in pairs(self.regions) do
if next(r.locations) then
logSpoiler("")
logSpoiler("Region: " .. r.name)
for k2,l in pairs(r.locations) do
if not _has({l.item}, "event") then
logSpoiler("\t " .. l.name .. ": " .. l.item.name)
end
end
end
end
end
return worldGraph

View file

@ -13,7 +13,7 @@ lg = love.graphics
U = require 'util'
local LOG_LEVEL, _logCounts, _logLines = 3, nil, nil
local LOG_LEVEL, _logCounts, _logLines = 4, nil, nil
local function _log(level, prefix, text, ...)
if LOG_LEVEL >= level then
local text = prefix .. text
@ -25,16 +25,17 @@ 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 logSpoiler(...) _log(4, 'SPOILER: ', ...) end
function logInfo(...) _log(5, 'INFO: ', ...) end
function logDebug(...) _log(6, 'DEBUG: ', ...) end
function countLogWarningsAndErrors()
return _logCounts[2], _logCounts[1]
end
function getLogText()
return table.concat(_logLines, "\n\r")
return table.concat(_logLines, "\r\n")
end
function resetLog()
_logCounts = {0, 0, 0, 0, 0}
_logCounts = {0, 0, 0, 0, 0, 0}
_logLines = {}
end
resetLog()

View file

@ -118,6 +118,7 @@ function C:_shuffleItems(tscFiles)
assert(#self.worldGraph:getEmptyLocations() == 0, self.worldGraph:emptyString() .. "\r\n" .. self.itemDeck:unplacedString())
self.worldGraph:writeItems(tscFiles)
self.worldGraph:logLocations()
end
function C:_fillItems(items, locations)
@ -165,7 +166,6 @@ function C:_writeLog()
local path = self:_getWritePath() .. '/log.txt'
local data = getLogText()
U.writeFile(path, data)
print("\n")
end
function C:_getWritePath()

View file

@ -40,9 +40,6 @@ function C:hasUnreplacedItems()
end
function C:placeItemAtLocation(item, location)
local template = '[%s] "%s" -> "%s"'
logNotice(template:format(location.map, location.name, item.name))
local wasChanged
self._text, wasChanged = self:_stringReplace(self._text, "<EVE....", item.script, location.event)
if not wasChanged then