Fixed GetData calls to potentially throw errors

This commit is contained in:
Wofsauge committed 2021-07-30 00:06:14 +02:00
1 parent 88b9ceecbf
commit f7b72ba35a
3 files changed
+16 -9

No files matched your search

+7
View File
@@ -826,6 +826,13 @@ function EID:getScreenSize()
return Vector(rx*2 + 13*26, ry*2 + 7*26) return Vector(rx*2 + 13*26, ry*2 + 7*26)
end end
function EID:getEntityData(entity, str)
if entity ~= nil and entity:GetData() ~= nil then
return entity:GetData()[str]
end
return nil
end
-- Creates a copy of a KColor object. This prevents overwriting existing -- Creates a copy of a KColor object. This prevents overwriting existing
function EID:copyKColor(colorObj) function EID:copyKColor(colorObj)
return KColor(colorObj.Red, colorObj.Green, colorObj.Blue, colorObj.Alpha) return KColor(colorObj.Red, colorObj.Green, colorObj.Blue, colorObj.Alpha)
+8 -8
View File
@@ -9,7 +9,7 @@ local game = Game()
require("eid_config") require("eid_config")
EID.Config = EID.UserConfig EID.Config = EID.UserConfig
EID.Config.Version = "3.2" EID.Config.Version = "3.2"
EID.Config.ModVersion = "3.71" EID.ModVersion = "3.71"
EID.DefaultConfig.Version = EID.Config.Version EID.DefaultConfig.Version = EID.Config.Version
EID.isHidden = false EID.isHidden = false
EID.player = nil EID.player = nil
@@ -174,8 +174,8 @@ questionMarkSprite:LoadGraphics()
function EID:IsAltChoise(pickup) function EID:IsAltChoise(pickup)
local data = pickup:GetData() local data = pickup:GetData()
if data["EID_IsAltChoise"] ~= nil then if EID:getEntityData(closest, "EID_IsAltChoise") then
return data["EID_IsAltChoise"] return EID:getEntityData(closest, "EID_IsAltChoise")
end end
if not REPENTANCE or game:GetLevel():GetStageType() < 4 or game:GetRoom():GetType() ~= RoomType.ROOM_TREASURE then if not REPENTANCE or game:GetLevel():GetStageType() < 4 or game:GetRoom():GetType() ~= RoomType.ROOM_TREASURE then
@@ -625,8 +625,8 @@ local function onRender(t)
EID:renderIndicator(closest) EID:renderIndicator(closest)
--Handle GetData Entities (specific) --Handle GetData Entities (specific)
if EID.Config["EnableEntityDescriptions"] and type(closest:GetData()["EID_Description"]) ~= type(nil) then if EID.Config["EnableEntityDescriptions"] and EID:getEntityData(closest, "EID_Description") then
local desc = closest:GetData()["EID_Description"] local desc = EID:getEntityData(closest, "EID_Description")
local origDesc = EID:getDescriptionObj(closest.Type, closest.Variant, closest.SubType) local origDesc = EID:getDescriptionObj(closest.Type, closest.Variant, closest.SubType)
if type(desc) == "table" then if type(desc) == "table" then
origDesc.Description = desc.Description or origDesc.Description origDesc.Description = desc.Description or origDesc.Description
@@ -651,7 +651,7 @@ local function onRender(t)
EID:printDescription(descriptionObj) EID:printDescription(descriptionObj)
elseif closest.Variant == PickupVariant.PICKUP_COLLECTIBLE then elseif closest.Variant == PickupVariant.PICKUP_COLLECTIBLE then
--Handle Collectibles --Handle Collectibles
if closest:GetData()["EID_DontHide"] ~= true then if EID:getEntityData(closest, "EID_DontHide") ~= true then
if (EID:hasCurseBlind() and not closest:ToPickup().Touched and EID.Config["DisableOnCurse"]) or (EID.Config["DisableOnAltPath"] and not closest:ToPickup().Touched and EID:IsAltChoise(closest)) or (game.Challenge == Challenge.CHALLENGE_APRILS_FOOL and EID.Config["DisableOnAprilFoolsChallenge"]) then if (EID:hasCurseBlind() and not closest:ToPickup().Touched and EID.Config["DisableOnCurse"]) or (EID.Config["DisableOnAltPath"] and not closest:ToPickup().Touched and EID:IsAltChoise(closest)) or (game.Challenge == Challenge.CHALLENGE_APRILS_FOOL and EID.Config["DisableOnAprilFoolsChallenge"]) then
EID:renderQuestionMark() EID:renderQuestionMark()
return return
@@ -666,7 +666,7 @@ local function onRender(t)
-- small delay when having obstruction enabled & entering the room to prevent spoilers -- small delay when having obstruction enabled & entering the room to prevent spoilers
return return
end end
if closest:GetData()["EID_DontHide"] ~= true then if EID:getEntityData(closest, "EID_DontHide") ~= true then
local isSoulstone = closest.SubType >= 81 and closest.SubType <= 97 local isSoulstone = closest.SubType >= 81 and closest.SubType <= 97
local hideinShop = closest:ToPickup():IsShopItem() and ((not isSoulstone and not EID.Config["DisplayCardInfoShop"]) or (isSoulstone and not EID.Config["DisplaySoulstoneInfoShop"])) local hideinShop = closest:ToPickup():IsShopItem() and ((not isSoulstone and not EID.Config["DisplayCardInfoShop"]) or (isSoulstone and not EID.Config["DisplaySoulstoneInfoShop"]))
local isOptionsSpawn = REPENTANCE and not EID.Config["DisplayCardInfoOptions?"] and closest:ToPickup().OptionsPickupIndex > 0 local isOptionsSpawn = REPENTANCE and not EID.Config["DisplayCardInfoOptions?"] and closest:ToPickup().OptionsPickupIndex > 0
@@ -684,7 +684,7 @@ local function onRender(t)
-- small delay when having obstruction enabled & entering the room to prevent spoilers -- small delay when having obstruction enabled & entering the room to prevent spoilers
return return
end end
if closest:GetData()["EID_DontHide"] ~= true then if EID:getEntityData(closest, "EID_DontHide") ~= true then
local isOptionsSpawn = REPENTANCE and not EID.Config["DisplayPillInfoOptions?"] and closest:ToPickup().OptionsPickupIndex > 0 local isOptionsSpawn = REPENTANCE and not EID.Config["DisplayPillInfoOptions?"] and closest:ToPickup().OptionsPickupIndex > 0
if isOptionsSpawn or (closest:ToPickup():IsShopItem() and not EID.Config["DisplayPillInfoShop"]) or (not EID.Config["DisplayObstructedPillInfo"] and not EID.hasValidWalkingpath) then if isOptionsSpawn or (closest:ToPickup():IsShopItem() and not EID.Config["DisplayPillInfoShop"]) or (not EID.Config["DisplayObstructedPillInfo"] and not EID.hasValidWalkingpath) then
EID:renderQuestionMark() EID:renderQuestionMark()
+1 -1
View File
@@ -77,7 +77,7 @@ if MCMLoaded then
MCM.AddSpace("EID", "Info") MCM.AddSpace("EID", "Info")
MCM.AddText("EID", "Info", function() return "External Item Descriptions" end) MCM.AddText("EID", "Info", function() return "External Item Descriptions" end)
MCM.AddSpace("EID", "Info") MCM.AddSpace("EID", "Info")
MCM.AddText("EID", "Info", function() return "Version "..EID.Config.ModVersion .." ("..EID.GameVersion..")" end) MCM.AddText("EID", "Info", function() return "Version "..EID.ModVersion .." ("..EID.GameVersion..")" end)
MCM.AddSpace("EID", "Info") MCM.AddSpace("EID", "Info")
MCM.AddText("EID", "Info", function() return "by Wofsauge" end) MCM.AddText("EID", "Info", function() return "by Wofsauge" end)
MCM.AddSpace("EID", "Info") MCM.AddSpace("EID", "Info")