Small code improvements and removal of unused variables

This commit is contained in:
Wofsauge committed 2022-01-21 00:05:51 +01:00
1 parent 2a61a8ce09
commit 6af9ed6fd6
4 files changed
+35 -44

No files matched your search

+12 -15
View File
@@ -321,10 +321,9 @@ function EID:getDescriptionObj(Type, Variant, SubType, entity)
description.Transformation = EID:getTransformation(Type, Variant, SubType) description.Transformation = EID:getTransformation(Type, Variant, SubType)
description.ModName = tableEntry and tableEntry[4]
description.ModName = tableEntry and tableEntry[4] description.ModName = tableEntry and tableEntry[4]
for k,modifier in pairs(EID.DescModifiers) do for _, modifier in pairs(EID.DescModifiers) do
if modifier.condition(description) then if modifier.condition(description) then
description = modifier.callback(description) description = modifier.callback(description)
end end
@@ -733,7 +732,6 @@ function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
-- utf8 word (sequence): 0x11xxxxxx 0x10xxxxxx 0x10xxxxxx ... 0x10xxxxxx -- utf8 word (sequence): 0x11xxxxxx 0x10xxxxxx 0x10xxxxxx ... 0x10xxxxxx
-- see https://en.wikipedia.org/wiki/UTF-8 -- see https://en.wikipedia.org/wiki/UTF-8
-- we can only break after space, or before 0x11xxxxxx -- we can only break after space, or before 0x11xxxxxx
local can_break_after_cursor = false
local cur, next = byte(str,cursor), byte(str,cursor+1) local cur, next = byte(str,cursor), byte(str,cursor+1)
if if
-- cond#1: we can break at the end of string -- cond#1: we can break at the end of string
@@ -824,7 +822,7 @@ function EID:renderString(str, position, scale, kcolor)
str = EID:replaceShortMarkupStrings(str) str = EID:replaceShortMarkupStrings(str)
local textPartsTable = EID:filterColorMarkup(str, kcolor) local textPartsTable = EID:filterColorMarkup(str, kcolor)
local offsetX = 0 local offsetX = 0
for i, textPart in ipairs(textPartsTable) do for _, textPart in ipairs(textPartsTable) do
local strFiltered, spriteTable = EID:filterIconMarkup(textPart[1], position.X, position.Y) local strFiltered, spriteTable = EID:filterIconMarkup(textPart[1], position.X, position.Y)
EID:renderInlineIcons(spriteTable, position.X + offsetX, position.Y) EID:renderInlineIcons(spriteTable, position.X + offsetX, position.Y)
EID.font:DrawStringScaledUTF8(strFiltered, position.X + offsetX, position.Y, scale.X, scale.Y, textPart[2], 0, false) EID.font:DrawStringScaledUTF8(strFiltered, position.X + offsetX, position.Y, scale.X, scale.Y, textPart[2], 0, false)
@@ -881,11 +879,10 @@ end
local itemConfigItemAttributes = { "AddMaxHearts", "AddHearts", "AddSoulHearts", "AddBlackHearts", "AddBombs", "AddCoins", "AddKeys", "CacheFlags" } local itemConfigItemAttributes = { "AddMaxHearts", "AddHearts", "AddSoulHearts", "AddBlackHearts", "AddBombs", "AddCoins", "AddKeys", "CacheFlags" }
function EID:CheckGlitchedItemConfig(id) function EID:CheckGlitchedItemConfig(id)
local localizedNames = EID:getDescriptionEntry("GlitchedItemText") local localizedNames = EID:getDescriptionEntry("GlitchedItemText")
local config = Isaac.GetItemConfig() local item = EID.itemConfig:GetCollectible(id)
local item = config:GetCollectible(id)
if not item then return "" end if not item then return "" end
local attributes = "" local attributes = ""
for k,v in ipairs(itemConfigItemAttributes) do for _,v in ipairs(itemConfigItemAttributes) do
local val = item[v] local val = item[v]
if val ~= 0 then if val ~= 0 then
if (v == "CacheFlags") then if (v == "CacheFlags") then
@@ -958,7 +955,7 @@ function EID:DetectModdedItems()
end end
function EID:isCollectibleUnlocked(collectibleID, itemPoolOfItem) function EID:isCollectibleUnlocked(collectibleID, itemPoolOfItem)
local itemPool = Game():GetItemPool() local itemPool = game:GetItemPool()
if maxCollectibleID == nil then maxCollectibleID = EID:GetMaxCollectibleID() end if maxCollectibleID == nil then maxCollectibleID = EID:GetMaxCollectibleID() end
for i= 1, maxCollectibleID do for i= 1, maxCollectibleID do
if ItemConfig.Config.IsValidCollectible(i) and i ~= collectibleID then if ItemConfig.Config.IsValidCollectible(i) and i ~= collectibleID then
@@ -966,7 +963,7 @@ function EID:isCollectibleUnlocked(collectibleID, itemPoolOfItem)
end end
end end
local isUnlocked = false local isUnlocked = false
for i = 0,1 do -- some samples to make sure for i = 0, 1 do -- some samples to make sure
local collID = itemPool:GetCollectible(itemPoolOfItem, false, 1) local collID = itemPool:GetCollectible(itemPoolOfItem, false, 1)
if collID == collectibleID then if collID == collectibleID then
isUnlocked = true isUnlocked = true
@@ -995,7 +992,7 @@ function EID:isCollectibleUnlockedAnyPool(collectibleID)
return false return false
end end
--iterate through the pools this item can be in --iterate through the pools this item can be in
for k,itemPoolID in ipairs(EID.XMLItemIsInPools[collectibleID]) do for _,itemPoolID in ipairs(EID.XMLItemIsInPools[collectibleID]) do
if (itemPoolID < ItemPoolType.NUM_ITEMPOOLS and EID:isCollectibleUnlocked(collectibleID, itemPoolID)) then if (itemPoolID < ItemPoolType.NUM_ITEMPOOLS and EID:isCollectibleUnlocked(collectibleID, itemPoolID)) then
EID.itemUnlockStates[collectibleID] = true EID.itemUnlockStates[collectibleID] = true
return true return true
@@ -1013,14 +1010,14 @@ end
-- Example input: {1,2,3,4,5,6,7,8} -- Example input: {1,2,3,4,5,6,7,8}
-- Result: "{{Crafting1}}{{Crafting2}}{{Crafting3}}{{Crafting4}}{{Crafting5}}{{Crafting6}}{{Crafting7}}{{Crafting8}}" -- Result: "{{Crafting1}}{{Crafting2}}{{Crafting3}}{{Crafting4}}{{Crafting5}}{{Crafting6}}{{Crafting7}}{{Crafting8}}"
local emptyPickupTable = {} local emptyPickupTable = {}
for i=1,29 do emptyPickupTable[i] = 0 end for i=1, 29 do emptyPickupTable[i] = 0 end
function EID:tableToCraftingIconsFull(craftTable, indicateCompleteContent) function EID:tableToCraftingIconsFull(craftTable, indicateCompleteContent)
local sortedList = {table.unpack(craftTable)} local sortedList = {table.unpack(craftTable)}
table.sort(sortedList, function(a, b) return a < b end) table.sort(sortedList, function(a, b) return a < b end)
local visitedItemCount = {table.unpack(emptyPickupTable)} local visitedItemCount = {table.unpack(emptyPickupTable)}
local iconString = "" local iconString = ""
for _,nr in ipairs(sortedList) do for _, nr in ipairs(sortedList) do
visitedItemCount[nr] = visitedItemCount[nr] + 1 visitedItemCount[nr] = visitedItemCount[nr] + 1
local completedColoring = indicateCompleteContent and EID:bagContainsItem(nr, visitedItemCount[nr], false) and "{{IconGreenTint}}" or "" local completedColoring = indicateCompleteContent and EID:bagContainsItem(nr, visitedItemCount[nr], false) and "{{IconGreenTint}}" or ""
iconString = iconString..completedColoring.."{{Crafting"..nr.."}}" iconString = iconString..completedColoring.."{{Crafting"..nr.."}}"
@@ -1034,11 +1031,11 @@ end
function EID:tableToCraftingIconsMerged(craftTable, indicateCompleteContent) function EID:tableToCraftingIconsMerged(craftTable, indicateCompleteContent)
local sortedList = {table.unpack(craftTable)} local sortedList = {table.unpack(craftTable)}
local filteredList = {table.unpack(emptyPickupTable)} local filteredList = {table.unpack(emptyPickupTable)}
for _,nr in ipairs(sortedList) do for _, nr in ipairs(sortedList) do
filteredList[nr] = filteredList[nr] + 1 filteredList[nr] = filteredList[nr] + 1
end end
local iconString = "" local iconString = ""
for nr,count in ipairs(filteredList) do for nr, count in ipairs(filteredList) do
if (count > 0) then if (count > 0) then
local completedColoring = indicateCompleteContent and EID:bagContainsItem(nr, count, true) and "{{ColorBagComplete}}" or "" local completedColoring = indicateCompleteContent and EID:bagContainsItem(nr, count, true) and "{{ColorBagComplete}}" or ""
iconString = iconString..completedColoring..count.."{{Crafting"..nr.."}}{{CR}}" iconString = iconString..completedColoring..count.."{{Crafting"..nr.."}}{{CR}}"
@@ -1085,7 +1082,7 @@ end
function EID:getScreenSize() function EID:getScreenSize()
local room = game:GetRoom() local room = game:GetRoom()
local pos = room:WorldToScreenPosition(Vector(0,0)) - room:GetRenderScrollOffset() - Game().ScreenShakeOffset local pos = room:WorldToScreenPosition(Vector(0,0)) - room:GetRenderScrollOffset() - game.ScreenShakeOffset
local rx = pos.X + 60 * 26 / 40 local rx = pos.X + 60 * 26 / 40
local ry = pos.Y + 140 * (26 / 40) local ry = pos.Y + 140 * (26 / 40)
+21 -25
View File
@@ -85,7 +85,7 @@ local pickupIDLookup = {
local function IsTaintedCain() local function IsTaintedCain()
--no clue how the display works for co-op, as far as I can tell we're only caring about player 1 --no clue how the display works for co-op, as far as I can tell we're only caring about player 1
--this check is necessary for some ingredient tracking now that Bag of Crafting is usable by everyone --this check is necessary for some ingredient tracking now that Bag of Crafting is usable by everyone
return game:GetPlayer(0):GetPlayerType() == 23 return EID.player:GetPlayerType() == 23
end end
local componentShifts = { local componentShifts = {
@@ -256,27 +256,24 @@ function EID:simulateBagOfCrafting(componentsTable)
end end
local poolWeights = { local poolWeights = {
{idx = 0, weight = 1}, {idx = 0, weight = 1, totalWeight = 0},
{idx = 1, weight = 2}, {idx = 1, weight = 2, totalWeight = 0},
{idx = 2, weight = 2}, {idx = 2, weight = 2, totalWeight = 0},
{idx = 3, weight = compCounts[4] * 10}, {idx = 3, weight = compCounts[4] * 10, totalWeight = 0},
{idx = 4, weight = compCounts[5] * 10}, {idx = 4, weight = compCounts[5] * 10, totalWeight = 0},
{idx = 5, weight = compCounts[7] * 5}, {idx = 5, weight = compCounts[7] * 5, totalWeight = 0},
{idx = 7, weight = compCounts[30] * 10}, {idx = 7, weight = compCounts[30] * 10, totalWeight = 0},
{idx = 8, weight = compCounts[6] * 10}, {idx = 8, weight = compCounts[6] * 10, totalWeight = 0},
{idx = 9, weight = compCounts[26] * 10}, {idx = 9, weight = compCounts[26] * 10, totalWeight = 0},
{idx = 12, weight = compCounts[8] * 10}, {idx = 12, weight = compCounts[8] * 10}, totalWeight = 0,
} }
if compCounts[9] + compCounts[2] + compCounts[13] + compCounts[16] == 0 then if compCounts[9] + compCounts[2] + compCounts[13] + compCounts[16] == 0 then
table.insert(poolWeights, {idx = 26, weight = compCounts[24] * 10}) table.insert(poolWeights, {idx = 26, weight = compCounts[24] * 10})
end end
for k,v in ipairs(poolWeights) do
v.totalWeight = 0
end
local totalWeight = 0 local totalWeight = 0
local qualityWeights = {[0]=0, 0, 0, 0, 0} local qualityWeights = {[0] = 0, 0, 0, 0, 0}
for _, poolWeight in ipairs(poolWeights) do for _, poolWeight in ipairs(poolWeights) do
if poolWeight.weight > 0 then if poolWeight.weight > 0 then
@@ -326,7 +323,7 @@ function EID:simulateBagOfCrafting(componentsTable)
--line break after boss pool --line break after boss pool
if (firstAfterBoss) then poolString = poolString .. " " end if (firstAfterBoss) then poolString = poolString .. " " end
poolString = poolString .. poolToIcon[v.idx] .. ":" .. math.floor(v.totalWeight/totalWeight*100+0.5) .. "%," poolString = poolString .. poolToIcon[v.idx] .. ":" .. math.floor(v.totalWeight/totalWeight*100+0.5) .. "%,"
if (k == 3) then firstAfterBoss = true else firstAfterBoss = false end firstAfterBoss = (k == 3)
end end
end end
poolString = string.sub(poolString,1,-2) .. "#" poolString = string.sub(poolString,1,-2) .. "#"
@@ -656,7 +653,6 @@ EID.bagOfCraftingRoomQueries = {}
EID.bagOfCraftingFloorQuery = {} EID.bagOfCraftingFloorQuery = {}
EID.BagItems = {} EID.BagItems = {}
local icount = 0
local bagOfCraftingOffset = 0 local bagOfCraftingOffset = 0
local lockedResults = nil local lockedResults = nil
local refreshNextTick = false local refreshNextTick = false
@@ -863,7 +859,7 @@ function EID:handleBagOfCraftingRendering()
local pickups = Isaac.FindByType(5, -1, -1, true, false) local pickups = Isaac.FindByType(5, -1, -1, true, false)
if EID.bagOfCraftingCurPickupCount ~= #pickups then if EID.bagOfCraftingCurPickupCount ~= #pickups then
for i, entity in ipairs(pickups) do for _, entity in ipairs(pickups) do
local craftingIDs = EID:getBagOfCraftingID(entity.Variant, entity.SubType) local craftingIDs = EID:getBagOfCraftingID(entity.Variant, entity.SubType)
if craftingIDs ~= nil and not entity:ToPickup():IsShopItem() then if craftingIDs ~= nil and not entity:ToPickup():IsShopItem() then
for _,v in ipairs(craftingIDs) do for _,v in ipairs(craftingIDs) do
@@ -882,7 +878,7 @@ function EID:handleBagOfCraftingRendering()
local itemCount = {} local itemCount = {}
--max 8 copies of a single item in our list, to avoid repeat recipes --max 8 copies of a single item in our list, to avoid repeat recipes
for i, v in ipairs(EID.bagOfCraftingFloorQuery) do for _, v in ipairs(EID.bagOfCraftingFloorQuery) do
if (not itemCount[v] or itemCount[v] < 8) then if (not itemCount[v] or itemCount[v] < 8) then
table.insert(itemQuery, v) table.insert(itemQuery, v)
if (not itemCount[v]) then itemCount[v] = 1 if (not itemCount[v]) then itemCount[v] = 1
@@ -890,7 +886,7 @@ function EID:handleBagOfCraftingRendering()
end end
end end
for i, v in ipairs(EID.BagItems) do for _, v in ipairs(EID.BagItems) do
if (not itemCount[v] or itemCount[v] < 8) then if (not itemCount[v] or itemCount[v] < 8) then
table.insert(itemQuery, v) table.insert(itemQuery, v)
if (not itemCount[v]) then itemCount[v] = 1 if (not itemCount[v]) then itemCount[v] = 1
@@ -998,12 +994,12 @@ function EID:handleBagOfCraftingRendering()
if (calcResultCache[queryString]) then if (calcResultCache[queryString]) then
sortedResults = calcResultCache[queryString] sortedResults = calcResultCache[queryString]
else else
for k, v in ipairs(sortedIDs) do for _, v in ipairs(sortedIDs) do
sortedResults[v] = {} sortedResults[v] = {}
end end
end end
for k, v in pairs(newResults) do for _, v in pairs(newResults) do
local resultID, lockedAchievementID = EID:calculateBagOfCrafting(v) local resultID, lockedAchievementID = EID:calculateBagOfCrafting(v)
if resultID ~= lockedAchievementID then if resultID ~= lockedAchievementID then
table.insert(sortedResults[resultID], {v, resultID, lockedAchievementID}) table.insert(sortedResults[resultID], {v, resultID, lockedAchievementID})
@@ -1016,7 +1012,7 @@ function EID:handleBagOfCraftingRendering()
results = sortedResults results = sortedResults
numResults = 0 numResults = 0
for k,v in ipairs(sortedIDs) do for _,v in ipairs(sortedIDs) do
if (refreshNextTick and bagOfCraftingOffset > 0 and v == refreshPosition) then if (refreshNextTick and bagOfCraftingOffset > 0 and v == refreshPosition) then
--jump to the item we were looking at before, so you can more easily refresh for variants of recipes --jump to the item we were looking at before, so you can more easily refresh for variants of recipes
bagOfCraftingOffset = numResults bagOfCraftingOffset = numResults
@@ -1097,11 +1093,11 @@ function EID:handleBagOfCraftingRendering()
end end
local curOffset = 0 local curOffset = 0
refreshPosition = -1 refreshPosition = -1
for k,id in ipairs(sortedIDs) do for _,id in ipairs(sortedIDs) do
if (curOffset + #results[id] <= bagOfCraftingOffset) then curOffset = curOffset + #results[id] if (curOffset + #results[id] <= bagOfCraftingOffset) then curOffset = curOffset + #results[id]
else else
if (refreshPosition == -1) then refreshPosition = id end if (refreshPosition == -1) then refreshPosition = id end
for k2, v in ipairs(results[id]) do for _, v in ipairs(results[id]) do
curOffset = curOffset + 1 curOffset = curOffset + 1
if (curOffset > bagOfCraftingOffset+EID.Config["BagOfCraftingResults"]) then break end if (curOffset > bagOfCraftingOffset+EID.Config["BagOfCraftingResults"]) then break end
if not v then break end if not v then break end
+1 -3
View File
@@ -102,10 +102,9 @@ local function CheckLogForItems(_)
-- Check log.txt every 5 frames if there's a collectible we haven't read the data for yet -- Check log.txt every 5 frames if there's a collectible we haven't read the data for yet
-- (Should work well for Corrupted Data) -- (Should work well for Corrupted Data)
if game:GetFrameCount() % 5 ~= 0 or not EID.Config["DisplayGlitchedItemInfo"] or not logFound or if game:GetFrameCount() % 5 ~= 0 or not EID.Config["DisplayGlitchedItemInfo"] or not logFound or
Isaac.GetItemConfig():GetCollectible(maxNumber - spawnedItems - 1) == nil then return end EID.itemConfig:GetCollectible(maxNumber - spawnedItems - 1) == nil then return end
local numEffects = 0 local numEffects = 0
local itemScore = 0
local eidDesc = "" local eidDesc = ""
local theLog = io.open(logLocation, "r") local theLog = io.open(logLocation, "r")
@@ -114,7 +113,6 @@ local function CheckLogForItems(_)
local line = theLog:read() local line = theLog:read()
while line ~= nil do while line ~= nil do
if string.find(line, "initialized with") then if string.find(line, "initialized with") then
local count = 0
spawnedItems = spawnedItems + 1 spawnedItems = spawnedItems + 1
lastEffectTrigger = "chain" lastEffectTrigger = "chain"
eidDesc = "" eidDesc = ""
+1 -1
View File
@@ -888,7 +888,7 @@ local function renderAchievementInfo()
hasShownAchievementWarning = true hasShownAchievementWarning = true
else else
-- Achievements Locked Check (do we have Cube of Meat or Book of Revelations unlocked?) -- Achievements Locked Check (do we have Cube of Meat or Book of Revelations unlocked?)
local characterID = Game():GetPlayer(0):GetPlayerType() local characterID = EID.player:GetPlayerType()
--ID 21 = Tainted Isaac. Tainted characters have definitely beaten Mom! (Fixes Tainted Lost's item pools ruining this check) --ID 21 = Tainted Isaac. Tainted characters have definitely beaten Mom! (Fixes Tainted Lost's item pools ruining this check)
if characterID < 21 and game.Challenge == 0 and not EID:PlayersHaveCollectible(CollectibleType.COLLECTIBLE_TMTRAINER) then if characterID < 21 and game.Challenge == 0 and not EID:PlayersHaveCollectible(CollectibleType.COLLECTIBLE_TMTRAINER) then
local hasBookOfRevelationsUnlocked = EID:isCollectibleUnlockedAnyPool(CollectibleType.COLLECTIBLE_BOOK_OF_REVELATIONS or CollectibleType.COLLECTIBLE_BOOK_REVELATIONS) local hasBookOfRevelationsUnlocked = EID:isCollectibleUnlockedAnyPool(CollectibleType.COLLECTIBLE_BOOK_OF_REVELATIONS or CollectibleType.COLLECTIBLE_BOOK_REVELATIONS)