Added EID:ReplaceVariableStr() to make text variable replacements easier

This commit is contained in:
Wofsauge committed 2024-06-03 22:57:38 +02:00
1 parent 2fda4452c5
commit 76a3b18179
5 files changed
+19 -13

No files matched your search

+6
View File
@@ -2048,3 +2048,9 @@ function EID:UpdateAllPlayerPassiveItems()
end
return listUpdatedForPlayers
end
-- Replaces Variable placeholders in string with a given value
-- Example: "My {1} message" --> "My test message"
function EID:ReplaceVariableStr(str, varID, newString)
return str:gsub("{"..varID.."}", newString)
end
+2 -2
View File
@@ -1172,7 +1172,7 @@ function EID:handleBagOfCraftingRendering(ignoreRefreshRate)
--filteredRecipesList is a table of tables for each item, so we have to iterate over the table using sortedIDs
if (bagOfCraftingOffset > 0) then
prevDesc = prevDesc .. prefix .. moreDesc:gsub("{1}", bagOfCraftingOffset)
prevDesc = prevDesc .. prefix .. EID:ReplaceVariableStr(moreDesc, 1, bagOfCraftingOffset)
end
local curOffset = 0
refreshPosition = -1
@@ -1207,7 +1207,7 @@ function EID:handleBagOfCraftingRendering(ignoreRefreshRate)
end
end
if (bagOfCraftingOffset + EID.Config["BagOfCraftingResults"] < filteredNumResults) then
prevDesc = prevDesc .. prefix .. moreDesc:gsub("{1}",(filteredNumResults-EID.Config["BagOfCraftingResults"]-bagOfCraftingOffset))
prevDesc = prevDesc .. prefix .. EID:ReplaceVariableStr(moreDesc, 1, (filteredNumResults-EID.Config["BagOfCraftingResults"]-bagOfCraftingOffset))
elseif lockedResults then
prevDesc = prevDesc .. prefix
end
+5 -5
View File
@@ -129,7 +129,7 @@ local function VoidCallback(descObj, isRune)
if v > 0 then
local statIncreaseStr = "↑ " .. voidStatIcons[i] .. " " .. voidNames[i] .. "#"
local replaceCount = 0
statIncreaseStr, replaceCount = string.gsub(statIncreaseStr, "{1}", "+" .. string.format("%.4g",v*voidStatUps[i]))
statIncreaseStr, replaceCount = EID:ReplaceVariableStr(statIncreaseStr, 1, "+" .. string.format("%.4g",v*voidStatUps[i]))
if replaceCount == 0 then statIncreaseStr = "↑ " .. voidStatIcons[i] .. " +" .. string.format("%.4g",v*voidStatUps[i]) .. " " .. voidNames[i] .. "#" end
EID:appendToDescription(descObj, statIncreaseStr)
end
@@ -284,8 +284,8 @@ local function BlackFeatherCallback(descObj)
local dmgColor = (hasBox or isGolden) and "ColorGold" or "ColorLime"
local description = EID:getDescriptionEntry("BlackFeatherInformation")
description, _ = string.gsub(description, "{1}", tostring(itemCounter))
description, _ = string.gsub(description, "{2}", "{{"..dmgColor.."}}"..damageMultiplied.."{{CR}}")
description, _ = EID:ReplaceVariableStr(description, 1, tostring(itemCounter))
description, _ = EID:ReplaceVariableStr(description, 2, "{{"..dmgColor.."}}"..damageMultiplied.."{{CR}}")
EID:appendToDescription(descObj, "# "..description)
return descObj
@@ -441,7 +441,7 @@ if EID.isRepentance then
for i,v in ipairs(statsToDisplay) do
local statIncreaseStr = "↑ " .. voidStatIcons[v] .. " " .. voidNames[v]
local replaceCount = 0
statIncreaseStr, replaceCount = string.gsub(statIncreaseStr, "{1}", "+" .. string.format("%.4g",voidStatUps[v]))
statIncreaseStr, replaceCount = EID:ReplaceVariableStr(statIncreaseStr, 1, "+" .. string.format("%.4g",voidStatUps[v]))
if replaceCount == 0 then statIncreaseStr = "↑ " .. voidStatIcons[v] .. " +" .. string.format("%.4g",voidStatUps[v]) .. " " .. voidNames[v] end
newStr = newStr .. statIncreaseStr
if #statsToDisplay > 1 then newStr = newStr .. "?" end
@@ -506,7 +506,7 @@ if EID.isRepentance then
end
end
if hasCarBattery then
EID:appendToDescription(descObj, " " .. EID:getDescriptionEntry("ResultsWithX"):gsub("{1}", "{{Collectible356}}"))
EID:appendToDescription(descObj, " " .. EID:ReplaceVariableStr(EID:getDescriptionEntry("ResultsWithX"), 1, "{{Collectible356}}"))
end
if firstID ~= 0 and EID.TabPreviewID == 0 then
EID.TabPreviewID = firstID
+2 -2
View File
@@ -184,8 +184,8 @@ local function DonationMachineCallback(descObj)
end
end
descObj.Description = string.gsub(descObj.Description, "{1}", coinsNeeded)
descObj.Description = string.gsub(descObj.Description, "{2}", coinsNeeded - totalDonations)
descObj.Description = EID:ReplaceVariableStr(descObj.Description, 1, coinsNeeded)
descObj.Description = EID:ReplaceVariableStr(descObj.Description, 2, coinsNeeded - totalDonations)
descObj.Icon = EID.InlineIcons["DonationMachine"]
return descObj
end
+4 -4
View File
@@ -89,7 +89,7 @@ function EID:CheckGlitchedItemConfig(id)
local s = string.format("%.4g",val)
local prefix = "↑ "
if val > 0 then s = "+" .. s else prefix = "↓ " end
attributes = attributes .. prefix .. string.gsub(localizedNames[v] or localizedNamesEnglish[v], "{1}", s)
attributes = attributes .. prefix .. EID:ReplaceVariableStr(localizedNames[v] or localizedNamesEnglish[v], 1, s)
if val ~= 1 and val ~= -1 then attributes = attributes .. localizedNames["pluralize"] or localizedNamesEnglish["pluralize"] end
attributes = attributes .. "#"
end
@@ -126,7 +126,7 @@ function EID:CheckGlitchedItemConfig(id)
local s = string.format("%.2g",SimpleRound(val))
local prefix = "↑ "
if val > 0 then s = "+" .. s else prefix = "↓ " end
attributes = attributes .. prefix .. string.gsub(voidNames[i], "{1}", s) .. "#"
attributes = attributes .. prefix .. EID:ReplaceVariableStr(voidNames[i], 1, s) .. "#"
end
end
@@ -173,8 +173,8 @@ function EID:CheckGlitchedItemConfig(id)
attributes = attributes .. "#"
end
attributes = attributes .. localizedNames[effectType] or localizedNamesEnglish[effectType] .. "#"
for k,v in ipairs(triggerReplacements) do attributes = string.gsub(attributes, "{T" .. k .. "}", v) end
for k,v in ipairs(replacements) do attributes = string.gsub(attributes, "{" .. k .. "}", v) end
for k,v in ipairs(triggerReplacements) do attributes = EID:ReplaceVariableStr(attributes, "T" .. k, v) end
for k,v in ipairs(replacements) do attributes = EID:ReplaceVariableStr(attributes, k, v) end
if effectTrigger ~= "chain" then lastEffectTrigger = effectTrigger end
end