From 805d57540ffc3953cd2bdca13c9a82ba04091a0c Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Sat, 5 Nov 2022 17:24:29 +0100 Subject: [PATCH] Fixed GetData() descriptions being unable to alter Modname, Quality and object icons --- eid_api.lua | 23 +++++++++++++++++++++++ eid_debugging.lua | 5 ++++- main.lua | 11 ++--------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index e8d49135..d4611152 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -428,6 +428,29 @@ function EID:getLegacyModDescription(Type, Variant, SubType) return nil end +-- Returns the icon and mod name of a given EID description object as a preformatted description string +function EID:getModNameString(descObj) + local modString = "" + if EID.Config["ModIndicatorDisplay"] == "Both" or EID.Config["ModIndicatorDisplay"] == "Name only" then + local modName = EID.ModIndicator[descObj.ModName] and EID.ModIndicator[descObj.ModName].Name or descObj.ModName + modString = modString .. " {{"..EID.Config["ModIndicatorTextColor"].."}}" .. modName + end + local modIcon = EID.ModIndicator[descObj.ModName] and EID.ModIndicator[descObj.ModName].Icon + if (EID.Config["ModIndicatorDisplay"] == "Both" or EID.Config["ModIndicatorDisplay"] == "Icon only") and modIcon then + modString = modString .. "{{".. modIcon .."}}" + end + return modString +end + +-- Attempts to merge two given Description objects into one +function EID:mergeDescriptionObjects(oldDescObj, newDescObj) + for k,v in pairs(oldDescObj) do + if not newDescObj[k] then + newDescObj[k] = v + end + end + return newDescObj +end -- returns the specified object table in the current language. -- falls back to english if it doesnt exist, unless specified otherwise function EID:getDescriptionEntry(objTable, objID, noFallback) diff --git a/eid_debugging.lua b/eid_debugging.lua index b24ff60e..4064b0b9 100644 --- a/eid_debugging.lua +++ b/eid_debugging.lua @@ -199,7 +199,10 @@ local function onDebugRender(t) local descTable = { ["Name"] = "Some Item with seed ".. v.InitSeed , ["Description"] = "Test specific description#Init seed: ".. v.InitSeed, - ["Transformation"] = "1,2" + ["Transformation"] = "1,2", + ["ModName"] = "My Mod name", + ["Quality"] = 4, + ["Icon"] = EID.ObjectIcon["5.100.1"], } v:GetData()["EID_Description"] = descTable end diff --git a/main.lua b/main.lua index 7bccbe85..674573ec 100644 --- a/main.lua +++ b/main.lua @@ -625,12 +625,7 @@ function EID:printDescription(desc, cachedID) end -- Display the mod this item is from if desc.ModName then - if EID.Config["ModIndicatorDisplay"] == "Both" or EID.Config["ModIndicatorDisplay"] == "Name only" then - curName = curName .. " {{"..EID.Config["ModIndicatorTextColor"].."}}" .. EID.ModIndicator[desc.ModName].Name - end - if (EID.Config["ModIndicatorDisplay"] == "Both" or EID.Config["ModIndicatorDisplay"] == "Icon only") and EID.ModIndicator[desc.ModName].Icon then - curName = curName .. "{{".. EID.ModIndicator[desc.ModName].Icon .."}}" - end + curName = curName .. EID:getModNameString(desc) end EID:renderString( @@ -1367,9 +1362,7 @@ local function onRender(t) local desc = EID:getEntityData(closest, "EID_Description") local origDesc = EID:getDescriptionObjByEntity(closest) if desc ~= nil and type(desc) == "table" then - origDesc.Description = desc.Description or origDesc.Description - origDesc.Name = desc.Name or origDesc.Name - origDesc.Transformation = desc.Transformation or origDesc.Transformation + origDesc = EID:mergeDescriptionObjects(origDesc, desc) else origDesc.Description = desc end