From 7bede51e7d392a08b504dabefea81eb8785bd877 Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Wed, 17 Jul 2024 19:14:34 +0200 Subject: [PATCH] Changed uses of Entity:GetData() to EID:get/setEntityData() --- features/eid_api.lua | 8 +++++++- main.lua | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/features/eid_api.lua b/features/eid_api.lua index 7ab8a58a..c0836561 100644 --- a/features/eid_api.lua +++ b/features/eid_api.lua @@ -700,7 +700,7 @@ function EID:hasDescription(entity) if EID.Config["EnableEntityDescriptions"] and EID:getTableName(entity.Type, entity.Variant, entity.SubType) == "custom" then isAllowed = __eidEntityDescriptions[entityString] ~= nil isAllowed = isAllowed or EID:getDescriptionData(entity.Type, entity.Variant, entity.SubType) ~= nil - isAllowed = isAllowed or entity:GetData() and type(entity:GetData()["EID_Description"]) ~= type(nil) + isAllowed = isAllowed or EID:getEntityData(entity, "EID_Description") ~= nil end if entity.Type == EntityType.ENTITY_PICKUP then if entity.SubType == 0 and EID:getDescriptionData(entity.Type, entity.Variant, entity.SubType) ~= nil then @@ -1633,6 +1633,12 @@ function EID:getEntityData(entity, str) return nil end +function EID:setEntityData(entity, str, value) + if EID:EntitySanityCheck(entity) and not EID:IsGridEntity(entity) and entity:GetData() ~= nil then + entity:GetData()[str] = value + end +end + -- Function to fix font compatibility. Resets config font to a value compatible with your current language function EID:fixDefinedFont(forceRefresh) local curLang = EID:getLanguage() diff --git a/main.lua b/main.lua index efdb174c..0f5f104c 100644 --- a/main.lua +++ b/main.lua @@ -329,7 +329,7 @@ if EID.isRepentance then -- Give this new entity its Flip Item data if possible local flipEntry = EID.flipItemPositions[curRoomIndex] and EID.flipItemPositions[curRoomIndex][entity.InitSeed] if flipEntry then - entity:GetData()["EID_FlipItemID"] = flipEntry[1] + EID:setEntityData(entity, "EID_FlipItemID", flipEntry[1]) end end EID:AddCallback(ModCallbacks.MC_POST_PICKUP_INIT, EID.postPickupInitFlip, PickupVariant.PICKUP_COLLECTIBLE) @@ -337,13 +337,13 @@ if EID.isRepentance then function EID:CheckPedestalIndex(entity) -- Only pedestals with indexes that were present at room load can be flip pedestals -- Fixes shop restock machines and Diplopia... mostly. At least while you're in the room. - if entity:GetData()["EID_FlipItemID"] and entity.Index > EID.flipMaxIndex then + if EID:getEntityData(entity, "EID_FlipItemID") and entity.Index > EID.flipMaxIndex then local curRoomIndex = game:GetLevel():GetCurrentRoomDesc().ListIndex local gridPos = game:GetRoom():GetGridIndex(entity.Position) local flipEntry = EID.flipItemPositions[curRoomIndex] and EID.flipItemPositions[curRoomIndex][entity.InitSeed] -- only wipe the data if the grid index matches (so Diplopia pedestals don't) if flipEntry and gridPos == flipEntry[2] then EID.flipItemPositions[curRoomIndex][entity.InitSeed] = nil end - entity:GetData()["EID_FlipItemID"] = nil + EID:setEntityData(entity, "EID_FlipItemID", nil) end end EID:AddCallback(ModCallbacks.MC_POST_PICKUP_UPDATE, EID.CheckPedestalIndex, PickupVariant.PICKUP_COLLECTIBLE) @@ -756,7 +756,7 @@ if EID.isRepentance then local flipEntry = EID.flipItemPositions[curRoomIndex][pedestal.InitSeed] if flipEntry then if pedestal.Index > EID.flipMaxIndex then EID.flipMaxIndex = pedestal.Index end - pedestal:GetData()["EID_FlipItemID"] = flipEntry[1] + EID:setEntityData(pedestal, "EID_FlipItemID", flipEntry[1]) end end end @@ -865,9 +865,8 @@ function EID:renderIndicator(entity, playerNum) ArrowOffset = Vector(0, -62) end local arrowPos = Isaac.WorldToScreen(entity.Position + ArrowOffset) - if not EID:IsGridEntity(entity) and entity:GetData() and entity:GetData()["EID_RenderOffset"] then - entityPos = entityPos + entity:GetData()["EID_RenderOffset"] - end + entityPos = entityPos + (EID:getEntityData(entity, "EID_RenderOffset") or Vector(0,0)) + -- Move highlights a bit to fit onto the alt Item layout of Flip / Tainted Laz if EID.isRepentance and not EID:IsGridEntity(entity) then if entity.Variant == 100 and EID:PlayersHaveCollectible(CollectibleType.COLLECTIBLE_FLIP) and EID:getEntityData(entity, "EID_FlipItemID") then @@ -1067,13 +1066,13 @@ function EID:onGameUpdate() local curPositions = {} for _, entity in ipairs(Isaac.FindByType(5, 100, -1, true, false)) do -- Flag pedestals as being describable on frame 0 (for Tainted Isaac / Glitched Crown type pedestals to not be non-existent for a frame) - entity:GetData()["EID_DescribeOnFirstFrame"] = true + EID:setEntityData(entity, "EID_DescribeOnFirstFrame", true) -- Fix Overlapping Pedestals if a collectible spawned this frame (needed for Mega Chest) local pos = entity.Position for _, otherPos in ipairs(curPositions) do if pos:Distance(otherPos[2]) == 0 then - entity:GetData()["EID_RenderOffset"] = Vector(10,0) - otherPos[1]:GetData()["EID_RenderOffset"] = Vector(-10,0) + EID:setEntityData(entity, "EID_RenderOffset", Vector(10,0)) + EID:setEntityData(otherPos[1], "EID_RenderOffset", Vector(-10,0)) end end table.insert(curPositions, {entity, entity.Position}) @@ -1135,7 +1134,7 @@ local function attemptPathfind(entity) -- Spawn a Fireplace entity to attempt a pathfind to the target pickup, then remove it afterwards pathCheckerEntity = game:Spawn(33, 0, EID.player.Position, nullVector, EID.player, 6969, 4354) - pathCheckerEntity:GetData()["EID_Pathfinder"] = true + EID:setEntityData(pathCheckerEntity, "EID_Pathfinder", true) pathCheckerEntity.Visible = false local successful = pathCheckerEntity:ToNPC().Pathfinder:HasPathToPos(entity.Position, false) pathsChecked[entity.InitSeed] = successful @@ -1404,12 +1403,13 @@ function EID:OnRender() for _, entitySearch in ipairs(searchGroups) do for _, entity in ipairs(entitySearch) do - if EID:hasDescription(entity) and (entity.FrameCount > 0 or entity:GetData()["EID_DescribeOnFirstFrame"]) and not EID.entitiesToPrint[GetPtrHash(entity)] then + if EID:hasDescription(entity) and (entity.FrameCount > 0 or EID:getEntityData(entity, "EID_DescribeOnFirstFrame")) and not EID.entitiesToPrint[GetPtrHash(entity)] then table.insert(inRangeEntities, entity) local diff = entity.Position:__sub(sourcePos) -- break ties with the render offset (for Mega Chest double collectibles) - if diff:Length() == EID.lastDist and entity:GetData()["EID_RenderOffset"] then - diff = diff + entity:GetData()["EID_RenderOffset"] + local entityDataRenderOffset = EID:getEntityData(entity, "EID_RenderOffset") + if diff:Length() == EID.lastDist and entityDataRenderOffset then + diff = diff + entityDataRenderOffset end if diff:Length() < EID.lastDist then EID.lastDescriptionEntity = entity