From c3c871061780cf41523031eeed7c3cdbde7b1ab2 Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Sun, 8 Oct 2023 16:54:53 +0200 Subject: [PATCH] Rework Unidentified Pill eval, to allow Description modifiers when unidentified --- eid_api.lua | 30 ++++++++++++++++++------------ main.lua | 21 +++++++++++++++------ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index 1436bc7b..dbbd5c95 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -395,18 +395,7 @@ function EID:getDescriptionObj(Type, Variant, SubType, entity, checkModifiers) EID:getObjectItemTypeAndCharge(description) if checkModifiers ~= false then - for _,modifier in ipairs(EID.DescModifiers) do - local result = modifier.condition(description) - if type(result) == "table" then - for _,callback in ipairs(result) do - -- If the modifier loads a different description obj (which also goes through the modifier checks), we should stop our checks so text doesn't get printed twice - if description.ObjSubType ~= SubType then break end - description = callback(description) - end - elseif result then - description = modifier.callback(description) - end - end + description = EID:applyDescriptionModifier(description, SubType) end return description end @@ -429,6 +418,23 @@ function EID:getLegacyModDescription(Type, Variant, SubType) return nil end +-- apply Description Modifier to a given description object +function EID:applyDescriptionModifier(description, SubType) + for _,modifier in ipairs(EID.DescModifiers) do + local result = modifier.condition(description) + if type(result) == "table" then + for _,callback in ipairs(result) do + -- If the modifier loads a different description obj (which also goes through the modifier checks), we should stop our checks so text doesn't get printed twice + if description.ObjSubType ~= SubType then break end + description = callback(description) + end + elseif result then + description = modifier.callback(description) + end + end + return description +end + -- Returns the icon and mod name of a given EID description object as a preformatted description string function EID:getModNameString(descObj) local modString = "" diff --git a/main.lua b/main.lua index d8fff891..be253159 100644 --- a/main.lua +++ b/main.lua @@ -813,12 +813,21 @@ function EID:renderUnidentifiedPill(entity) table.insert(EID.CachedIcons, {}) table.insert(EID.CachedRenderPoses, Vector(pos.X, pos.Y)) end - EID:renderString( - "{{Pill"..pillColor.."}} "..EID:getDescriptionEntry("unidentifiedPill"), - pos, - Vector(EID.Scale, EID.Scale), - EID:getErrorColor() - ) + + local descriptionObj = EID:getDescriptionObj(entity.Type, entity.Variant, entity.SubType, entity, false) + descriptionObj.Name = EID:getDescriptionEntry("unidentifiedPill") + descriptionObj.Description = "" + descriptionObj.ShowWhenUnidentified = false + descriptionObj = EID:applyDescriptionModifier(descriptionObj, -999) + + if EID.Config["ShowItemIcon"] then + descriptionObj.Name = "{{Pill"..pillColor.."}} "..descriptionObj.Name + end + EID:renderString(descriptionObj.Name, pos + Vector(0,-1), Vector(EID.Scale, EID.Scale), EID:getErrorColor()) + if EID.Config["ShowItemDescription"] and descriptionObj.ShowWhenUnidentified then + pos.Y = pos.Y + EID.lineHeight * EID.Scale + EID:printBulletPoints(descriptionObj.Description, pos) + end end -- RGB colors for each player's highlights (Red, Blue, Green, Yellow)