Added helper function to print errors in console and log

This commit is contained in:
Wofsauge committed 2025-03-07 16:39:50 +01:00
1 parent 9597058ecc
commit 43e9e66bf2
3 files changed
+37 -25

No files matched your search

+20 -8
View File
@@ -142,7 +142,7 @@ function EID:addCollectible(id, description, itemName, language)
itemName = itemName or nil itemName = itemName or nil
language = language or "en_us" language = language or "en_us"
if id == -1 then if id == -1 then
print("EID Error: Trying to add collectible description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")") EID:WriteErrorMsg("Trying to add collectible description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")")
return return
end end
local modName = EID._currentMod local modName = EID._currentMod
@@ -161,7 +161,7 @@ function EID:addTrinket(id, description, itemName, language)
itemName = itemName or nil itemName = itemName or nil
language = language or "en_us" language = language or "en_us"
if id == -1 then if id == -1 then
print("EID Error: Trying to add trinket description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")") EID:WriteErrorMsg("Trying to add trinket description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")")
return return
end end
EID:CreateDescriptionTableIfMissing("custom", language) EID:CreateDescriptionTableIfMissing("custom", language)
@@ -177,7 +177,7 @@ function EID:addCharacterInfo(characterId, description, playerName, language)
playerName = playerName or "Modded Character" playerName = playerName or "Modded Character"
language = language or "en_us" language = language or "en_us"
if characterId == -1 then if characterId == -1 then
print("EID Error: Trying to add character description to id = -1, which is not allowed! (Name: "..tostring(playerName).."; Description: "..tostring(description)..")") EID:WriteErrorMsg("Trying to add character description to id = -1, which is not allowed! (Name: "..tostring(playerName).."; Description: "..tostring(description)..")")
return return
end end
EID:CreateDescriptionTableIfMissing("CharacterInfo", language) EID:CreateDescriptionTableIfMissing("CharacterInfo", language)
@@ -229,7 +229,7 @@ function EID:addCard(id, description, itemName, language)
itemName = itemName or nil itemName = itemName or nil
language = language or "en_us" language = language or "en_us"
if id == -1 then if id == -1 then
print("EID Error: Trying to add card description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")") EID:WriteErrorMsg("Trying to add card description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")")
return return
end end
EID:CreateDescriptionTableIfMissing("custom", language) EID:CreateDescriptionTableIfMissing("custom", language)
@@ -259,7 +259,7 @@ function EID:addPill(id, description, itemName, language)
itemName = itemName or nil itemName = itemName or nil
language = language or "en_us" language = language or "en_us"
if id == -1 then if id == -1 then
print("EID Error: Trying to add pill description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")") EID:WriteErrorMsg("Trying to add pill description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")")
return return
end end
EID:CreateDescriptionTableIfMissing("pills", language) EID:CreateDescriptionTableIfMissing("pills", language)
@@ -281,7 +281,7 @@ function EID:addHorsePill(id, description, itemName, language)
itemName = itemName or nil itemName = itemName or nil
language = language or "en_us" language = language or "en_us"
if id == -1 then if id == -1 then
print("EID Error: Trying to add horsepill description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")") EID:WriteErrorMsg("Trying to add horsepill description to id = -1, which is not allowed! (Name: "..tostring(itemName).."; Description: "..tostring(description)..")")
return return
end end
EID:CreateDescriptionTableIfMissing("horsepills", language) EID:CreateDescriptionTableIfMissing("horsepills", language)
@@ -308,7 +308,7 @@ function EID:addBirthright(characterId, description, playerName, language)
playerName = playerName or nil playerName = playerName or nil
language = language or "en_us" language = language or "en_us"
if characterId == -1 then if characterId == -1 then
print("EID Error: Trying to add Birthright description to id = -1, which is not allowed! (Name: "..tostring(characterId).."; Description: "..tostring(description)..")") EID:WriteErrorMsg("Trying to add Birthright description to id = -1, which is not allowed! (Name: "..tostring(characterId).."; Description: "..tostring(description)..")")
return return
end end
EID:CreateDescriptionTableIfMissing("birthright", language) EID:CreateDescriptionTableIfMissing("birthright", language)
@@ -557,7 +557,7 @@ function EID:loadFont(fontFileName)
EID.font:SetMissingCharacter(2) EID.font:SetMissingCharacter(2)
---@diagnostic enable ---@diagnostic enable
if not EID.font:IsLoaded() then if not EID.font:IsLoaded() then
Isaac.DebugString("EID - ERROR: Could not load font from '" .. EID.modPath .. "resources/font/default.fnt" .. "'") EID:WriteErrorMsg("Could not load font from '" .. EID.modPath .. "resources/font/default.fnt" .. "'")
return false return false
end end
return true return true
@@ -3179,3 +3179,15 @@ function EID:HasPathToPosition(startPos, endPos)
-- return true if it has a path -- return true if it has a path
return pathfinderObj:GetPath() ~= nil return pathfinderObj:GetPath() ~= nil
end end
---Prints a message in both the console and the Log file, to make important messages from EID stand out everywhere
---@param str string
function EID:WriteDebugMsg(str)
print(str)
Isaac.DebugString(str)
end
---Prints an error message in both the console and the Log file, to make important messages from EID stand out everywhere
---@param str string
function EID:WriteErrorMsg(str)
EID:WriteDebugMsg("EID ERROR: " .. str)
end
+8 -8
View File
@@ -17,7 +17,7 @@ function EID:countEntries(t)
end end
EID:countEntries(EID.descriptions["en_us"]) EID:countEntries(EID.descriptions["en_us"])
local enUSEntries = count local enUSEntries = count
print("en_us entries: "..enUSEntries) EID:WriteDebugMsg("en_us entries: "..enUSEntries)
local maxChecklimit = {["tarotClothBuffs"] = 2} local maxChecklimit = {["tarotClothBuffs"] = 2}
@@ -34,7 +34,7 @@ local ignoreNodesWithName = {["fonts"] = true}
for _, lang in ipairs(languageFilesToCheck) do for _, lang in ipairs(languageFilesToCheck) do
print("Now checking integrity of languagefile: " .. lang) EID:WriteDebugMsg("Now checking integrity of languagefile: " .. lang)
-- Generic function to compare two tables -- Generic function to compare two tables
function EID:compareTables(table1, table2, prevKey, progress) function EID:compareTables(table1, table2, prevKey, progress)
local checkLimit = EID:getMaxCheckLimit(prevKey) local checkLimit = EID:getMaxCheckLimit(prevKey)
@@ -44,10 +44,10 @@ for _, lang in ipairs(languageFilesToCheck) do
if not (ignoreNodesWithName[k] or checkLimit < 0) then if not (ignoreNodesWithName[k] or checkLimit < 0) then
-- only evaluate nodes that are not listed in this table -- only evaluate nodes that are not listed in this table
if not table2[k] then if not table2[k] then
print(" Table '" .. prevKey .. "' does not contain key: " .. k) EID:WriteDebugMsg(" Table '" .. prevKey .. "' does not contain key: " .. k)
progress[2] = progress[2] + 1 progress[2] = progress[2] + 1
elseif type(table2[k]) ~= type(table1[k]) then elseif type(table2[k]) ~= type(table1[k]) then
-- print("Type mismatch in table '" .. prevKey .. "', key: " .. k) -- EID:WriteDebugMsg("Type mismatch in table '" .. prevKey .. "', key: " .. k)
progress[2] = progress[2] + 1 progress[2] = progress[2] + 1
elseif type(table2[k]) == "table" then elseif type(table2[k]) == "table" then
EID:compareTables(table1[k], table2[k], prevKey.."->"..k, progress) EID:compareTables(table1[k], table2[k], prevKey.."->"..k, progress)
@@ -59,7 +59,7 @@ for _, lang in ipairs(languageFilesToCheck) do
local filteredSpriteText, spriteTable = EID:filterIconMarkup(textPart[1]) local filteredSpriteText, spriteTable = EID:filterIconMarkup(textPart[1])
if string.find(filteredSpriteText, "{{") or string.find(filteredSpriteText, "}}") then if string.find(filteredSpriteText, "{{") or string.find(filteredSpriteText, "}}") then
print(" Table '" .. EID:WriteDebugMsg(" Table '" ..
prevKey .. "' entry '" .. k .. "' does contain a broken markup object: '" .. table2[k]) prevKey .. "' entry '" .. k .. "' does contain a broken markup object: '" .. table2[k])
progress[1] = progress[1] - 2 progress[1] = progress[1] - 2
progress[2] = progress[2] + 1 progress[2] = progress[2] + 1
@@ -67,7 +67,7 @@ for _, lang in ipairs(languageFilesToCheck) do
else else
for _, sprite in ipairs(spriteTable) do for _, sprite in ipairs(spriteTable) do
if sprite[1][1] == "ERROR" then if sprite[1][1] == "ERROR" then
print(" Table '" .. EID:WriteDebugMsg(" Table '" ..
prevKey .. prevKey ..
"' entry '" .. k .. "' does contain a bad icon markup in string: '" .. table2[k]) "' entry '" .. k .. "' does contain a bad icon markup in string: '" .. table2[k])
progress[1] = progress[1] - 2 progress[1] = progress[1] - 2
@@ -86,8 +86,8 @@ for _, lang in ipairs(languageFilesToCheck) do
EID:compareTables(EID.descriptions["en_us"], EID.descriptions[lang], lang, progress) EID:compareTables(EID.descriptions["en_us"], EID.descriptions[lang], lang, progress)
local errors = (enUSEntries - progress[1])-progress[2] local errors = (enUSEntries - progress[1])-progress[2]
print("Errors found: "..errors .." / "..enUSEntries) EID:WriteDebugMsg("Errors found: "..errors .." / "..enUSEntries)
print("Translation progress: "..((enUSEntries-errors)/enUSEntries*100).."%") EID:WriteDebugMsg("Translation progress: "..((enUSEntries-errors)/enUSEntries*100).."%")
end end
+9 -9
View File
@@ -1,4 +1,4 @@
if EID and EID.Name then print("Error: Two instances of EID found! Please uninstall one of them!") return end -- If EID is already loaded, warn the user and dont load the second one. if EID and EID.Name then print("EID Error: Two instances of EID found! Please uninstall one of them!") return end -- If EID is already loaded, warn the user and dont load the second one.
EID = RegisterMod("External Item Descriptions", 1) EID = RegisterMod("External Item Descriptions", 1)
-- important variables -- important variables
EID.GameVersion = "ab+" EID.GameVersion = "ab+"
@@ -129,7 +129,7 @@ if EID.isRepentance then
for _,lang in ipairs(EID.Languages) do for _,lang in ipairs(EID.Languages) do
local wasSuccessful, err = pcall(require,"descriptions."..EID.GameVersion.."."..lang) local wasSuccessful, err = pcall(require,"descriptions."..EID.GameVersion.."."..lang)
if not wasSuccessful and not string.find(err, "not found") then if not wasSuccessful and not string.find(err, "not found") then
Isaac.ConsoleOutput("Load rep "..lang.." failed: "..tostring(err)) EID:WriteErrorMsg("Load rep "..lang.." failed: "..tostring(err))
end end
end end
local _, _ = pcall(require,"descriptions."..EID.GameVersion..".transformations") local _, _ = pcall(require,"descriptions."..EID.GameVersion..".transformations")
@@ -142,7 +142,7 @@ if EID.isRepentance then
for _,lang in ipairs(EID.Languages) do for _,lang in ipairs(EID.Languages) do
local wasSuccessful, err = pcall(require,"descriptions."..EID.GameVersion.."."..lang) local wasSuccessful, err = pcall(require,"descriptions."..EID.GameVersion.."."..lang)
if not wasSuccessful and not string.find(err, "not found") then if not wasSuccessful and not string.find(err, "not found") then
Isaac.ConsoleOutput("Load rep+ "..lang.." failed: "..tostring(err)) EID:WriteErrorMsg("Load rep+ "..lang.." failed: "..tostring(err))
end end
end end
local _, _ = pcall(require,"descriptions."..EID.GameVersion..".transformations") local _, _ = pcall(require,"descriptions."..EID.GameVersion..".transformations")
@@ -182,16 +182,16 @@ if not success then
if EID.isRepentance then if EID.isRepentance then
success = EID:loadFont("../mods/"..modfolder.."/resources/font/eid_"..fontFile..".fnt") success = EID:loadFont("../mods/"..modfolder.."/resources/font/eid_"..fontFile..".fnt")
if not success then if not success then
Isaac.ConsoleOutput("EID WAS NOT ABLE TO LOAD THE FONT!!!!!!!! Please contact the mod creator!\n") EID:WriteErrorMsg("EID WAS NOT ABLE TO LOAD THE FONT!!!!!!!! Please contact the mod creator!\n")
Isaac.ConsoleOutput("File not found (absolute path): "..EID.modPath .. "resources/font/eid_"..fontFile..".fnt\n") EID:WriteErrorMsg("File not found (absolute path): "..EID.modPath .. "resources/font/eid_"..fontFile..".fnt\n")
Isaac.ConsoleOutput("File not found (relative path): ../mods/"..modfolder.."/resources/font/eid_"..fontFile..".fnt") EID:WriteErrorMsg("File not found (relative path): ../mods/"..modfolder.."/resources/font/eid_"..fontFile..".fnt")
return return
else else
EID.modPath = "../mods/"..modfolder.."/" EID.modPath = "../mods/"..modfolder.."/"
end end
else else
Isaac.ConsoleOutput("EID WAS NOT ABLE TO LOAD THE FONT!!!!!!!! Please contact the mod creator!\n") EID:WriteErrorMsg("EID WAS NOT ABLE TO LOAD THE FONT!!!!!!!! Please contact the mod creator!\n")
Isaac.ConsoleOutput("File does not exist: "..EID.modPath .. "resources/font/eid_"..fontFile..".fnt") EID:WriteErrorMsg("File does not exist: "..EID.modPath .. "resources/font/eid_"..fontFile..".fnt")
return return
end end
end end
@@ -1871,7 +1871,7 @@ function EID:OnGameStart(isSave)
local isDefaultConfig = true local isDefaultConfig = true
for key, value in pairs(EID.Config) do for key, value in pairs(EID.Config) do
if type(value) ~= type(EID.DefaultConfig[key]) and not configIgnoreList[key] then if type(value) ~= type(EID.DefaultConfig[key]) and not configIgnoreList[key] then
print("EID Warning! : Config value '"..key.."' has wrong data-type. Resetting it to default...") EID:WriteDebugMsg("EID Warning: Config value '"..key.."' has wrong data-type. Resetting it to default...")
EID.Config[key] = EID.DefaultConfig[key] EID.Config[key] = EID.DefaultConfig[key]
end end
if EID.DefaultConfig[key] ~= value then if EID.DefaultConfig[key] ~= value then