Small code improvements and removal of unused variables
This commit is contained in:
1 parent
2a61a8ce09
commit
6af9ed6fd6
4 files changed
+35
-44
No files matched your search
+12
-15
@@ -321,10 +321,9 @@ function EID:getDescriptionObj(Type, Variant, SubType, entity)
|
||||
|
||||
description.Transformation = EID:getTransformation(Type, Variant, SubType)
|
||||
|
||||
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
|
||||
description = modifier.callback(description)
|
||||
end
|
||||
@@ -733,7 +732,6 @@ function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
|
||||
-- utf8 word (sequence): 0x11xxxxxx 0x10xxxxxx 0x10xxxxxx ... 0x10xxxxxx
|
||||
-- see https://en.wikipedia.org/wiki/UTF-8
|
||||
-- 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)
|
||||
if
|
||||
-- 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)
|
||||
local textPartsTable = EID:filterColorMarkup(str, kcolor)
|
||||
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)
|
||||
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)
|
||||
@@ -881,11 +879,10 @@ end
|
||||
local itemConfigItemAttributes = { "AddMaxHearts", "AddHearts", "AddSoulHearts", "AddBlackHearts", "AddBombs", "AddCoins", "AddKeys", "CacheFlags" }
|
||||
function EID:CheckGlitchedItemConfig(id)
|
||||
local localizedNames = EID:getDescriptionEntry("GlitchedItemText")
|
||||
local config = Isaac.GetItemConfig()
|
||||
local item = config:GetCollectible(id)
|
||||
local item = EID.itemConfig:GetCollectible(id)
|
||||
if not item then return "" end
|
||||
local attributes = ""
|
||||
for k,v in ipairs(itemConfigItemAttributes) do
|
||||
for _,v in ipairs(itemConfigItemAttributes) do
|
||||
local val = item[v]
|
||||
if val ~= 0 then
|
||||
if (v == "CacheFlags") then
|
||||
@@ -958,7 +955,7 @@ function EID:DetectModdedItems()
|
||||
end
|
||||
|
||||
function EID:isCollectibleUnlocked(collectibleID, itemPoolOfItem)
|
||||
local itemPool = Game():GetItemPool()
|
||||
local itemPool = game:GetItemPool()
|
||||
if maxCollectibleID == nil then maxCollectibleID = EID:GetMaxCollectibleID() end
|
||||
for i= 1, maxCollectibleID do
|
||||
if ItemConfig.Config.IsValidCollectible(i) and i ~= collectibleID then
|
||||
@@ -966,7 +963,7 @@ function EID:isCollectibleUnlocked(collectibleID, itemPoolOfItem)
|
||||
end
|
||||
end
|
||||
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)
|
||||
if collID == collectibleID then
|
||||
isUnlocked = true
|
||||
@@ -995,7 +992,7 @@ function EID:isCollectibleUnlockedAnyPool(collectibleID)
|
||||
return false
|
||||
end
|
||||
--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
|
||||
EID.itemUnlockStates[collectibleID] = true
|
||||
return true
|
||||
@@ -1013,14 +1010,14 @@ end
|
||||
-- Example input: {1,2,3,4,5,6,7,8}
|
||||
-- Result: "{{Crafting1}}{{Crafting2}}{{Crafting3}}{{Crafting4}}{{Crafting5}}{{Crafting6}}{{Crafting7}}{{Crafting8}}"
|
||||
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)
|
||||
local sortedList = {table.unpack(craftTable)}
|
||||
table.sort(sortedList, function(a, b) return a < b end)
|
||||
local visitedItemCount = {table.unpack(emptyPickupTable)}
|
||||
|
||||
local iconString = ""
|
||||
for _,nr in ipairs(sortedList) do
|
||||
for _, nr in ipairs(sortedList) do
|
||||
visitedItemCount[nr] = visitedItemCount[nr] + 1
|
||||
local completedColoring = indicateCompleteContent and EID:bagContainsItem(nr, visitedItemCount[nr], false) and "{{IconGreenTint}}" or ""
|
||||
iconString = iconString..completedColoring.."{{Crafting"..nr.."}}"
|
||||
@@ -1034,11 +1031,11 @@ end
|
||||
function EID:tableToCraftingIconsMerged(craftTable, indicateCompleteContent)
|
||||
local sortedList = {table.unpack(craftTable)}
|
||||
local filteredList = {table.unpack(emptyPickupTable)}
|
||||
for _,nr in ipairs(sortedList) do
|
||||
for _, nr in ipairs(sortedList) do
|
||||
filteredList[nr] = filteredList[nr] + 1
|
||||
end
|
||||
local iconString = ""
|
||||
for nr,count in ipairs(filteredList) do
|
||||
for nr, count in ipairs(filteredList) do
|
||||
if (count > 0) then
|
||||
local completedColoring = indicateCompleteContent and EID:bagContainsItem(nr, count, true) and "{{ColorBagComplete}}" or ""
|
||||
iconString = iconString..completedColoring..count.."{{Crafting"..nr.."}}{{CR}}"
|
||||
@@ -1085,7 +1082,7 @@ end
|
||||
|
||||
function EID:getScreenSize()
|
||||
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 ry = pos.Y + 140 * (26 / 40)
|
||||
|
||||
+21
-25
@@ -85,7 +85,7 @@ local pickupIDLookup = {
|
||||
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
|
||||
--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
|
||||
|
||||
local componentShifts = {
|
||||
@@ -256,27 +256,24 @@ function EID:simulateBagOfCrafting(componentsTable)
|
||||
end
|
||||
|
||||
local poolWeights = {
|
||||
{idx = 0, weight = 1},
|
||||
{idx = 1, weight = 2},
|
||||
{idx = 2, weight = 2},
|
||||
{idx = 3, weight = compCounts[4] * 10},
|
||||
{idx = 4, weight = compCounts[5] * 10},
|
||||
{idx = 5, weight = compCounts[7] * 5},
|
||||
{idx = 7, weight = compCounts[30] * 10},
|
||||
{idx = 8, weight = compCounts[6] * 10},
|
||||
{idx = 9, weight = compCounts[26] * 10},
|
||||
{idx = 12, weight = compCounts[8] * 10},
|
||||
{idx = 0, weight = 1, totalWeight = 0},
|
||||
{idx = 1, weight = 2, totalWeight = 0},
|
||||
{idx = 2, weight = 2, totalWeight = 0},
|
||||
{idx = 3, weight = compCounts[4] * 10, totalWeight = 0},
|
||||
{idx = 4, weight = compCounts[5] * 10, totalWeight = 0},
|
||||
{idx = 5, weight = compCounts[7] * 5, totalWeight = 0},
|
||||
{idx = 7, weight = compCounts[30] * 10, totalWeight = 0},
|
||||
{idx = 8, weight = compCounts[6] * 10, totalWeight = 0},
|
||||
{idx = 9, weight = compCounts[26] * 10, totalWeight = 0},
|
||||
{idx = 12, weight = compCounts[8] * 10}, totalWeight = 0,
|
||||
}
|
||||
if compCounts[9] + compCounts[2] + compCounts[13] + compCounts[16] == 0 then
|
||||
table.insert(poolWeights, {idx = 26, weight = compCounts[24] * 10})
|
||||
end
|
||||
|
||||
for k,v in ipairs(poolWeights) do
|
||||
v.totalWeight = 0
|
||||
end
|
||||
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
|
||||
if poolWeight.weight > 0 then
|
||||
@@ -326,7 +323,7 @@ function EID:simulateBagOfCrafting(componentsTable)
|
||||
--line break after boss pool
|
||||
if (firstAfterBoss) then poolString = poolString .. " " end
|
||||
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
|
||||
poolString = string.sub(poolString,1,-2) .. "#"
|
||||
@@ -656,7 +653,6 @@ EID.bagOfCraftingRoomQueries = {}
|
||||
EID.bagOfCraftingFloorQuery = {}
|
||||
EID.BagItems = {}
|
||||
|
||||
local icount = 0
|
||||
local bagOfCraftingOffset = 0
|
||||
local lockedResults = nil
|
||||
local refreshNextTick = false
|
||||
@@ -863,7 +859,7 @@ function EID:handleBagOfCraftingRendering()
|
||||
local pickups = Isaac.FindByType(5, -1, -1, true, false)
|
||||
|
||||
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)
|
||||
if craftingIDs ~= nil and not entity:ToPickup():IsShopItem() then
|
||||
for _,v in ipairs(craftingIDs) do
|
||||
@@ -882,7 +878,7 @@ function EID:handleBagOfCraftingRendering()
|
||||
local itemCount = {}
|
||||
|
||||
--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
|
||||
table.insert(itemQuery, v)
|
||||
if (not itemCount[v]) then itemCount[v] = 1
|
||||
@@ -890,7 +886,7 @@ function EID:handleBagOfCraftingRendering()
|
||||
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
|
||||
table.insert(itemQuery, v)
|
||||
if (not itemCount[v]) then itemCount[v] = 1
|
||||
@@ -998,12 +994,12 @@ function EID:handleBagOfCraftingRendering()
|
||||
if (calcResultCache[queryString]) then
|
||||
sortedResults = calcResultCache[queryString]
|
||||
else
|
||||
for k, v in ipairs(sortedIDs) do
|
||||
for _, v in ipairs(sortedIDs) do
|
||||
sortedResults[v] = {}
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs(newResults) do
|
||||
for _, v in pairs(newResults) do
|
||||
local resultID, lockedAchievementID = EID:calculateBagOfCrafting(v)
|
||||
if resultID ~= lockedAchievementID then
|
||||
table.insert(sortedResults[resultID], {v, resultID, lockedAchievementID})
|
||||
@@ -1016,7 +1012,7 @@ function EID:handleBagOfCraftingRendering()
|
||||
results = sortedResults
|
||||
|
||||
numResults = 0
|
||||
for k,v in ipairs(sortedIDs) do
|
||||
for _,v in ipairs(sortedIDs) do
|
||||
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
|
||||
bagOfCraftingOffset = numResults
|
||||
@@ -1097,11 +1093,11 @@ function EID:handleBagOfCraftingRendering()
|
||||
end
|
||||
local curOffset = 0
|
||||
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]
|
||||
else
|
||||
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
|
||||
if (curOffset > bagOfCraftingOffset+EID.Config["BagOfCraftingResults"]) then break end
|
||||
if not v then break end
|
||||
|
||||
+1
-3
@@ -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
|
||||
-- (Should work well for Corrupted Data)
|
||||
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 itemScore = 0
|
||||
local eidDesc = ""
|
||||
|
||||
local theLog = io.open(logLocation, "r")
|
||||
@@ -114,7 +113,6 @@ local function CheckLogForItems(_)
|
||||
local line = theLog:read()
|
||||
while line ~= nil do
|
||||
if string.find(line, "initialized with") then
|
||||
local count = 0
|
||||
spawnedItems = spawnedItems + 1
|
||||
lastEffectTrigger = "chain"
|
||||
eidDesc = ""
|
||||
|
||||
@@ -888,7 +888,7 @@ local function renderAchievementInfo()
|
||||
hasShownAchievementWarning = true
|
||||
else
|
||||
-- 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)
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user