Adds function to add arbitrary description modifiers

This commit is contained in:
Wofsauge committed 2021-06-04 16:13:39 +02:00
1 parent 418508ecca
commit a89a73055a
3 files changed
+112 -63

No files matched your search

+21 -2
View File
@@ -294,7 +294,6 @@ function EID:getDescriptionObj(Type, Variant, SubType)
local description = {}
description.ItemType = Type
description.ItemVariant = Variant
description.RealID = SubType
description.ID = SubType
description.fullItemString = Type.."."..Variant.."."..description.ID
description.Name = EID:getObjectName(Type, Variant, description.ID)
@@ -303,7 +302,12 @@ function EID:getDescriptionObj(Type, Variant, SubType)
description.Description = tableEntry and tableEntry[3] or EID:getXMLDescription(Type, Variant, description.ID)
description.Transformation = EID:getTransformation(Type, Variant, description.ID)
for k,modifier in pairs(EID.DescModifiers) do
if modifier.condition(description) then
description = modifier.callback(description)
end
end
return description
end
@@ -695,6 +699,21 @@ function EID:renderString(str, position, scale, kcolor)
return textPartsTable[#textPartsTable][2]
end
-- Adds Description object modifiers.
-- Used for altering descriptions. Example: Spindown dice, Tarot Cloth, ...
function EID:addDescriptionModifier(modifierName, condition, callback)
EID.DescModifiers[modifierName] = {
condition = condition,
callback = callback
}
end
-- Removes a Description object modifier
-- Used for altering descriptions. Example: Spindown dice, Tarot Cloth, ...
function EID:removeDescriptionModifier(modifierName)
EID.DescModifiers[modifierName] = nil
end
-- Interpolates between 2 KColors with a given fraction.
function EID:interpolateColors(kColor1, kColor2, fraction)
local t =
+77
View File
@@ -0,0 +1,77 @@
if REPENTANCE then
-- Handle Birthright
local function BirthrightCondition(descObj)
return descObj.ItemType == 5 and descObj.ItemVariant == PickupVariant.PICKUP_COLLECTIBLE and descObj.ID == 619
end
local function BirthrightCallback(descObj)
local playerID = EID.player.SubType + 1
local birthrightDesc = EID.descriptions[EID.Config["Language"]]["birthright"][playerID] or EID.descriptions["en_us"]["birthright"][playerID] or nil
if birthrightDesc ~=nil then
local playerName = birthrightDesc[1] or EID.player:GetName()
descObj.Description = "{{CustomTransformation}} {{ColorGray}}"..playerName.."{{CR}}#"..birthrightDesc[3]
end
return descObj
end
EID:addDescriptionModifier("Birthright", BirthrightCondition, BirthrightCallback)
-- Handle Bingeeater description addition
local function BingeeaterCondition(descObj)
return descObj.ItemType == 5 and descObj.ItemVariant == PickupVariant.PICKUP_COLLECTIBLE and EID.player:HasCollectible(664)
end
local function BingeeaterCallback(descObj)
local translatedDesc = EID.descriptions[EID.Config["Language"]]["bingeEaterBuffs"]
local bingeBuff = (translatedDesc and translatedDesc[descObj.ID]) or EID.descriptions["en_us"]["bingeEaterBuffs"][descObj.ID] or nil
if bingeBuff ~= nil then
local bingeStr = "#{{Collectible664}} "
descObj.Description = descObj.Description..bingeStr..bingeBuff[3]:gsub("#",bingeStr)
end
return descObj
end
EID:addDescriptionModifier("Bingeeater", BingeeaterCondition, BingeeaterCallback)
-- Handle Spindown Dice description addition
local function SpindownDiceCondition(descObj)
return descObj.ItemType == 5 and descObj.ItemVariant == PickupVariant.PICKUP_COLLECTIBLE and EID.player:HasCollectible(723)
end
local function SpindownDiceCallback(descObj)
descObj.Description = descObj.Description.."#{{Collectible723}} :"
local refID = descObj.ID
for i = 1,EID.Config["SpindownDiceResults"] do
local spinnedID = EID:getSpindownResult(refID)
refID = spinnedID
if spinnedID > 0 then
descObj.Description = descObj.Description.."{{Collectible"..spinnedID.."}}"
if i ~= EID.Config["SpindownDiceResults"] then
descObj.Description = descObj.Description.." ->"
end
else
local errorMsg = EID.descriptions[EID.Config["Language"]]["spindownError"] or EID.descriptions["en_us"]["spindownError"] or nil
descObj.Description = descObj.Description..errorMsg
break
end
end
return descObj
end
EID:addDescriptionModifier("Spindown Dice", SpindownDiceCondition, SpindownDiceCallback)
-- Handle Tarot Cloth description addition
local function TarotClothCondition(descObj)
return descObj.ItemType == 5 and descObj.ItemVariant == PickupVariant.PICKUP_TAROTCARD and EID.player:HasCollectible(451)
end
local function TarotClothCallback(descObj)
local translatedDesc = EID.descriptions[EID.Config["Language"]]["tarotClothBuffs"] or EID.descriptions["en_us"]["tarotClothBuffs"]
local clothBuff = (translatedDesc and translatedDesc[descObj.ID]) or ( translatedDesc and translatedDesc[descObj.ID]) or nil
if clothBuff ~= nil then
local bingeStr = "#{{Collectible451}} "
descObj.Description = descObj.Description..bingeStr..clothBuff[3]:gsub("#",bingeStr)
end
return descObj
end
EID:addDescriptionModifier("Tarot Cloth", TarotClothCondition, TarotClothCallback)
end
+14 -61
View File
@@ -11,9 +11,11 @@ EID.Config = EID.UserConfig
EID.Config.Version = "3.2"
EID.DefaultConfig.Version = EID.Config.Version
EID.isHidden = EID.Config["Hidden"]
EID.player = nil
-- general variables
EID.PositionModifiers = {}
EID.DescModifiers = {}
EID.UsedPosition = Vector(EID.Config["XPosition"], EID.Config["YPosition"])
EID.isDisplaying = false
EID.isDisplayingPermanent = false
@@ -54,6 +56,7 @@ end
require("eid_data")
require("eid_api")
require("eid_modifiers")
-- load Repentence descriptions
if REPENTANCE then
@@ -407,9 +410,9 @@ EID.pathCheckerEntity = nil
EID.hasValidWalkingpath = true
function EID:onGameUpdate()
local player = Isaac.GetPlayer(0)
EID.player = Isaac.GetPlayer(0)
if not EID.Config["DisplayObstructedCardInfo"] or not EID.Config["DisplayObstructedPillInfo"] then
if EID.lastDescriptionEntity == nil or (EID.Config["DisableObstructionOnFlight"] and player.CanFly) then
if EID.lastDescriptionEntity == nil or (EID.Config["DisableObstructionOnFlight"] and EID.player.CanFly) then
if EID.pathCheckerEntity ~= nil then
EID.pathCheckerEntity:Remove()
EID.pathCheckerEntity = nil
@@ -418,14 +421,14 @@ function EID:onGameUpdate()
return
end
if EID.pathCheckerEntity == nil then
EID.pathCheckerEntity = Isaac.Spawn(500, 69420, 0, player.Position, nullVector, nil) -- Spawns the EID Helper entity
EID.pathCheckerEntity = Isaac.Spawn(500, 69420, 0, EID.player.Position, nullVector, nil) -- Spawns the EID Helper entity
EID.pathCheckerEntity:ClearEntityFlags(EntityFlag.FLAG_APPEAR)
EID.pathCheckerEntity:AddEntityFlags (EntityFlag.FLAG_PERSISTENT | EntityFlag.FLAG_NO_STATUS_EFFECTS | EntityFlag.FLAG_NO_SPRITE_UPDATE | EntityFlag.FLAG_HIDE_HP_BAR | EntityFlag.FLAG_NO_DEATH_TRIGGER)
EID.hasValidWalkingpath = false
elseif not EID.pathCheckerEntity:Exists() then
EID.pathCheckerEntity = nil
else
EID.pathCheckerEntity.Position = player.Position
EID.pathCheckerEntity.Position = EID.player.Position
EID.hasValidWalkingpath = EID.pathCheckerEntity:ToNPC().Pathfinder:HasPathToPos ( EID.lastDescriptionEntity.Position, false )
end
end
@@ -465,21 +468,21 @@ local function onRender(t)
EID:renderMCMDummyDescription()
local player = Isaac.GetPlayer(0)
EID.player = Isaac.GetPlayer(0)
if EID.GameVersion == "ab+" then
if player:HasCollectible(CollectibleType.COLLECTIBLE_SCHOOLBAG) then
if EID.player:HasCollectible(CollectibleType.COLLECTIBLE_SCHOOLBAG) then
EID:addTextPosModifier("Schoolbag", Vector(0,30))
else
EID:removeTextPosModifier("Schoolbag")
end
else
if player.SubType == 21 or player.SubType == 25 then -- T-Isaac, T-Blue Baby
if EID.player.SubType == 21 or EID.player.SubType == 25 then -- T-Isaac, T-Blue Baby
EID:addTextPosModifier("Tained HUD", Vector(0,30))
else
EID:removeTextPosModifier("Tained HUD")
end
if player:HasCollectible(710) and EID.Config["DisplayBagOfCrafting"] ~= "never" then
if EID.Config["DisplayBagOfCrafting"] == "always" or (EID.Config["DisplayBagOfCrafting"] == "hold" and string.find(player:GetSprite():GetAnimation(), "PickupWalk")) then
if EID.player:HasCollectible(710) and EID.Config["DisplayBagOfCrafting"] ~= "never" then
if EID.Config["DisplayBagOfCrafting"] == "always" or (EID.Config["DisplayBagOfCrafting"] == "hold" and string.find(EID.player:GetSprite():GetAnimation(), "PickupWalk")) then
local success = EID:handleBagOfCraftingRendering()
if success then
return
@@ -496,14 +499,13 @@ local function onRender(t)
EID.lastDescriptionEntity = nil
EID.lastDist = 10000
local player = Isaac.GetPlayer(0)
local searchGroups = {}
searchGroups[1] = Isaac.FindByType(EntityType.ENTITY_EFFECT, -1, -1, true, false)
searchGroups[2] = Isaac.FindInRadius(player.Position, tonumber(EID.Config["MaxDistance"])*40, searchPartitions)
searchGroups[2] = Isaac.FindInRadius(EID.player.Position, tonumber(EID.Config["MaxDistance"])*40, searchPartitions)
for _, entitySearch in ipairs(searchGroups) do
for i, entity in ipairs(entitySearch) do
if EID:hasDescription(entity) and entity.FrameCount > 0 then
local diff = entity.Position:__sub(player.Position)
local diff = entity.Position:__sub(EID.player.Position)
if diff:Length() < EID.lastDist then
EID.lastDescriptionEntity = entity
EID.lastDist = diff:Length()
@@ -573,45 +575,6 @@ local function onRender(t)
end
local descriptionObj = EID:getDescriptionObj(closest.Type, closest.Variant, closest.SubType)
if REPENTANCE then
-- Handle Birthright
if closest.SubType == 619 then
local playerID = player.SubType + 1
local birthrightDesc = EID.descriptions[EID.Config["Language"]]["birthright"][playerID] or EID.descriptions["en_us"]["birthright"][playerID] or nil
if birthrightDesc ~=nil then
local playerName = birthrightDesc[1] or player:GetName()
descriptionObj.Description = "{{CustomTransformation}} {{ColorGray}}"..playerName.."{{CR}}#"..birthrightDesc[3]
end
end
-- Handle Bingeeater description addition
if player:HasCollectible(664) then
local translatedDesc = EID.descriptions[EID.Config["Language"]]["bingeEaterBuffs"]
local bingeBuff = (translatedDesc and translatedDesc[closest.SubType]) or EID.descriptions["en_us"]["bingeEaterBuffs"][closest.SubType] or nil
if bingeBuff ~= nil then
local bingeStr = "#{{Collectible664}} "
descriptionObj.Description = descriptionObj.Description..bingeStr..bingeBuff[3]:gsub("#",bingeStr)
end
end
-- Handle Spindown Dice description addition
if player:HasCollectible(723) then
descriptionObj.Description = descriptionObj.Description.."#{{Collectible723}} :"
local refID = closest.SubType
for i = 1,EID.Config["SpindownDiceResults"] do
local spinnedID = EID:getSpindownResult(refID)
refID = spinnedID
if spinnedID > 0 then
descriptionObj.Description = descriptionObj.Description.."{{Collectible"..spinnedID.."}}"
if i ~= EID.Config["SpindownDiceResults"] then
descriptionObj.Description = descriptionObj.Description.." ->"
end
else
local errorMsg = EID.descriptions[EID.Config["Language"]]["spindownError"] or EID.descriptions["en_us"]["spindownError"] or nil
descriptionObj.Description = descriptionObj.Description..errorMsg
break
end
end
end
end
EID:printDescription(descriptionObj)
elseif closest.Variant == PickupVariant.PICKUP_TAROTCARD then
--Handle Cards & Runes
@@ -625,15 +588,6 @@ local function onRender(t)
return
end
local descriptionObj = EID:getDescriptionObj(closest.Type, closest.Variant, closest.SubType)
-- Handle Tarot Cloth description addition
if player:HasCollectible(451) then
local translatedDesc = EID.descriptions[EID.Config["Language"]]["tarotClothBuffs"] or EID.descriptions["en_us"]["tarotClothBuffs"]
local clothBuff = (translatedDesc and translatedDesc[closest.SubType]) or ( translatedDesc and translatedDesc[closest.SubType]) or nil
if clothBuff ~= nil then
local bingeStr = "#{{Collectible451}} "
descriptionObj.Description = descriptionObj.Description..bingeStr..clothBuff[3]:gsub("#",bingeStr)
end
end
EID:printDescription(descriptionObj)
elseif closest.Variant == PickupVariant.PICKUP_PILL then
--Handle Pills
@@ -651,7 +605,6 @@ local function onRender(t)
local identified = pool:IsPillIdentified(pillColor)
if (identified or EID.Config["ShowUnidentifiedPillDescriptions"]) then
local descEntry = EID:getDescriptionObj(closest.Type, closest.Variant, pillColor)
descEntry["realSubType"] = pillColor
EID:printDescription(descEntry)
else
EID:renderString(