This commit is contained in:
Buurazu authored and GitHub committed 2022-01-11 13:57:50 -05:00
1 parent 76a8a2d651
commit e2cd42f1f2
1 file changed
+52 -65
+52 -65
View File
@@ -18,41 +18,71 @@ local logLocation = os.getenv("SYSTEMDRIVE") .. "/Users/" .. os.getenv("USERNAME
local logFound = false
local logCursor = 0
local debugLogLocation = os.getenv("SYSTEMDRIVE") .. "/Users/" .. os.getenv("USERNAME") .. "/Documents/My Games/Binding of Isaac Repentance/tmtrainerlog.txt"
local debugLog = io.open(debugLogLocation, "w+")
--currently english only
local attributeConversions = {
--chain = "Then: ",
chain = "",
active = "On use:#",
pickup_collected = "When you collect a pickup:#",
enemy_kill = "On kill, chance to:#",
damage_taken = "When you take damage:#",
entity_spawned = "When a {T1} is spawned, chance to:#",
tear_fire = "When you fire a tear, chance to:#",
enemy_hit = "On hitting an enemy, chance to:#",
room_clear = "On room clear:#",
active = "On use:",
pickup_collected = "When you collect a pickup:",
enemy_kill = "On kill, chance to:",
damage_taken = "When you take damage:",
entity_spawned = "When a {{ColorGray}}{T1}{{ColorText}} is spawned, chance to:",
tear_fire = "When you fire a tear, chance to:",
enemy_hit = "On hitting an enemy, chance to:",
room_clear = "On room clear:",
area_damage = "Deal {1} damage in an area around you",
add_temporary_effect = "Gain {1} for the room",
convert_entities = "Convert all {1} in the room to {2}",
convert_entities = "Convert all {{ColorGray}}{1}{{ColorText}} in the room to {{ColorGray}}{2}{{ColorText}}",
use_active_item = "Use {1}",
spawn_entity = "Spawn a {1}",
spawn_entity = "Spawn a {{ColorGray}}{1}{{ColorText}}",
fart = "Fart with size {1}",
}
--999.-1?
local genericEntityNames = {
["4.-1"] = "lit Bombs",
["5.-1"] = "pickups",
["5.10"] = "Hearts",
["5.20"] = "Coins",
["5.30"] = "Keys",
["5.40"] = "Bomb pickups",
["5.70"] = "Pills",
["5.300"] = "Cards",
["9.-1"] = "projectiles",
["1000.-1"] = "effects",
}
local lastEffectTrigger = "chain"
local function entityToName(e)
--local name = ""
local name = genericEntityNames[e] or EID.XMLEntityNames[e] or "NO NAME"
if name == "NO NAME" then
debugLog:write(e .. " (" .. name .. ")\n")
debugLog:flush()
end
--if name == "" then return e end
return genericEntityNames[e] or EID.XMLEntityNames[e] or name
end
local function parseEffectLine(raw)
local words = {}
for w in string.gmatch(raw,"%S+") do table.insert(words, w) end
local triggerReplacements = {}
local replacements = {}
local printEffect = true
-- words[1] = "[INFO]", words[2] = "-"
local effectTrigger = words[3]
if (string.find(effectTrigger, "entity_spawned")) then
effectTrigger = "entity_spawned"
triggerReplacements[1] = string.sub(words[3], 16, -2)
triggerReplacements[1] = entityToName(string.sub(words[3], 16, -2))
end
-- words[4] = "->"
local effectType = words[5]
@@ -72,22 +102,21 @@ local function parseEffectLine(raw)
replacements[1] = "{{Collectible" .. Isaac.GetItemIdByName(name) .. "}}" .. name
elseif effectType == "convert_entities" then
--figure out how to convert entity numbers
replacements[1] = words[6]
replacements[2] = words[8]
replacements[1] = entityToName(words[6])
replacements[2] = entityToName(words[8])
elseif effectType == "spawn_entity" then
replacements[1] = words[6]
replacements[1] = entityToName(words[6])
elseif effectType == "fart" then
replacements[1] = words[6]
elseif effectType == "area_damage" then
--I could check for 0 damage here and not show it
--It also has flags in words[8] but they don't seem very useful, usually all zeroes
replacements[1] = words[6]
if words[6] == "0" then printEffect = false end
end
local eidString = ""
if effectTrigger ~= lastEffectTrigger then eidString = eidString .. (attributeConversions[effectTrigger] or (effectTrigger .. "#")) end
eidString = eidString .. (attributeConversions[effectType] or fullEffect) .. extraText .. "#"
if effectTrigger ~= lastEffectTrigger then eidString = eidString .. (attributeConversions[effectTrigger] or effectTrigger) .. "#" end
if printEffect then eidString = eidString .. (attributeConversions[effectType] or fullEffect) .. extraText .. "#" end
for k,v in ipairs(triggerReplacements) do eidString = string.gsub(eidString, "{T" .. k .. "}", v) end
for k,v in ipairs(replacements) do eidString = string.gsub(eidString, "{" .. k .. "}", v) end
@@ -95,38 +124,16 @@ local function parseEffectLine(raw)
return eidString
end
--SOMETHING SCREWY WITH GLOWING HOURGLASS
local function CountLogItems()
local theLog = io.open(logLocation, "r")
theLog:seek("set", logCursor)
local itemCount = 0
local line = theLog:read()
while line ~= nil do
if string.find(line, "initialized with") then
itemCount = itemCount + 1
end
line = theLog:read()
end
theLog:close()
return itemCount
end
local function CheckLogForItems(_)
if (not logFound or game:GetFrameCount() % 5 ~= 0 or not EID:PlayersHaveCollectible(CollectibleType.COLLECTIBLE_TMTRAINER)) then return end
local numEffects = 0
local itemScore = 0
local effects = {}
local eidDesc = ""
local theLog = io.open(logLocation, "r")
theLog:seek("set", logCursor)
local logLines = {}
local line = theLog:read()
while line ~= nil do
if string.find(line, "initialized with") then
@@ -134,27 +141,19 @@ local function CheckLogForItems(_)
spawnedItems = spawnedItems + 1
lastEffectTrigger = "chain"
eidDesc = ""
-- find the number of effects, and the score given
-- (this match gets every number in the line)
-- find the number of effects to watch for
for s in string.gmatch(line, "%d*%.?%d+") do
if count == 0 then
numEffects = tonumber(s)
count = 1
elseif count == 1 then
itemScore = tonumber(s)
end
numEffects = tonumber(s)
break
end
elseif numEffects > 0 then
numEffects = numEffects - 1
table.insert(effects, line)
eidDesc = eidDesc .. parseEffectLine(line)
-- also display the unparsed line for debug purposes (REMOVE THIS)
--eidDesc = eidDesc .. "(" .. line .. ")#"
if numEffects == 0 then
-- Glowing Hour Glass type effects will cause the game to reload all items, check if our desc is equal to the first one
if (EID:getDescriptionObj(5, 100, maxNumber - 1).Description == eidDesc) then spawnedItems = 1 end
EID:addCollectible(maxNumber - spawnedItems, eidDesc)
print("adding " .. (maxNumber - spawnedItems))
--print("adding " .. (maxNumber - spawnedItems))
end
end
@@ -166,8 +165,6 @@ local function CheckLogForItems(_)
end
EID:AddCallback(ModCallbacks.MC_POST_UPDATE, CheckLogForItems)
-- figure out where to resume loading item descriptions when continuing a file
-- unfortunately, I'm not bothering to save descriptions if you close the game
local function GameStartTMTRAINER(_,isSave)
local theLog = io.open(logLocation, "r")
if (theLog == nil) then
@@ -177,17 +174,7 @@ local function GameStartTMTRAINER(_,isSave)
else
logFound = true
end
spawnedItems = 0
--[[if isSave then
-- check what item ID we're on
local config = Isaac.GetItemConfig()
while config:GetCollectible(maxNumber - spawnedItems - 1) ~= nil do
spawnedItems = spawnedItems + 1
end
-- if we exit and reload in a room with a new pedestal to spawn, that item's info is grabbable but spawnedItems would be too high
spawnedItems = spawnedItems - CountLogItems()
print("resuming at " .. (maxNumber - spawnedItems - 1))
end]]
end
EID:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, GameStartTMTRAINER)