Changed uses of Entity:GetData() to EID:get/setEntityData()

This commit is contained in:
Wofsauge committed 2024-07-17 19:14:34 +02:00
1 parent 0b6cb9040b
commit 7bede51e7d
2 files changed
+21 -15

No files matched your search

+7 -1
View File
@@ -700,7 +700,7 @@ function EID:hasDescription(entity)
if EID.Config["EnableEntityDescriptions"] and EID:getTableName(entity.Type, entity.Variant, entity.SubType) == "custom" then if EID.Config["EnableEntityDescriptions"] and EID:getTableName(entity.Type, entity.Variant, entity.SubType) == "custom" then
isAllowed = __eidEntityDescriptions[entityString] ~= nil isAllowed = __eidEntityDescriptions[entityString] ~= nil
isAllowed = isAllowed or EID:getDescriptionData(entity.Type, entity.Variant, entity.SubType) ~= 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 end
if entity.Type == EntityType.ENTITY_PICKUP then if entity.Type == EntityType.ENTITY_PICKUP then
if entity.SubType == 0 and EID:getDescriptionData(entity.Type, entity.Variant, entity.SubType) ~= nil 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 return nil
end 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 to fix font compatibility. Resets config font to a value compatible with your current language
function EID:fixDefinedFont(forceRefresh) function EID:fixDefinedFont(forceRefresh)
local curLang = EID:getLanguage() local curLang = EID:getLanguage()
+14 -14
View File
@@ -329,7 +329,7 @@ if EID.isRepentance then
-- Give this new entity its Flip Item data if possible -- Give this new entity its Flip Item data if possible
local flipEntry = EID.flipItemPositions[curRoomIndex] and EID.flipItemPositions[curRoomIndex][entity.InitSeed] local flipEntry = EID.flipItemPositions[curRoomIndex] and EID.flipItemPositions[curRoomIndex][entity.InitSeed]
if flipEntry then if flipEntry then
entity:GetData()["EID_FlipItemID"] = flipEntry[1] EID:setEntityData(entity, "EID_FlipItemID", flipEntry[1])
end end
end end
EID:AddCallback(ModCallbacks.MC_POST_PICKUP_INIT, EID.postPickupInitFlip, PickupVariant.PICKUP_COLLECTIBLE) EID:AddCallback(ModCallbacks.MC_POST_PICKUP_INIT, EID.postPickupInitFlip, PickupVariant.PICKUP_COLLECTIBLE)
@@ -337,13 +337,13 @@ if EID.isRepentance then
function EID:CheckPedestalIndex(entity) function EID:CheckPedestalIndex(entity)
-- Only pedestals with indexes that were present at room load can be flip pedestals -- 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. -- 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 curRoomIndex = game:GetLevel():GetCurrentRoomDesc().ListIndex
local gridPos = game:GetRoom():GetGridIndex(entity.Position) local gridPos = game:GetRoom():GetGridIndex(entity.Position)
local flipEntry = EID.flipItemPositions[curRoomIndex] and EID.flipItemPositions[curRoomIndex][entity.InitSeed] 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) -- 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 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
end end
EID:AddCallback(ModCallbacks.MC_POST_PICKUP_UPDATE, EID.CheckPedestalIndex, PickupVariant.PICKUP_COLLECTIBLE) 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] local flipEntry = EID.flipItemPositions[curRoomIndex][pedestal.InitSeed]
if flipEntry then if flipEntry then
if pedestal.Index > EID.flipMaxIndex then EID.flipMaxIndex = pedestal.Index end 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 end
end end
@@ -865,9 +865,8 @@ function EID:renderIndicator(entity, playerNum)
ArrowOffset = Vector(0, -62) ArrowOffset = Vector(0, -62)
end end
local arrowPos = Isaac.WorldToScreen(entity.Position + ArrowOffset) local arrowPos = Isaac.WorldToScreen(entity.Position + ArrowOffset)
if not EID:IsGridEntity(entity) and entity:GetData() and entity:GetData()["EID_RenderOffset"] then entityPos = entityPos + (EID:getEntityData(entity, "EID_RenderOffset") or Vector(0,0))
entityPos = entityPos + entity:GetData()["EID_RenderOffset"]
end
-- Move highlights a bit to fit onto the alt Item layout of Flip / Tainted Laz -- 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 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 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 = {} local curPositions = {}
for _, entity in ipairs(Isaac.FindByType(5, 100, -1, true, false)) do 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) -- 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) -- Fix Overlapping Pedestals if a collectible spawned this frame (needed for Mega Chest)
local pos = entity.Position local pos = entity.Position
for _, otherPos in ipairs(curPositions) do for _, otherPos in ipairs(curPositions) do
if pos:Distance(otherPos[2]) == 0 then if pos:Distance(otherPos[2]) == 0 then
entity:GetData()["EID_RenderOffset"] = Vector(10,0) EID:setEntityData(entity, "EID_RenderOffset", Vector(10,0))
otherPos[1]:GetData()["EID_RenderOffset"] = Vector(-10,0) EID:setEntityData(otherPos[1], "EID_RenderOffset", Vector(-10,0))
end end
end end
table.insert(curPositions, {entity, entity.Position}) 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 -- 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 = 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 pathCheckerEntity.Visible = false
local successful = pathCheckerEntity:ToNPC().Pathfinder:HasPathToPos(entity.Position, false) local successful = pathCheckerEntity:ToNPC().Pathfinder:HasPathToPos(entity.Position, false)
pathsChecked[entity.InitSeed] = successful pathsChecked[entity.InitSeed] = successful
@@ -1404,12 +1403,13 @@ function EID:OnRender()
for _, entitySearch in ipairs(searchGroups) do for _, entitySearch in ipairs(searchGroups) do
for _, entity in ipairs(entitySearch) 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) table.insert(inRangeEntities, entity)
local diff = entity.Position:__sub(sourcePos) local diff = entity.Position:__sub(sourcePos)
-- break ties with the render offset (for Mega Chest double collectibles) -- break ties with the render offset (for Mega Chest double collectibles)
if diff:Length() == EID.lastDist and entity:GetData()["EID_RenderOffset"] then local entityDataRenderOffset = EID:getEntityData(entity, "EID_RenderOffset")
diff = diff + entity:GetData()["EID_RenderOffset"] if diff:Length() == EID.lastDist and entityDataRenderOffset then
diff = diff + entityDataRenderOffset
end end
if diff:Length() < EID.lastDist then if diff:Length() < EID.lastDist then
EID.lastDescriptionEntity = entity EID.lastDescriptionEntity = entity